- I think I realized a highpass filter, can you tell me what I did wrong and how to correct the code?
How can I create a bandpass FIR filter using firpm?
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
FRANCESCA SANASI
le 8 Oct 2023
Commenté : Star Strider
le 8 Oct 2023
I have to create a bandpass FIR filter for an EEG signal with cutoff frequencies [1,8] Hz and sampling rate= 500, I wanted to first use the firpmord command to find the minimum order for the filter to work and then realize the same filter with the same specifics through both firpm and the windows method with fir1 trying the minimum order, and higher order and a lower order to show how the filter changes, but there are some problems:
- when trying to use firpmord I don't know how to choose the amplitude and the deviation, i chose to have a rp=0.5 and rs=30 in dB but I don't know how to link them to dev or how to choose the amplitude
- I tried the formula for the dev that is on the matlab example but I can't understand if it's right and why should I use this formula
- I can't understand how to use the w parameter that I get from appliying firpmord.
- I think I realized a highpass filter, can you tell me what I did wrong and how to correct the code?
- If you're confident with filters applied to EEG do you think that I chose good values for rp and rs? Should I change them?
Here's the code:
fFIR= [1 8]; % frequenza di taglio in Hz
a=[0 1]; %ampiezza desiderata
rp= 0.5; %ripple banda passante in dB
rs= 30; %ripple banda di stop in dB
fs=500; % frequenza di campionamento in Hz
dev = [ 10^(-rs/20) (10^(rp/20)-1)/(10^(rp/20)+1)];
%ricavo l'ordine minimo del filtro
[n,fo, ao, w]=firpmord(fFIR,a,dev,fs);
b = firpm(n,fo,ao,w);
freqz(b,1,1024,fs)
title('Filtro FIR passabanda con frequenze di taglio [1,8] Hz')
2 commentaires
Paul
le 8 Oct 2023
Hi FRANCESCA,
For this part of your question:
Réponse acceptée
Star Strider
le 8 Oct 2023
I could not get this to work with firpm, since it apparently only works with lowpass filters.
Fs = 500;
Fn = Fs/2;
fcomb = [0.8 1 8 8.2]/Fn;
n = 2^12
hh = fir1(n, fcomb(2:3));
figure
freqz(hh, 1, 2^16, Fs)
set(subplot(2,1,1), 'XLim',[0 10])%, 'XScale','log')
set(subplot(2,1,2), 'XLim',[0 10])%, 'XScale','log')
Higher values for ‘n’ will produce steeper (shorter) transition regions, however they also lengthen the filter, requiring longer signals to work with it.
Your best option however is likely to use an IIR filter, designed by —
Wp = [1 8]/Fn; % Passband Frequency (Normalised)
Ws = [0.8 8.2]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 60; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptic Filter Design: Zero-Pole-Gain
n
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos2, 2^16, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',[0 10])%, 'XScale','log')
set(subplot(2,1,2), 'XLim',[0 10])%, 'XScale','log')
EEG_Filtered - filtfilt(sos,g,EEG);
.
2 commentaires
FRANCESCA SANASI
le 8 Oct 2023
Modifié(e) : FRANCESCA SANASI
le 8 Oct 2023
Star Strider
le 8 Oct 2023
As always, my pleasure!
You had better results with firpm than I did!
I do not usually use firpm, preferring fir1, usually with kaiserord, to create comb filters that have multiple passbands and stopbands that make them preferable to and more efficient than designing a number of IIR filters to do the same thing. For single bandpass or stopband filters or with short signals (that would not work with FIR filters), I generally use elliptic filters.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Digital Filter Design dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



