I am trying to implement an IIR bandpass in Matlab. There are two things I don't understand. But first of all, let me post the code.
fs = 50000; %Hz
f1filter = 1000; %Hz
f2filter = 2000; %Hz
filterOrdnung = 6; %erzeugt (2 * filterOrdnung) Filterkoeffizienten
anzahlFilter = 5; %Anzahl der zu berechnenden Filter zur Auswertung
schrittweiteVerschiebung = 1000; %Verschiebung in Hz
astop = 20; %Verstärkung an den Bandgrenzen des Bandpasses
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k = zeros(anzahlFilter, 1); %Vektor für Gain
z = zeros(2*filterOrdnung,anzahlFilter); %Matrix für
%Nullstellen
p = zeros(2*filterOrdnung, anzahlFilter); %Matrix für
%Polstellen
sos = zeros(anzahlFilter * filterOrdnung + (anzahlFilter - 1), 6); %Matrix für Filterkoeffizienten
[z(:,1), p(:,1), k(1,1)] = cheby2(filterOrdnung, astop, [((2*f1filter)/fs)...
((2*f2filter)/fs)]);
[sos(1:6,:), g] = zp2sos(z(:,1),p(:,1),k(1,1)); %Output form:[b01,b11,b21,1,a11,a21
% b02,b12,b22,1,a12,a22
% b0N,b1N...........a2N]
fvtool(sos(1:6, :),'Analysis','freq');
So I want to create a bandpass of the bandwith of 1000Hz to 2000Hz. The filter order is the 6th order and the stop attenuation should be 20dB. I want to have the Structure of second order form. (By the way, is there any specific Matlab function to create an IIR filter as a cascade of Directform II structures?)
I am creating "sos" much larger than I need it to be now because I want to create several different bandpasses, but let's just focus on this example.
1)First question: Why do I receive 12 numerator and 12 denominator coefficients when I only have 6th order IIR? In the books I have read, that for a 6th order IIR I should receive 7 numerator and 7 denominator coefficients, with the first denominator coefficient = 1.
2)At the header of the code, I declare astop as 20dB. The Matlab documentation of cheby2 tells me, that this is the attenuation of the stopband. But when I let the code run and look at the magnitude, the magnitude of the passband is about 20dB. I expected it to be 0dB while the stopband should be -20dB. The normed frequencys seem to be about correct though. I hope I could explain my problems well enough.