# How to plot magnitude and phase response of 2 cascaded filters in Matlab?

How would I go about plotting a magnitude and phase response of a system that consists of two cascaded 2nd order Butterworth filters in Matlab? Filters are the same.

% Filter coeffs:
[B, A] = butter( 2, 1000/8000*2, 'high' ); % Cutoff at 1000 Hz, fs 8000 Hz.

% Cascade 2 filters: input -> filter -> filter -> output :
[out1, state1 ] = filter( B, A, in,   state1);
[out2, state2 ] = filter( B, A, out1, state2);


Using MATLAB/Octave as the tool, the following approach lets you plot the magnitude & phase samples of the DTFT of the cascade of the two discrete-time LTI filters using their LCCDE coefficient vectors $$b[k]$$, and $$a[k]$$, assuming they have LCCDE representations..

Since the cascade LTI system is described as: $$h[n] = h_1[n] \star h_2[n]$$ and consequently $$H(z) = H_1(z) H_2(z)$$

Where the $$h[n]$$ is the impulse response of the cascade system and $$H(z)$$ is its transfer function (Z-transform of impulse response). Those $$h_1[n]$$ and $$h_2[n]$$ refer to the impulse responses of the individual systems that make up the cascade.

Assuming that individual systems do have rational Z-transforms, then we have the following expression for the composite (cascade) system Z-transfom:
\begin{align} H(z) &=\frac{ \sum_{k=0}^{M} B[k]z^{-k} } {\sum_{k=0}^{N} A[k]z^{-k}} = H_1(z) H_2(z) \\ \\ &= \left( \frac{ \sum_{k=0}^{M_1} b_1[k]z^{-k} } {\sum_{k=0}^{N_1} a_1[k]z^{-k}} \right) \left( \frac{ \sum_{k=0}^{M_2} b_2[k]z^{-k} } {\sum_{k=0}^{N_2} a_1[k]z^{-k}} \right) \end{align}

Where individual coefficients $$b_1[k],a_1[k],b_2[k],a_2[k]$$ are those that represent the cascaded systems.

We want $$B[k]$$ and $$A[k]$$ that represent the cascade system, from which we can use the following Matlab/Octave function to plot the DTFT magnitude and phase responses, assumimg that the cascade is a stable LTI system so that it will have a frequency response function:

figure,freqz(B,A);


Now it can be shown by polynomial manipulations that the coefficients $$B[k]$$ and$$A[k]$$ are related to the individual coefficients $$b_1[k],a_1[k],b_2[k],a_2[k]$$ as the following: $$B[k] = b_1[k] \star b_2[k]$$ and $$A[k] = a_1[k] \star a_2[k]$$

Hence the required frequency response plot can be obtained in the combined call as follows:

figure,freqz(conv(b1,b2),conv(a1,a2));


where b1,a1 and b2,a2 are the coefficient vectors that represent the individual systems. The method can be generalised to N systems in cascade.

When you pass a signal from two cascaded filters, what happens is that the magnitude response of the whole chain is the product of individual filters, and the phase response is the sum of individual phase responses. This is because the transfer functions are multiplied in the cascade implementation.

So if the frequency response of the single filters are $$H_A(w)=|H_A(w)|e^{j\angle H_A(w)}$$ $$H_B(w)=|H_B(w)|e^{j\angle H_B(w)}$$ then the frequency response of the two cascaded filters (overall) is \begin{align} H_{AB}(w)&=H_A(w)H_B(w)\\ &=\left(|H_A(w)|e^{j\angle H_A(w)}\right)\left(|H_B(w)|e^{j\angle H_B(w)}\right)\\ &=|H_A(w)||H_B(w)|e^{j(\angle H_A(w)+\angle H_B(w))} \end{align}

You can use [h,w] = freqz(b,a) in Matlab to get the frequency response of your desired filters. Use abs and angle to find the magnitude and phase:

...
[hA,w] = freqz(bA,aA);
[hB,w] = freqz(bB,aB);
hAB = hA.*hB;
MagResp = 20*log10(abs(hAB));
PhaseResp = angle(hAB);
plot(w,MagResp)
...


when the two filters are identical, then the overall magnitude is squared and the overall phase is scaled by two: \begin{align} H_{AA}(w)&=\left(|H_A(w)|e^{j\angle H_A(w)}\right)\left(|H_A(w)|e^{j\angle H_A(w)}\right)\\ &=|H_A(w)|^2e^{j2\angle H_A(w)} \end{align}

• Yes, filter is the same. – Danijel Mar 27 '17 at 11:51
• Yes, I added the general case at the beginning, then the identical case at the end. – msm Mar 27 '17 at 12:09
• Shouldn't it be wAB = w + w, and then plot(wAB)? Is angle(hAB) necessary? – Danijel Mar 27 '17 at 12:43
• w is the frequency axis and remains fix. We should just add function values at given w values. – msm Mar 27 '17 at 20:03
• angle(hAB) gives you the phase of the complex array hAB. Without that, you just have a bunch of complex values of size legth(w). – msm Mar 28 '17 at 1:42