Smoothing and Filtering Data with FFT

24 views (last 30 days)
sbareben
sbareben on 9 May 2017
Commented: Star Strider on 10 May 2017
i've a many file each one include a signal, into the file the sample are saved every 0.01s (100Hz), the problem is that my signal is composed from much noise, i made the FFT of the signal, i take the magnitude of it, now my question is, how can i made filter or usign FFT to smoothing it? beacuse i'm interesting only to the value of signal that are >= 2 more or less, the rest that is tall i'm interested to smoothing, beacuse than i need to integrate the filtered signal. And i need to create an automated system to filter the signal, that is equal to each file. But i'don't know how to filter the data with FFT.
This is the original signal:
SO i did the FFT of this signal:
fft_value = fft(SignalIn);
magnitude = abs(fft_value);
frequency = 100*(0:(numel(magnitude)-1))/numel(magnitude);
plot(frequency, magnitude);
And this is the magnitude.
First of all, the calculate of the magnitude is correct?
If i analize it, i take into consideration only the value from 0 to 50Hz, so the half of the plot, than my noise is concentrate, around the high amplitude peaks right? For example between 1Hz to 20Hz? How can i filter into this frequency for example and get a clean signal that smoothed low components, and don't change the high signal components?

Answers (2)

Star Strider
Star Strider on 9 May 2017
Your Fourier transform calculation is incorrect. See the documentation in this version fft (link), especially the code between the first (top) two plot figures.
Second, you can do filtering in the frequency domain with the Signal Processing Toolbox fftfilt (link) function. You will have to experiment with the FIR filters to get the result you want.
Here is prototype code for a bandstop filter to get you started with your FIR filter design (that you will need in order to use fftfilt):
Fs = 256;
notch_frq = [45 48 50 52];
mags = [1 0 1];
devs = [0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(notch_frq,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
figure(1)
freqz(hh, 1, 2^17, Fs)
See the documentation for the various functions to understand how to design the filter you want.
  5 Comments
sbareben
sbareben on 10 May 2017
Edited: sbareben on 10 May 2017
I'm trying to integrate the signal, but if don't filter it right the velocity result is incorrect.
Star Strider
Star Strider on 10 May 2017
I cannot see anything in the signal you plotted that suggests specific peaks in the spectrum. It has significant broadband noise that you can probably only eliminate with a wavelet filter in the time domain before processing it further. There are examples in the Wavelet Toolbox on this. (I do not have sufficient experience with wavelets to help you with this.)

Sign in to comment.


sbareben
sbareben on 9 May 2017
Edited: sbareben on 9 May 2017
Thanks, for the answer, so i adjust my fourier transform like this:
L = length(signal);
f = Fs*(0:(L/2))/L;
Y = fft(signal);
P2 = abs(Y/L);
P1 = P2(1:floor(L/2)+1);
P1(2:end-1) = 2*P1(2:end-1);
plot(f,P1)
title('Single-Sided Amplitude Spectrum of Data(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
Now if i analize it, i can see that the noise is concentrate from 0Hz to 20Hz (apposimately)right?
Now, i would to filter the signal, to doing that in accordance as you suggest and use a FIR filter, how can i use the frequency founded into FFT analysis to filter data? Sorry for the question, but i really don't know how to do it beacuse i'm not a filter expert, and before doing something i'll try to understand better.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!