%  Name:  Kris Tuthill
%  Date: 12/04/01
%  Coures: EE416
%
%  Project: 5
%
%
%  Chirp z-transform
%
%


% 1.

% The Chirp z-transform (czt) uses the next power-of-2 
% length FFT to perform a fast convolution when computing 
% the z-transform on a specified chirp contour.
% The chirp z-transform algorithm is a means by which 
% one can determine samples of the z-transform equally 
% spaced along a contour in the z-plane.  The chirp transform
% finds these samples along the unit circle, while the 
% chirp z-transform algorithm refers to samples along 
% a general contour.


% 2.

% The advantage of the chirp z-transform is that it
% enables one to calculate the samples of the z-transform 
% equally spaced over an arc or a spiral contour with an 
% arbitrary startingpoint and arbitrary frequency range. 
% region. In contrast, the frequency range of the DFT is strictly
% related to the sampling frequency. Furthermore, the chirp z-transform
% allows one to calculate an arbitrary number of samples
% along this contour, which arbitrarily reduces the error in frequency
% representation. The chirp z-transform allows one to leave the unit
% circle and calculate samples in the z-plane, while the DFT is limited
% to the unit circle. 


% 3.

fs= 1000;														% Stop frequency
f= 10;															% Signal frequency is 100Hz
w= 2*pi*f;													% Angular frequency
dw= 2*pi;											       	% Angular frequency offset
t= 0:1/fs:1;													% Time range

x= sin(w*t)+2*sin((w+dw)*t)+3*cos((w-dw)*t);			% Signal

h= fir1(50,[0.01 0.05], hamming(51));			       % FIR filter
y= conv(x, h);												% Convolution of filter and signal
Y= freqz(y);											    	% Z-transform of output
	

f1= 10;														% Start frequency for CZT
f2= 15;														% Stop frequency
m1= 1000;														% Number of elements									
w1= exp(-j*2*pi*(f2-f1)/(m1*fs));						% Complex frequency
a1= exp(j*2*pi*f1/fs);								    	% Complex frquency starting point

z= czt(y,m1,w1,a1);										   % Chir z-transform
fz= ((0:length(z)-1)'*(f2-f1)/length(z))+f1;	      % Frequency range

figure(1);													
subplot(211);
plot(abs(Y));												% Plot of DFT												
title('DFT of FIR filtered signal');	
xlabel('frequency');										
ylabel('amplitude');										
subplot(212);
plot(fz,abs(z)); 											% Plot of CZT
axis([f1 f2 0 2000]);										% Specify axis							
title('CZT of FIR filtered signal');	
xlabel('frequency');										
ylabel('amplitude');										

