Azzera filtri
Azzera filtri

Chebyshev Type 2 filter not working as expected

5 visualizzazioni (ultimi 30 giorni)
Rudy Steel
Rudy Steel il 7 Gen 2022
Commentato: Rudy Steel il 7 Gen 2022
I have some EEG data and I designed a 20th order bandpass chebyshev type 2 filter with a stopband of 10hz and passband of 4hz. I filtered my signal with this filter however the response I obtained does not seem to be making sense. Can anyone help/identify what I am doing wrong?
EEGdata = load('EEGdata.csv');
Fs = 1200; % Sampling frequency
T = 1/Fs; % Sampling period
L = length(EEGdata); % Length of signal
t = [0:(L-1)]*T; % Time vector
%now using bandpass chebyshev type 2 filter
[A,B,C,D] = cheby2(10,40,[4 10]/600);
d = designfilt('bandpassiir','FilterOrder',20, ...
'StopbandFrequency1',4,'StopbandFrequency2',10, ...
'StopbandAttenuation',40,'SampleRate',1200);
sos = ss2sos(A,B,C,D);
% fvt = fvtool(sos,d,'Fs',1200);
% legend(fvt,'cheby2','designfilt')
%filtering original data
EEG_filt = filtfilt(d,EEGdata);
figure();
subplot(2,1,1)
plot(t,EEGdata); title('EEGdata.csv before filtering'); grid on; axis tight; xlim([0 20]);
xlabel('Time in seconds'); ylabel('Amplitude/\muV');
subplot(2,1,2)
plot(t,EEG_filt); title('EEGdata.csv after filtering'); grid on; axis tight; xlim([0 20]);
xlabel('Time in seconds'); ylabel('Amplitude/\muV');
I have attached the results of the plots obtained as well as the magnitude response of the filter.
  2 Commenti
Cris LaPierre
Cris LaPierre il 7 Gen 2022
Could you expain more on why your results are incorrect, or perhaps describe what you think the results should look like?
Rudy Steel
Rudy Steel il 7 Gen 2022
I am not understanding the plot I obtained after filtering. I would assume I should obtain the same signal along the entire x-axis (the first 20seconds) with the difference now that the result would be cleaner

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 7 Gen 2022
You have a ringing artifact because you have such a high order filter. Notice that the y axis of your filtered data is scaled by 10^5. You can scale this to see what you expect.
EEGdata = load('EEGdata.csv');
Fs = 1200; % Sampling frequency
T = 1/Fs; % Sampling period
L = length(EEGdata); % Length of signal
t = [0:(L-1)]*T; % Time vector
%now using bandpass chebyshev type 2 filter
[A,B,C,D] = cheby2(10,40,[4 10]/600);
d = designfilt('bandpassiir','FilterOrder',20, ...
'StopbandFrequency1',4,'StopbandFrequency2',10, ...
'StopbandAttenuation',40,'SampleRate',1200);
sos = ss2sos(A,B,C,D);
%filtering original data
EEG_filt = filtfilt(d,EEGdata);
figure();
plot(t,EEG_filt); title('EEGdata.csv after filtering'); grid on; axis tight; xlim([0 20]);
xlabel('Time in seconds'); ylabel('Amplitude/\muV');
ylim([-10 10])
  2 Commenti
Cris LaPierre
Cris LaPierre il 7 Gen 2022
Things improve if you drop your filter order
EEGdata = load('EEGdata.csv');
Fs = 1200; % Sampling frequency
T = 1/Fs; % Sampling period
L = length(EEGdata); % Length of signal
t = [0:(L-1)]*T; % Time vector
%now using bandpass chebyshev type 2 filter
[A,B,C,D] = cheby2(10,40,[4 10]/600);
d = designfilt('bandpassiir','FilterOrder',8, ...
'StopbandFrequency1',4,'StopbandFrequency2',10, ...
'StopbandAttenuation',40,'SampleRate',Fs);
sos = ss2sos(A,B,C,D);
%filtering original data
EEG_filt = filtfilt(d,EEGdata);
plot(t,EEG_filt); title('EEGdata.csv after filtering'); grid on; axis tight; xlim([0 20]);
xlabel('Time in seconds'); ylabel('Amplitude/\muV');
ylim([-10 10])
Rudy Steel
Rudy Steel il 7 Gen 2022
Yes, I in fact did not consider the scale of the y-axis, I also now considered reducing the order of the filter and you are right the results do improve. Thank you

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by