D = load('Xaris load.mat');
t = D.t;
Xs_ddot = D.Xs_ddot;
Xu_ddot = D.Xu_ddot;
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
Wp = [3 25]/Fn;
Ws = Wp .* [0.2 1.1];
Rp = 1;
Rs = 30;
[n, Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn,'bandpass');
[bp_sos,bp_g] = tf2sos(b,a);
Rs = 10;
Rp = 20;
Ws = [9.95 10.05]/Fn;
n = 2;
[b,a] = cheby2(n,Rs,Ws,'stop');
[bs_sos,bs_g] = tf2sos(b,a);
figure(1)
freqz(bp_sos,1024,Fs)
figure(2)
freqz(bs_sos,1024,Fs)
Xs_bp = filtfilt(bp_sos, bp_g, Xs_ddot);
Xs_out = filtfilt(bs_sos, bs_g, Xs_bp);
Xu_bp = filtfilt(bp_sos, bp_g, Xu_ddot);
Xu_out = filtfilt(bs_sos, bs_g, Xu_bp);
figure(3)
subplot(2,1,1)
plot(t, Xs_ddot)
title('Unfiltered ‘Xs\_ddot’')
grid
subplot(2,1,2)
plot(t, Xs_out)
title('Filtered ‘Xs\_ddot’')
grid
figure(4)
subplot(2,1,1)
plot(t, Xu_ddot)
title('Unfiltered ‘Xu\_ddot’')
grid
subplot(2,1,2)
plot(t, Xu_out)
title('Filtered ‘Xu\_ddot’')
grid
Best Answer