%% Convert Coupled Allpass Filter Lattice to Transfer Function
% Compute the reflection coefficient using tf2cl function.

[b,a] = cheby1(10,.5,.4); 
[k1,k2,beta] = tf2cl(b,a);

% Construct the original and the power-complementary filters.

[num,den,numpc] = cl2tf(k1,k2,beta);  
[h,w] = freqz(num,den); 
hpc = freqz(numpc,den);

% Plot the frequency response.

subplot(211)
plot(w./pi,20*log10(abs(h)),'k')
hold on;
grid on;
plot(w./pi,20*log10(abs(hpc)),'b') 
xlabel('Normalized Frequency (x \pi radians/sample)');
ylabel('dB');
legend('Original Filter','Power Complementary Filter',...
    'Location','best');
subplot(212)
plot(w./pi,unwrap(angle(h)),'k')
hold on; 
grid on;
xlabel('Normalized Frequency (x \pi radians/sample)');
ylabel('Phase (radians)');
plot(w./pi,unwrap(angle(hpc)),'b')

% Copyright 2012 The MathWorks, Inc.