I'm a DSP newbie trying to get into the field. Despite being able to use some of the MATLAB tools, I'm still not completely solid on some intuition of the frequency domain.
I've implemented a biquad Chebyshev type 2 filter in direct form II using design()
and fdesign()
, and cascaded an all pass filter before it to make sure the phase is approximately linear using iirgrpdelay()
Here are my filter coefficients. The cascade filter is made up of two stages; the first is an all-pass equalizing filter and the second is my band-stop filter.
Stage 1 SOSMatrix: 0.381213874783434 -1.557955120504960 1.591776409857931 1.000000000000000 -0.978752487382327 0.239489586868207 0.552531400073819 -0.022041931397907 0.944632862505602 1.000000000000000 -0.023333860458169 0.584916555420538 0.208375162206942 0.338597008794322 0.403080816836635 1.000000000000000 0.840022632313836 0.516956286439685 0.738077366524991 2.000000000000000 1.498774195719990 1.000000000000000 1.334423828293380 0.492454012507487 Stage 1 ScaleValues: 0.260737099485881 1.000000000000000 1.000000000000000 1.000000000000000 4.222053367426932 Stage 2 SOSMatrix: 1.000000000000000 -1.649455187829982 1.000000000000000 1.000000000000000 -1.104541883178642 0.913753853150600 1.000000000000000 -1.264410719232027 1.000000000000000 1.000000000000000 -1.653222532296871 0.943601232271565 1.000000000000000 -1.611538275581591 1.000000000000000 1.000000000000000 -1.117951080612895 0.785871033092721 1.000000000000000 -1.329923547522389 1.000000000000000 1.000000000000000 -1.524529858509588 0.841251385596782 1.000000000000000 -1.536278103762843 1.000000000000000 1.000000000000000 -1.372242531855038 0.762644118662937 1.000000000000000 -1.433307330009434 1.000000000000000 1.000000000000000 -1.221557613144382 0.735502467713962 Stage 2 ScaleValues: 0.954605779388083 0.954605779388083 0.901497869853696 0.901497869853696 0.873798810487316 0.873798810487316 1.000000000000000
The frequency response looks according to the spec., but my input is coming out attenuated. I should put a legend here but the blue line is the input and yellow line the output.
Here's how I'm constructing my sinusoidal input; the amplitude is -6dB full-scale and its frequency is set to 0.01. My filter sampling frequency is 1MHz, and it's to my understanding that this sinusoid should be within the passband.
% Generate input
% input attenuation; <db> and <absolute value>
input_att_db = -6;
input_att_ab = 10 ^ (input_att_db / (-20));
% input sinusoid with angular frequency w0 for L samples
f0 = 0.01;
w0 = 2 * pi * f0;
L = 1000;
n = 0:L - 1;
input = sin(w0 * n) / input_att_ab;
I'm then just calling the filter as if its a function. I named my filter cas
short for "cascade".
outputi = cas(input);
plot(n, outputi)
Is this normal? If not what could I be doing wrong? Any pointers would be much appreciated!
cas()
is doing. $\endgroup$