use fast fourier transform (fft) to perform low-pass filtering
December 13th, 2009 by Lawrence David
here’s an easy way to do low-pass signal filtering in matlab:
function [s_data_v] = fftsmooth(data_v,freq_n)
% use fft low pass filter to smoothen out a signalfft_data_v = fft(data_v);
s_fft_data_v = zeros(1,length(data_v));
s_fft_data_v(1:freq_n) = fft_data_v(1:freq_n);
s_fft_data_v(end-freq_n:end) = fft_data_v(end-freq_n:end);
s_data_v = real(ifft(s_fft_data_v));
A few suggestions – cutting off frequencies like that effectively multiplies by a rectangular window, which will smear a lot of content back in the time domain. It’s for this reason that low pass filter design usually multiplies the ideal lpf in the frequency domain (i.e., rect window cutoff at the proper frequency) with a hann window or something similar. Check out this thread http://www.dsprelated.com/showmessage/42364/1.php for some more in depth thoughts on the subject.
Also, the “real” would not be necessary if you ensure conjugate symmetry before the ifft(). For even N, keep the first N/2+1 elements and set the last N/2-1 to conj(fliplr(s_fft_data_v(2:N/2))). I think that would be the correct syntax in your case, but you probably want to check the details to make sure.
I do hope these ideas are helpful and apologies if I’m pointing out something you’re already aware of and intentionally omitting!
Could you please explain more about what you wrote and how does it work?
I used it and the result is good but i don’t know how does it work.
Hello, would you please add some explanation so that it could be easier for us who doesn’t have vast knowledge of matlab.
I have 20k voltage output at 1ms sampling rate. I already done fft in matlab now now I want to apply low pass filter with cut off freq=400hz. How can I do it?
Thanks
I tried to use this code to demodulate DSBSC AM signal(i.e.,using coherent detector),but the demodulated signal i am getting is not smooth.It has ripples in it.Plz can you help?