%% Example 4.17 CDF(6,2) filters

syms z y

%
% For n=4 the Bezout polynomial is

B = 1+4*y+10*y^2+20*y^3

%
% For the transform of the highpass synthesis filter I first substitute y=\frac{\left(z^{-1} +2+z\right)}{4} and multiply by 16z^{-1} {\left(1-z\right)}^2.
%

G = 16*z^(-1)*(1-z)^2 * subs(B,y,(z+2+z^(-1))/4);
expand(G)

%
% I write this in terms of \omega ,z=e^{i\omega }. I see that it is twice the expression G2 below.
%

syms w;
G2 = 5*cos(4*w)+30*cos(3*w)+ 56*cos(2*w) - 14*cos(w) - 77

%
% Here's the check that they are equal:
%

simplify(subs(G,z,exp(i*w))-2*G2)

%
% so symbolically the transform of the high pass synthesis filter, in terms of \omega is
%

G3 = (sqrt(2)/32)*exp(-4*i*w)*G2

%

G1 = @(w) eval(vectorize(G3))

%
% The low pass filter is

Glow = sqrt(2)*(1+z)^6/64

%
% I substitute z=e^{i\omega } then turn it in to a MATLAB function

Glow3 = subs(Glow,z,exp(i*w))
G0 = @(w) eval(vectorize(Glow3))

%
%

W = 0:0.001:pi; 
figure
plot(W,abs(G1(W)))
hold on
plot(W,abs(G0(W)),'--')
title('CDF(6,2) synthesis filters')
xlabel('frequency \omega (multiples of \pi)')
hold off
axis([0 pi 0 7])
annotation('textarrow',[0.4997 0.3747],[0.2942 0.1942],'String','low pass filter')
annotation('textarrow',[0.7176 0.6158],[0.6593 0.5735],'String','high pass filter')
annotation('textarrow',[0.3265 0.2229],[0.4007 0.2745],'String','cross over point')