Filter Question - FIR and IRR
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hey everyone, I'm trying to do the following:
Make an IIR and FIR filter that passes between 40-50 KHz, and blocks out noise that is occurring at 75Khz. There is 25 dB of stopband attenuation, and the passband ripple is set at 3.
With that noted, here is the code I have so far:
f_p=40000; %Pass Frequency in Hz
f_s=50000; %Stop Frequency in Hz
r_s=25; %Stopband Attenuation in dB
r_p=3; %Passband Ripple
d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',38e3,f_p,f_s,53e3,r_s,r_p,140e3);
%Fst1 — frequency at the edge of the end of the first stop band. Specified in normalized frequency units by default.
%Fp1 — frequency at the edge of the start of the pass band. Specified in normalized frequency units by default.
%Fp2 — frequency at the edge of the end of the pass band. Specified in normalized frequency units by default.
%Fst2 — frequency at the edge of the start of the second stop band. Specified in normalized frequency units by default.
%Ap — passband ripple in dB (the default units).
%Ast1 — attenuation in the first stopband in dB (the default units).
%Ast2 — attenuation in the second stopband in dB (the default units).
% Create the FIR filter
Hd2 = design(d,'equiripple');
fvtool(Hd2)
%Create the IIR filter
Hd1 = design(d,'butter');
fvtool(Hd1);
------------------------------------------------------------------
First off, does my methodology seem correct for creating an FIR and IIR filter that will accomplish this goal? Secondly, when I run the code, this is the error message I get:
??? Error using ==> fdesign.abstracttype.equiripple at 13
Frequency specifications must be between 0 and 1.
Error in ==> fdesign.abstracttype.superdesign at 106
Hd = feval(method, this, varargin{:});
Error in ==> fdesign.abstracttype.design at 11
varargout{1} = superdesign(this, varargin{:});
Error in ==> PEPractice at 13
Hd2 = design(d,'equiripple');
-----------------------------------------------------------------
Any insight as to what is wrong? Please help if you can!
0 comentarios
Respuesta aceptada
Wayne King
el 16 de Nov. de 2011
You have to use a supported specificaton string. If you want to limit the order to a fixed value, then you have to realize, you may not be able to specify other things. In a minimum-order design, you are allowing the filter design method to find the order, if you specify it, then you have to give up certain things.
d = fdesign.lowpass('N,Fp,Ap,Ast',4,50e3,3,25,200e3);
Hde = design(d,'ellip');
The above gets you more than 25 dB of stopband attenuation by 75 kHz.
But you may like:
Hd = design(d,'equiripple');
better.
Más respuestas (9)
Walter Roberson
el 14 de Nov. de 2011
Do not use frequency in hertz: use proportionate frequency in terms of the fraction of the frequency compared to the nyquest frequency.
0 comentarios
Honglei Chen
el 14 de Nov. de 2011
The approach looks fine. I assume your sampling frequency is 140 kHz? If that's the case, I think you are just missing an r_s in front of 140e3 because you need to specify stop band attenuation for both sides, as indicated in the spec string.
HTH
0 comentarios
Wayne King
el 14 de Nov. de 2011
Hi, if you specify your filter design in Hz, then the sampling frequency has to be a trailing scalar. In the following:
d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',38e3,f_p,f_s,53e3,r_s,r_p,140e3);
You forgot the specification for your 2nd stopband. In a bandpass design there are two stopbands.
Try:
d = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2',38e3,f_p,f_s,53e3,r_s,r_p,r_s,140e3);
Wayne King
el 14 de Nov. de 2011
fdesign.bandpass() works with normalized frequencies unless you input the sampling frequency as a scalar trailing all other specifications. Your filter specification:
'Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2'
expects 7 input argument values in the correct order. If you want to specify those frequencies, Fst1, Fp1, etc. in Hz (not normalized frequency), then you must add an 8th input argument at the end of the others. You do NOT change the specification string, just add a comma and then your sampling frequency. You should NOT use a specification for sampling frequency.
That is how the fdesign interface is designed. All of them work that way.
You have created two designs Hd1 and Hd2. You could have designated them as
HdFIR = design(d,'equiripple');
% and
HdIIR = design(d,'butter');
if that makes easier to remember. To label fvtool() output, you can use title()
fvtool(HdFIR); title('FIR Filter');
Or you can use a handle and then set a legend.
hfvt = fvtool([HdFIR HdIIR]);
legend(hfvt,'FIR Filter','IIR Filter');
0 comentarios
Wayne King
el 16 de Nov. de 2011
You did not tell us your sampling frequency. I'm assuming that your sampling frequency is not 140 kHz in this instance because your proposed stopband frequency is higher than the Nyquist. So I'll assume 200 kHz for this example.
d = fdesign.lowpass('Fp,Fst,Ap,Ast',50e3,75e3,3,25,200e3);
By the way, are you reading the MATLAB documentation? This is all explained with examples.
Wayne King
el 16 de Nov. de 2011
Hi Alex, if you read the documentation, order specification is possible in both fdesign.bandpass and fdesign.lowpass. Please look in the documentation for specification strings with N, Na, or Nb.
Some of these order specifications require the DSP System Toolbox, but you can certainly specify an order with just Signal. For example, just for fdesign.lowpass
'N,F3dB'
'Nb,Na,F3dB'
'N,F3dB,Fst' (*)
'N,F3dB,Ap' (*)
'N,F3dB,Ast' (*)
'N,F3dB,Ap,Ast' (*)
'N,Fc'
'N,Fc,Ap,Ast'
'N,Fp,Ap'
'N,Fp,Ap,Ast'
'N,Fp,F3dB' (*)
'N,Fp,Fst'
'N,Fp,Fst,Ap' (*)
'N,Fp,Fst,Ast' (*)
'N,Fst,Ast'
'N,Fst,Ap,Ast' (*)
'Nb,Na,Fp,Fst' (*)
The above all allow you to specify the order.
0 comentarios
Alex
el 16 de Nov. de 2011
4 comentarios
Honglei Chen
el 17 de Nov. de 2011
What effect of this 50 Ohm do you want to take into consideration? If these are pure resistance then they are frequency independent and I don't see why it will affect the frequency response except a constant scale.
Ver también
Categorías
Más información sobre Filter Design en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!