The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 help with threshold filter

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
fmartin Posted - 08/11/2003 : 4:26:33 PM

I have data that has many unwanted peaks which have too high of an amplitude. I need to get rid of these peaks, but I am not sure what function in origin to use. I've tried using the threshold function, but unfortunately it will only filter out data below a certain amplitude, which makes sense since usually that would be noise. Is there any function I can use to filter out the high amplitude noise?
2   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 08/13/2003 : 3:23:29 PM
Hi,

The Origin C function pasted below does threshold filtering by either throwing out frequency components that are below or above a specified threshold value.

You will need Origin 7SR4 to run this.

1> Compile the attached function.
2> Place your time and amplitude data that you want to filter, in the first two columns of a worksheet.
3> With the worksheet active, go to script window and type
tfilter
or type
tfilter 1
The first command will do threshold filtering by throwing out values below specified threshold, and the second command throws out values above specified threshold.
4> FFT of your data is computed and shown in a new graph
5> A dialog comes up asking for cutoff value - enter value by looking at graph and deciding where you want the threshold to be
6> Filtering is performed, and the raw data along with filtered result are shown in a new graph. The filtered data is added as new column to data worksheet.

Easwar
OriginLab.


#include <Origin.h>
#include <matrix.h>


void tfilter(int iMethod = 0)
{
// Declare worksheet object from active page - quit if not valid worksheet
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("Active page is not a worksheet!\n");
return;
}

// Declare x,y datasets from first two columns - quit if they are not valid
Dataset dsX(wks, 0);
Dataset dsY(wks, 1);
if(!dsX || !dsY)
{
printf("Could not define X, Y datasets!\n");
return;
}

// Get size of data to be filtered
int np = dsY.GetSize();

// Declare vectors to be used with FFT call
vector<complex> vecSignal(np), vecFFT(np);
vecSignal=dsY;

// Compute FFT - internally this calls the NAG library functions
int nRet=FFT(vecSignal, vecFFT);
if(nRet!=0)
{
printf("Error when computing FFT. Error code: %d\n", nRet);
return;
}

// Get amplitude of FFT result
vector vecFFTAmpl;
vecFFT.GetAmplitude(vecFFTAmpl);

// Create a temp wks and store FFT results in there
Worksheet wksFFT;
wksFFT.Create("Origin.OTW", CREATE_HIDDEN);
Dataset dsFreq(wksFFT, 0);
Dataset dsAmpl(wksFFT, 1);
dsFreq.SetSize(np / 2);
// Compute freq column
double dFreqStep = 1.0 / (dsX[1] - dsX[0]) / np;
for(int ii = 0; ii < np / 2; ii++)
{
dsFreq[ii] = ii * dFreqStep;
}
// Fill amplitude
dsAmpl = vecFFTAmpl;
dsAmpl.SetSize(np / 2);

// Create a graph and show user the FFT spectrum in log scale
Curve crvFFT(dsFreq.GetName(), dsAmpl.GetName());
GraphPage gpg;
gpg.Create("Origin.OTP");
GraphLayer gly = gpg.Layers();
nRet = gly.AddPlot(crvFFT, IDM_PLOT_LINE);
Scale sc(gly.Y); // Get X scale object from graph layer
sc.Type = LOG10_SPACE; // Set axis scale as Log10
gly.Rescale();

// Ask user for threshold cutoff value
string strInput = InputBox("Enter cutoff value:");
double dCutoff = atof(strInput);
if(dCutoff <= 0)
{
printf("Invalid entry!\n");
return;
}

// Remove all components above or below this value, based on method passed
for(ii = 0; ii < np; ii++)
{
if(0 == iMethod)
{
// Drop all components below cutoff value
if(vecFFTAmpl[ii] < dCutoff) vecFFT[ii] = 0.;
}
else
{
// Drop all components above cutoff value
if(vecFFTAmpl[ii] > dCutoff) vecFFT[ii] = 0.;
}
}


// Compute inverse FFT and extract real part
nRet = IFFT(vecFFT, vecFFT);
if(nRet!=0)
{
printf("Error when computing inverse FFT. Error code: %d\n", nRet);
return;
}

// Add another column to worksheet next to data, and place result
int iCol = wks.AddCol("Filt");
Dataset dsResult(wks, iCol);
vector vecReal(np);
vecFFT.GetReal(vecReal);
dsResult = vecReal;

// Delete temp graph and wks
wksFFT.Destroy();
gpg.Destroy();

// Create a new graph to show original data and filtered result
Curve crvData(dsX.GetName(), dsY.GetName());
Curve crvResult(dsX.GetName(), dsResult.GetName());
GraphPage gpage;
gpage.Create("Origin.OTP");
GraphLayer glyr = gpage.Layers();
// Add data to plot
glyr.AddPlot(crvData, IDM_PLOT_LINE);
// Add filter result and set color to red
glyr.AddPlot(crvResult, IDM_PLOT_LINE);
DataPlot dp2 = glyr.DataPlots(1);
dp2.SetColor(1, TRUE);
glyr.Rescale();
}


easwar Posted - 08/12/2003 : 10:42:23 PM
Hi,

I presume by peaks you are refering to specific frequency components in the FFT spectrum of the data, and you want a method to remove all frequency components that are above a particular value, keep the rest, and perform an inverse transform to filter the data?

The code behind the threshold filter is LabTalk script and could be modified to work the other way - to remove components that are above a value. Alternately, if you have version 7, you could do this by calling NAG functions from Origin C.

Let us know if the above is what you want to do, and we could provide some code segments to do this using Origin C and NAG. Do you have version 7?

Easwar
OriginLab.


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000