How to do digital filtering in Matlab with a specified cut off frequency?

46 views (last 30 days)
Hello all,
I am relatively new in Matlab for doing signal processing.
I have a time series of 30 min duration having the sampling frequency of 10 Hz. So I have 18000 points in the time series and and the highest resolvable frequency of 5Hz. Now in order to avoid the high frequency noise , I want to eliminate all the frequency above 2 Hz using the FFT.
In order to do that shall I take the FFT of the time-series in Matlab and then put zero for all the complex coefficients above 2 Hz and then take the Inverse FFT of that? Will by doing this I will eliminate all the frequency contribution above 2 Hz?
Please help me in this regard. Thanks to all in advance.

Accepted Answer

Star Strider
Star Strider on 14 Dec 2015
Filtering in the frequency domain is not the optimal method because you have to filter the entire (both sides) of the symmetrical fft. It is relatively easy to do the filtering in the time domain using the Signal Processing Toolbox. This is my filter design and implementation procedure: How to design a lowpass filter for ocean wave data in Matlab?. If you do not have the Signal Processing Toolbox, the University of York (U.K.) interactive Butterworth / Bessel / Chebyshev Filters filter design page is the best available substitute I’ve found. Use the core MATLAB filter function if you don’t have the Signal Processing Toolbox filtfilt function.
  2 Comments
subharthi chowdhuri
subharthi chowdhuri on 14 Dec 2015
Thanks a lot for your answer.
Let me be a little more specific on what I am doing. I have the sonic data of temperature collected at 10 Hz frequency for a run of 30 min duration. The sampling interval is 0.1 seconds.
You have suggested a butterworth filter. I would be very pleased if you can explain a bit how I can apply this filter for removing the frequencies greater than 2 Hz?
Thanks again for your help.
Star Strider
Star Strider on 14 Dec 2015
My pleasure.
With a 10 Hz sampling frequency, the Nyquist frequency is 5 Hz. This designs a stable filter with what appears to me a good response:
Fs = 10; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Fco = 2; % Cutoff Frequency (Hz)
Wp = Fco/Fn; % Normalised Cutoff Frequency (rad)
Ws = 1.2*Wp; % Stopband Frequency (rad)
Rp = 5; % Passband Ripple (dB)
Rs = 20; % Stopband Ripple (dB)
[n,Wn] = buttord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[b,a] = butter(n,Wn); % Calculate Filter Coefficients
[sos,g] = tf2sos(b,a); % Convert To Second Order Section Representation
figure(1)
freqz(sos, 1024, Fs) % Plot Filter Response (Bode Plot)
Use filtfilt to do the filtering. See the documentation on the individual functions for details on how they work and how to use them in filter design.

Sign in to comment.

More Answers (1)

Chad Greene
Chad Greene on 14 Dec 2015
I wrote a function called filter1 to make frequency filtering a little more user friendly. If your 10 Hz measurements are in an array called y and you want to low-pass filter-out the frequencies higher than 2 Hz, syntax is
y_filt = filter1('lp',y,'fc',2,'fs',10);
where 'lp' means low-pass, 'fc' means cutoff frequency, and 'fs' means sampling frequency.
  1 Comment
Pablo Estuardo
Pablo Estuardo on 27 Jul 2020
Edited: Pablo Estuardo on 27 Jul 2020
Dear Chad, can you please help me with some problem here...
I have a hourly resolution current velocity time series. So, the sampling interval is 3600 seconds, or 1/3600 hertz, and I want to filter the data in the band of energy between 19 and 22 hours (remove all from 0 to 19 hours and from 22 to 24 hours)
y_filt = filter1('bp',y,'fc',[1/(19*3600) 1/(22*3600)],'fs',1/3600);
But the sonsole send me this error....I will apreciate any suggestions.
Best regards

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!