12-03-2009 11:51 AM
Im having a problem filtering my data after decimating it. Even though I undecimate the data back to its original form it
still gives me an output that I dont expect. Here the is the function I wrote. I will attach pre filtering and post filtering to this post.
The situation is that I have 12 channels of data coming in interleaved. I basically decimate the data and store it in data[12][100] with nSamples = 1200 and nChannels = 12. This function just serves as a wrapper for the filtering to take place.
Here is the source code without filtering. I'm decimating and then undecimating to prove that the undecimation works.
Basically this function is obsolete without the filtering functions. Its just straight data manipulation.
int filterDaq1Data(double* input,int nChannels,int nSamples)
{
int counter = 0; //counter to traverse all the data points
double data[GRAWCOUNT][GBUFFERSIZE]; //decimated data
double filtered[GRAWCOUNT][GBUFFERSIZE] = {{0},{0}}; //filtered data
int status = 0;
if(nSamples) //if samples acquired then continue
{
for(int i = 0; i < nChannels; i++)
{ //decimate data channels
Decimate(&input[i],nSamples,nChannels,DISABLE_OPTION,data[i]);
//filter data per channel
// status = Bw_LPF(data[i],nSamples/nChannels,gDaqRate,200,5,filtered[i]);
// status = Elp_LPF(data[i],nSamples/nChannels,gDaqRate,50,0.1,40.0,5,filtered[i]);
// status = Ch_LPF(data[i],nSamples/nChannels,gDaqRate,50,0.1,5,filtered[i]);
// status = Wind_LPF(gDaqRate,50,nSamples/nChannels,data[i],HAMMING_FILTER);
// status = WindFIR_Filter(LOWPASS,gDaqRate,50,60,nSamples/nChannels,HAMMING,0,data[i]);
// status = HamWin(data[i],nSamples/nChannels);
}
for(int i = 0; i < GBUFFERSIZE; i++) //undecimate data back into memory pointer
{
for(int j = 0; j < GRAWCOUNT; j++)
{ //stored data into daq pointer
daq1FilteredData[counter] = data[j][i];
// daq1FilteredData[counter] = filtered[j][i];
counter++; //increment counter to next pointer location
}
}
}
If you look at data.jpg you should see that the waveforms are apparent, but noisy.
Here is the source code wiht the bw_LPF. I decimate, filter, then undecimate the data back to its original form.
int filterDaq1Data(double* input,int nChannels,int nSamples)
{
int counter = 0; //counter to traverse all the data points
double data[GRAWCOUNT][GBUFFERSIZE]; //decimated data
double filtered[GRAWCOUNT][GBUFFERSIZE] = {{0},{0}}; //filtered data
int status = 0;
if(nSamples) //if samples acquired then continue
{
for(int i = 0; i < nChannels; i++)
{ //decimate data channels
Decimate(&input[i],nSamples,nChannels,DISABLE_OPTION,data[i]);
//filter data per channel
status = Bw_LPF(data[i],nSamples/nChannels,gDaqRate,50,5,filtered[i]);
// status = Elp_LPF(data[i],nSamples/nChannels,gDaqRate,50,0.1,40.0,5,filtered[i]);
// status = Ch_LPF(data[i],nSamples/nChannels,gDaqRate,50,0.1,5,filtered[i]);
// status = Wind_LPF(gDaqRate,50,nSamples/nChannels,data[i],HAMMING_FILTER);
// status = WindFIR_Filter(LOWPASS,gDaqRate,50,60,nSamples/nChannels,HAMMING,0,data[i]);
// status = HamWin(data[i],nSamples/nChannels);
}
for(int i = 0; i < GBUFFERSIZE; i++) //undecimate data back into memory pointer
{
for(int j = 0; j < GRAWCOUNT; j++)
{ //stored data into daq pointer
// daq1FilteredData[counter] = data[j][i];
daq1FilteredData[counter] = filtered[j][i];
counter++; //increment counter to next pointer location
}
}
}
notice data filtering.jpg the waveforms are not what I expected. If I'm filtering out the high freq and allowing 50 hz to pass through shouldnt I see
smoother waves of data.jpg?
Can someone help me troubleshoot this issue?
12-04-2009 09:47 AM
In general you need to low pass filter before you decimate, otherwise you risk "aliasing" that wraps high frequency components back into lower frequencies that will usually look like "noise".
Design your filter for the sample rate before decimation, insure that its cutoff frequency and order is low enough that everything above 1/2 the decimated rate is removed. Then you can decimate the data to the lower rate without aliasing.
--wally.