% Kevin Brenon
% 26785079
% EE416 Project 5
% Dec. 5, 2001

% The Chirp Z-Transform

% 1. Explain the concept of the Chirp Z-Transform and the Chirp Transform Algorithm.
%		The CTA is based on expressing the DFT as a convolution. The CTA contains a 
%		complex exponential sequence with linearly increasing frequency.  In radar
%		systems, this type of signal is called a chirp signal, hence the name.  The
%		more general form of the CTA is the Chirp Z-transform.  The CZT is used to 
%		obtain smaples of the z-transform equally spaced in angle on a spiral contour 
%		in the z-plane.

% 2. Enumerate some of the key advantages and applications of the chirp z-transform.
%		The CZT is more flexible that the FFT since it can be used to compute any set 
%		of equally spaced samples of the Fourier Transform on the unit circle.  It is 
%		also useful for doing convolutions with fixed, prespecified impulse responses.
%		The CZT is used in radar and sonar signal processing for pulse compression.

% 3. Use MATLAB to show the advantage of using the CZT over its counterpart in a 
%    particular case.

fs = 1000;
F = 12;
W = 2*pi*F;
dW = 2*pi*0.75;
t = 0:1/fs:1.5;
x1 = 1*sin(W*t);				%Create the input signal in three sections, then add
x2 = 2*sin((W+dW)*t);		%them together.
x3 = 3*cos((W-dW)*t);
x = x1+x2+x3;
figure(1);
plot(t,x)
title('The Input Signal x(t)');
ylabel('x(t)');
xlabel('Time');
figure(2);
freqz(x);
title('The Input Signal x(t)');

h = fir1(50,[0.015 0.035],kaiser(51,0.5));	%Create an FIR filter using a Kaiser
[y,ty] = linfilt(x,t,h,t);							%window, then evaluate the output
figure(3);												%using the linfilt function.
plot(ty,y)
title('The Output y(t) Through an FIR Filter h(t)')
ylabel('y(t)');
xlabel('Time');
figure(4);
freqz(y)
title('The Output y(t) Through an FIR Filter h(t)')

fmin = 0;
fmax = 25;
m = 512;
w = exp(-j*2*pi*(fmin-fmax)/(m*fs));
a = exp(j*2*pi*fmin/fs);
ch = czt(y,m,w,a);			%Perform the CZT and set up the limits.
fz = ((0:length(ch)-1)'*(fmax-fmin)/length(ch))+fmin;
figure(5);
plot(fz,20*log10(abs(ch)))
title('The Chirp Z-Transform of x(t) Through an FIR Filter');
ylabel('Magnitude (dB)');
xlabel('Frequency');
figure(6);
freqz(ch)
title('The Chirp Z-Transform of x(t) Through an FIR Filter');

% Zoom in on the CZT plot to show detail.
figure(7);
subplot(3,1,1);
plot(fz,20*log10(abs(ch)))
title('The Chirp Z-Transform of x(t) Through an FIR Filter');
ylabel('Magnitude (dB)');
axis([5 20 -20 30]);

subplot(3,1,2);
plot(fz,20*log10(abs(ch)))
ylabel('Magnitude (dB)');
axis([7.5 17.5 -20 30]);

subplot(3,1,3);
plot(fz,20*log10(abs(ch)))
ylabel('Magnitude (dB)');
xlabel('Frequency');
axis([10 14 -20 30]);

