# cascade realisation from direct realisation

I am trying to convert filter realisation from Direct form 1 to cascade using function provided from Digital signal processing by Proakis. I designed lowpass IIR filter and extracted numerator and denominator coefficients. I used fvtool to plot pole zero as well as magnitude response. But when I use dir2cas function provided in textbook, matlab shows an error while plotting using fvtool. Can someone help?

The filter function:

filte = designfilt('lowpassiir','PassbandRipple',1,'StopbandAttenuation',30, ...
'PassbandFrequency', 3.4e3, 'StopbandFrequency', 4e3, ...
'SampleRate', 16e3);
sos = filte.Coefficients;
[b,a] = sos2tf(filte.Coefficients);
%fvtool(sos);

[b0, B0, A0] = dir2cas(b,a);
fvtool(B0,A0);


function [b0, B, A] = dir2cas(b,a);
b0 = b(1);
b = b/b0;
a0 = a(1);
a = a/a0;

b0 = b0/a0;
M = length(b);
N = length(a);

if N >M
b = [b zeros(1, N-M)];
elseif M > N
a = [a zeros(1, N-M)];
N = M;
else
NM = 0;
end

k = floor(N/2);
B = zeros(k,3);
A = zeros(k,3);

if k*2 == N;
b = [b 0];
a = [a 0];
end

broots = cplxpair(roots(b));
aroots = cplxpair(roots(a));
for i = 1:2:2*k
Brow = broots(i:1:i+1,:);
Brow = real(poly(Brow));
B(fix((i +1)/2),:) = Brow;
Arow = aroots(i:1:i+1,:);
Arow = real(poly(Arow));
A(fix((i+1)/2),:) = Arow;
end

• I’m voting to close this question because reading the documentation of fvtool should solve the problem. – Matt L. Jul 21 at 10:02
• Hi Matt, I went through fvtool documentation, however it still says error. Moreover after converting to cascade, I have 3 outputs numerator, denominator and bo constant, which connects 2 cascade functions. – RohitM Jul 22 at 10:10