
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dhanushka Amarasinghe
% EE 416
% Project No.5
% Due-12/03/01
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;


%  (1) Explain Chirp Z-transform (CZT) and Chirp Transform Algorithm (CTA)

%   The CTA is an algorithm that is used to determine sapmles that are equally
%   spaced in along a contour in z-plane. CZT is used to find these samples in 
%   unit circle.

%  (2) Enumerate key advantages and applications of Chirp Z-Transform (CZT)

%   Some of the advantages of CZT are
%   * It  can be used to calculate an arbitary number of samples along its 
%   contour which reduces the error in freq. representation.
%   * CZT can be used to find samples which is equally spaced over a arc or
%   a spiral contour.
%   * CZT can be used to find samples outside the unit circle. But DFT is 
%   limits this to unit circle.


%  (3) Use Matlab to show advatage of CZT

fs=1000;										% Set stop frequency
f=15;											% Set frequency to be 60Hz
w=2*pi*f;										% Find angular frequency
dw=2*pi*3/4;									% Frequency increment
t=0:1/fs:1.5;									% Time range

x=sin(w*t)+2*sin((w+dw)*t)+3*cos((w-dw)*t);		% Define signal
Xz=freqz(x);									% Z-Transform of x

d1=fir1(50,[0.015 0.035],kaiser(51,0.5));		% Define filter
y1=conv(x,d1);									% Filter output
Y=freqz(y1);									% Z-transform of y1
	
figure(1);										
plot(abs(Y));									% Plot Z-transform Yz
title('Plot of Z-Transform');	            	
xlabel('frequency');							
ylabel('amplitude');							


f1=7.5;
f2=17.5;
e1=512;											% Number of elements									
q1=exp(-j*2*pi*(f2-f1)/(e1*fs));    			% Complex ratio
a1=exp(j*2*pi*f1/fs);							% Starting point

chz=czt(y1,e1,q1,a1);							    % Finding CZT function
fchz=((0:length(chz)-1)'*(f2-f1)/length(chz))+f1;	% Frequency range

figure(2);										
plot(fchz,abs(chz));							% Plot the Chirp Z-transform computed
axis([f1 f2 0 4000]);							% Set axis size

fs=2000;										% Stop frequency
ft2=20;											
w2=2*pi*ft2;									% Angular frequency
dw=2*pi*3/4;									% Frequency increment
t=0:1/fs:1.5;									

x2=sin(w2*t)+2*sin((w2+dw)*t)+3*cos((w2-dw)*t);	% Define signal
Xz=freqz(x2);									% Z-Transform of x
h2=fir1(60,[0.035 0.055],kaiser(61,0.6));		% Define filter
y2=conv(x2,h2);									% Filter output
Yz=freqz(y2);									% Z-transform of y2



f2=17.5;
f3=27.5;
e2=1024;										% Number of elements									
q2=exp(-j*2*pi*(f3-f2)/(e2*fs));				% Complex ratio
a2=exp(j*2*pi*f2/fs);							% Complex starting point

chz2=czt(y2,e2,q2,a2);							% Compute using CZT function
fchz2=((0:length(chz2)-1)'*(f3-f2)/length(chz2))+f2;  % Set frequency range

figure(3);										
plot(fchz2,abs(chz2));							% Plot the Chirp Z-transform computed
axis([f2 f3 0 4000]);							% Set axis size



fs=1500;										% Stop frequency
ft3=25;											% Frequency to be 25Hz
w3=2*pi*ft3;							    	% Angular frequency
dw=2*pi*3/4;									% Frequency increment
t=0:1/fs:1.5;									

x3=sin(w3*t)+2*sin((w3+dw)*t)+3*cos((w3-dw)*t);	
Xz=freqz(x3);									% Z-Transform of x
h3=fir1(70,[0.055 0.075],kaiser(71,0.7));		% Define filter
y3=conv(x3,h3);									% Filter output
Yz=freqz(y3);								    % Z-transform of y1


f3=27.5;
f4=37.5;
e3=512;											% Number of elements									
q3=exp(-j*2*pi*(f4-f3)/(e3*fs));				% Set complex ratio
a3=exp(j*2*pi*f3/fs);							% Set complex starting point

chz3=czt(y3,e3,q3,a3);							% Compute using CZT function
fchz3=((0:length(chz3)-1)'*(f4-f3)/length(chz3))+f3;	% Set frequency range

figure(4);										
plot(fchz3,abs(chz3));							% Plot the Chirp Z-transform computed
axis([f3 f3 0 4000]);							% Set axis size







