% Jonathon Panek   
% EE 416
% Project 5
% Due 12/3/01
% ===========================================================================
% Chirp z-Transform (CZT) & Chirp Transform Algorithm (CTA)
% ===========================================================================
% The chirp z-transform is used to resolve frequencies which are 
% indistinguishable from the unit circle. The method is to choose a contour 
% inside the unit circle which is closer to the poles of the system, and then
% evaluate the z-transform along this contour. Since the contour lies closer 
% to the poles, the resolution between poles will be greater.
% The chirp z-transform algorithm (CTA) is a means by which one can determine 
% samples of the z-transform equally spaced along a contour in the z-plane.
% ===========================================================================
% Some advantages of the CZT & CTA:
% 1. It enables one to calculate the samples of the z-transform equally 
%    spaced over an arc or a spiral contour with an arbitrary starting point 
%    and arbitrary frequency range. 
% 2. The CZT allows calculation of an arbitrary number of samples along this 
%    contour, not limited to the contour of the unit circle which reduces the 
%    error in frequency representation. For the DFT case, if one requires a 
%    frequency representation of higher resolution, the only solution is to 
%    zero-pad the signal (i.e., the number of sample points in the DFT is the 
%    same as the number of points in the signal). 
% ===========================================================================
% The chirp transform is commonly used in radar and sonar signal processing 
% for pulse compression. 
% ===========================================================================
	 clear all;
% Implement CZT and show the advantage over its counterpart FIR
    fs=1000;
    t=0:1/fs:1.5;
    F=10;
    w=2*pi*F;
    dw=2*pi*.8;
% Signal x(t)
    x=sin(w*t)+2*sin((w+dw)*t)+3*cos((w-dw)*t);
    figure(1);
    plot(t,x);
    title('x(t)=sin(w*t)+2*sin((w+dw)*t)+3*cos((w-dw)*t)');
    xlabel('t');
    ylabel('x(t)');
    
% Convolve with filter and plot magnitude 
	 figure(2);
	 subplot(221);
    h1=fir1(30,[0.001 0.003], kaiser(31,.2));
    y1=conv(x,h1);
    y1=y1(1:1501);
    plot(t,y1);
    title('Filter h1t) Output');
% Convolve with filter and plot magnitude 
    subplot(222);
	 h2=fir1(30,[0.002 0.004], kaiser(31,.4));
    y2=conv(x,h2);
    y2=y2(1:1501);
    plot(t,y2);
    title('Filter h2(t) Output');
% Convolve with filter and plot magnitude
    subplot(223);
	 h3=fir1(30,[0.002 0.006], kaiser(31,.6));
    y3=conv(x,h3);
    y3=y3(1:1501);
    plot(t,y3);
    title('Filter h3(t) Output');
% Convolve with filter and plot magnitude 
    subplot(224);
	 h4=fir1(30,[0.004 0.008], kaiser(31,.8));
    y4=conv(x,h4);
    y4=y4(1:1501);
    plot(t,y4);
    title('Filter h4(t) Output');

% CZT 1
    f1=10;
    f2=20;
    M=length(x);
    A=exp(j*2*pi*f1/f2);
    W=exp(j*2*pi*(f2-f1)/(M/fs));
    Z1=czt(y1, M, W, A);
    figure(3);
    freqz(Z1);
    title('CZT 1');
% FFT 1
    F1=fft(y1);
    figure(4);
    freqz(F1);
    title('FFT 1');

% CZT 2
    f1=30;
    f2=40;
    M=length(x);
    A=exp(j*2*pi*f1/f2);
    W=exp(j*2*pi*(f2-f1)/(M/fs));
    Z2=czt(y2, M, W, A);
    figure(5);
    freqz(Z2);
    title('CZT 2');
% FFT 2
    F2=fft(y2);
    figure(6);
    freqz(F2);
	 title('FFT 2');
    
% CZT 3
    f1=10;
    f2=30;
    M=length(x);
    A=exp(j*2*pi*f1/f2);
    W=exp(j*2*pi*(f2-f1)/(M/fs));
    Z3=czt(y3, M, W, A);
    figure(7);
    freqz(Z3);
    title('CZT 3');
% FFT 3
    F3=fft(y3);
    figure(8);
    freqz(F3);
	 title('FFT 3');
    
% CZT 4
    f1=20;
    f2=40;
    M=length(x);
    A=exp(j*2*pi*f1/f2);
    W=exp(j*2*pi*(f2-f1)/(M/fs));
    Z4=czt(y4, M, W, A);
    figure(9);
    freqz(Z4);
    title('CZT 4');
% FFT 4
    F4=fft(y4);
    figure(10);
    freqz(F4);
	 title('CZT 4');


        


   