MATLAB: How to filter a low frequency movement from the data

filterwave

Goodmorning,
For my thesis i'm analyzing wave data of flume tests. But it seems that there is some sort of 'long wave' present in the flume. Now i am trying to filter this long wave out of my data but i can't find a decent way to to this.
I already tried to filter my data using the Polyfit and polyval functions, this did filter the long wave out of the signal. But in my opinion this was more or less tweaking the function to get a good result. Secondly i do not want to use a moving avarage because this eliminates data. My supervisor told me to try the Filtfilt option. But now i am stuck wondering how to filter my signal with use of this FiltFilt.
See the figure below, there seems to be some longer wave present which i want to filter out for both the water level elevation and velocity. I was wondering if this is even possible or that my 'timeframe' is to short.

Best Answer

This uses a highpass Chebyshev Type II filter to eliminate the low frequency variation and the c-d (constant) offset from both signals. You can use the Fourier transform in figure(2) as a guide to fine-tuning the passband (here Wp) and stopband (here Ws) frequencies to eliminate the frequencies you want. (Since this is a highpass filter, Ws must be lower than Wp.) I designed a highpass filter rather than a bandpass filter since your signals seem to have very little high-frequency noise.
The Code
D = load('Time elevation velocity.mat');
t = D.datavec(:,1);
wle = D.datavec(:,2);
vel = D.datavec(:,3);
figure(1)
plot(t, wle, t, vel)
grid
Ts = mean(diff(t)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = size(t,1); % Signal Length
FTwle = fft([wle vel])/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure(2)
plot(Fv, abs(FTwle(Iv))*2)
grid
axis([0 3 ylim])
Wp = 0.25/Fn; % Stopband Frequency (Normalised)
Ws = 0.20/Fn; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws,'high'); % Filter Design, Sepcify Bandstop
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sos, 2^16, Fs) % Filter Bode Plot
wle_vel_filtered = filtfilt(sos, g, [wle vel]); % Filter Signal
figure(4)
plot(t, wle_vel_filtered)
grid