LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fft and automatic filter

Hi.

I have a couple of data from a measure and want to do an automatic filter.
The way how I want to proceed is the following one:
I want to make an FFT on the data, and then make a frequency detector.
The unwanted frequency are 50Hz and 100Hz.
IF (and only if) the 50Hz and/or 100Hz are detected on the FFT (automatic detector), then, I will filter the data with 2 band-cut filter (one with 50Hz central frequency, and one with 100Hz), then re-made an other FFT to make sure the frequency I have removed from the datas are there any more.

How can I do that?
Is the way I want to to it succesfull? If not, why?
0 Kudos
Message 1 of 14
(4,743 Views)
Hi,

Do you mean that filter the 50Hz and 100Hz signals no matter how strong they are?

How about cascade a 50Hz filter and a 100Hz filter and filter the acquired time domain signal before FFT?

Bill
0 Kudos
Message 2 of 14
(4,725 Views)
It depends in complicated ways on several factors. What is the sampling frequency? How many samples are taken in each acquistion? How close to the undesired 50 and 100 Hz interfering signals are the desired signals? What are the relative amplitudes of the desired and undesired signals? Do you need to reconstruct the waveform after the filtering?

What you suggest may work. How well depends on some of the issues I mentioned above. Tell us more about your application and someone can probably help.

Lynn
0 Kudos
Message 3 of 14
(4,722 Views)
What is the sampling frequency? 5kHz
How many samples are taken in each acquistion? More than 2E6 samples...
How close to the undesired 50 and 100 Hz interfering signals are the desired signals? I have to filter as close as possible ( 5% of each center frequency will be good)
What are the relative amplitudes of the desired and undesired signals? I dont know. I have to fix it with a command.
Do you need to reconstruct the waveform after the filtering? YES.
0 Kudos
Message 4 of 14
(4,720 Views)
bill choy : I want to filter the signal ONLY if there is 50Hz and 100Hz peaks.
The FFT will be the answer to the question : "have my signal to be filtred?" the FFT answer by yes or no.
Yes is Peaks are detected.
No, if not.

Am I clear??? (I'm not sure to be)
0 Kudos
Message 5 of 14
(4,718 Views)
The size of the frequency bins in the FFT is related to the number of samples. The frequency resolution is delta f = fs/N where fs is the sampling frequency and N is the number of samples. Look at the help files for the FFT. With your values the frequency bins are 2.5 millihertz wide. With real circuits your 50 or 100 Hz signals will occupy several bins. One approach would be to take the bins within 5% of the center frequency of the interference and test their amplitudes against some threshold (for example baseline plus one standard deviation). If the values exceed the threshold, replace them with baseline values. Then do an inverse transform on the modified spectrum to reconstruct the filtered time domain signal.

So long as your system preceeding the FFT is reasonably linear this will probably work. If the signal of interest has much energy in the 5% bands around 50 or 100 Hz, you will lose some of the data.

Lynn
0 Kudos
Message 6 of 14
(4,710 Views)
johnsold.
Thanks for the explain.
I understand how to do, but have a litle problem : I dont know how to do a "over threshold detection". Have I do to it with a cursor coordinate? how can I make a Detector for only this part of the graph (FFT graph) and not for the other part?
Did you have an example, just to show me how doing (the way of think).
If not, can you just give any more detail that could be helpfull.

Thank you in advance
0 Kudos
Message 7 of 14
(4,696 Views)
Here is an example vi. It tests around 50 Hz for spectrum values greater than the threshold, arbitrarily set to mean plus standard deviation of entire spectrum. If any element is foud to be above the threhsold, all of the elements in the test interval are replaced with the mean.

Lynn
0 Kudos
Message 8 of 14
(4,676 Views)
Thank you johnsold.

I have test your vi (and try to understand how it works).
Please correct me if I'm wrong : You change the value of the data scaned if the signal data is over the threshold.
Question : what is the command that fix the value of the threshold?
Other question : my array is a 2D array. how can I do the same thing with it? (with a for loop, and indexation I suppose)
The last question is : I have puted a reverse FFT to see the signal filtred, on the graph, the first values seems to be higher than the initial array. why? is it a mathematical error? (no problem with it, I just cut those first values out, but I want to understand why...)
If I understand well, I jsut have to put the same thing in serial to have two frequency filters.

Other question : Why you dont use a filter bloc made in labview?
The way i was thinking the vi is as follow :
I test the signal with a FFT, do the over threshold detection. If one (or two) peak(s) over the threshlod is detected, the you filter the signal with a simple filter.
What do you think about this method? Is it a good way to construct my application? If not : why?
Please find an example of the way I was thinking the vi (doesn't work correctly, but the idea is there)...
0 Kudos
Message 9 of 14
(4,662 Views)
If you have LabVIEW Full or Pro version, you can probably do exactly what you want by using the Extract Single Tone Information.vi or the Harmonic Distortion Analyzer.vi. You may need to use two passes to get both 50Hz and 100Hz. Set the exported signals to residual signal and you have your filter.

If you don't already have it, Numerical Recipes in C by Press et. al. is a great reference for this kind of problem. It is a good overview with examples and contains a plethora of references if you need to get deeper into a particular subject. The sections on peak finding and fourier filtering would be very useful to you. The algorithms also translate to LabVIEW very well, since LabVIEW has most of the analysis routines explained in the book (FFT, curve fitting, matrix math, etc.).
0 Kudos
Message 10 of 14
(4,658 Views)