How to design a lowpass filter for ocean wave data in Matlab?

214 views (last 30 days)
Hi there.
What frequency specification should I use in order to create a low-pass filter ? ( Specifically filter order and Frequency specifications) I have a huge data set contains unfiltered water level data and it is in meters relative to mean lower water (MLW) at hourly intervals. The time stamp is in Julian data.
thank you in advance.

Accepted Answer

Star Strider
Star Strider on 22 Mar 2015
You need to know the passband of the filter you want to design (the frequencies you want to either keep or filter out), and the sampling frequency (Fs) at the very least. Since you have Fs, the Signal Processing Toolbox makes the rest easy. From your description, a Butterworth design is likely the best. You are always free to experiment with other designs, but the scheme I’m outlining for the Butterworth design is a prototype for all of them. You have already decided on a lowpass design, the default for all of them, so you don’t have to specify a filter type. (I usually prefer a bandpass with a very low cutoff, in the event that I want to filter out baseline drift. That’s simply my personal bias, because my signals usually have baseline drift.)
  1. To determine the order, start with the buttord function;
  2. Use the output of buttord to design a transfer function (b,a) realization of your filter with the butter function, (I usually use 1 dB for Rp and 10 dB for Rs, but these are not relevant for Butterworth designs);
  3. Use the tf2sos function to create a second-order-section representation for stability;
  4. Use the trapz function (be sure to give it your sampling frequency, ‘Fs’, to make the output understandable) in order to check the filter performance to be sure it is stable and does what you intend it to do;
  5. Use the filtfilt function for the actual filtering, since unlike filter, filtfilt does not introduce any phase distortion.
The documentation is reasonably clear on all these, so their usage should be straightforward, but that assumes some experience in discrete signal processing. If you have any problems, follow up here and I’ll do my best to help you solve them.
  1 Comment
Explorer on 25 Jan 2016
Edited: Explorer on 25 Jan 2016
Step 1: Determing Order
As I have to design chebyshev type II, I started with following code but got error.
Fs = 200; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [1 100]/Fn; % Filter Passband (Normalised)
Ws = Wp .* [0.5 1/0.5]; % Filter Stopband (Normalised)
Rp=1; Rs= 10;
Error using cheb2ord (line 62) The cutoff frequencies must be within the interval of (0,1).
Why am I getting this error?
I was suggested yo design chebyshev here:

Sign in to comment.

More Answers (1)

Neo Mthimkhulu
Neo Mthimkhulu on 14 May 2019
been trying to implement a filter for accelerometer data but I am unable to use filtfilt function
there is the error its giving me:
Error in filtfilt (line 97)
[b,a,zi,nfact,L] = getCoeffsAndInitialConditions(b,a,Npts);
Error in Arduino (line 68)
y = filtfilt(sos,g,Q)
if ~isempty(instrfind)
arduinoCom = serial('COM7', 'BaudRate', 9600);
Xval = 0;
Yval = 0;
Zval = 0;
Xval1 = 0;
Yval1 = 0;
Zval1 = 0;
bufLen = 100 ;
index = 1:bufLen;
gxData = zeros(bufLen,1);
gyData = zeros(bufLen,1);
gzData = zeros(bufLen,1);
gData = zeros(1,3);
gxDataFilt = zeros(bufLen,1);
gyDataFilt = zeros(bufLen,1);
gzDataFilt = zeros(bufLen,1);
Wp =[1 4]/500;
Ws = [0.5 4.5]/500;
[n,Wn] = buttord(Wp,Ws,1,10);
[num,den] = butter(8,Wn,'bandpass');
% Transfer = tf(num,den)
[sos,g] = tf2sos(num,den);
while n<101
Data = fscanf(arduinoCom);
% Extracting Data from A Character array
Axis1 = extractBetween(Data,'X:','Y:');
X =str2double(Axis1);
Axis2 = extractBetween(Data, 'Y:','Z:');
Y =str2double(Axis2);
Axis3 = extractBetween(Data,'Z:','m');
Z =str2double(Axis3);
% Real-Time Plot of Acceleration vs Time
gxData = [gxData(2:end);X];
gyData = [gyData(2:end);Y];
gzData = [gzData(2:end);Z];
gData = [gxData gyData gzData];
% FilteredSignal = filter(Hd,X);
%FilteredSignal = bandpass(X,[1 4],1000);
Q = trapz(gData);
y = filtfilt(sos,g,Q)
n = n + 1;

Community Treasure Hunt

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

Start Hunting!