%Erik Kronbeck
%Person # 27601719
%Matlab Project #5

%1.
%The chirp transfrom algorithm(CTA) is an algorithm based on expressing the 
%DFT as a convolution. It does not simplify the DFT at all but it is very 
%useful in several applications. It is best used for implementing 
%technologies that are well suited for doing convolution with a fixed, 
%prespecified impulse response. It is also more flexible because it can be 
%used to compute any set of equally spaced samples of the Fourier transform
%unit circle.

%The Chirp z-transform(CZT) is used in Matlab by using the CZT function.
%It is used by the following command:
%           CZT(X,M,W,A) 
%    where:   X is the sequence 
%             M is the length of the transform
%             W is the complex ratio between points on the coutour described
%               by z=Aw^-(0:M-1)
%             A is the complex starting point

%It should be noted that the CTA is a special case of the CZT algorithms.

%2. 

%Advantages of Chirp Z-transform

%1) N=M for FFT but N does not equal M for CTA

%2) w0 is 0 for any value of CTA and w0 is 0 for FFT

%3) delta w is any value for CTA and is 2pi/N for FFT

%Certain technologies such as charge-coupled devices(CCD) and surface 
%acoustic wave(SAW) devices are useful applications for the CZT because
%it is helpful with them to implement convolution with a fixed, prespecified
%impulse response. They can implement FIR filters with the filter impulse
%response being specified at the time of fabrication by a geometric pattern 
%of electrodes.

%3.
%Particular case

fs=1000;

t=0:1/fs:2;

f=15;  

w=2*pi*f;

dw=2*pi*0.75;

x1=sin(w*t);

x2=2*sin((w+dw)*t);

x3=3*sin((w-dw)*t);

x=x1+x2+x3;

figure(1);

plot(t,x);

title('plot of x(t)');

figure(2);

freqz(x);

title('frequency response of x');

h1=fir1(50,[0.015 0.035],kaiser(51,.5));

y=conv(x,h1);

figure(3);

freqz(y);

title('frequency response of y');

f1=10;

f2=20;

m1=512;

w1=exp(-j*2*pi*(f2-f1)/(m1*fs));

a1=exp(j*2*pi*f1/fs);

z1=czt(y,m1,w1,a1);

fz1=((0:length(z1)-1)'*(f2-f1)/length(z1))+f1;

figure(4);

plot(abs(z1));

title('plot of czt of y');
figure(5);
plot(fz1,abs(z1));

axis([10 15 0 3000]);

title('plot of czt of y magnified from 10-15');

figure(6);

plot(fz1,abs(z1));

axis ([12 14.5 0 3000]);

title('plot of czt of y magnified from 12-14.5');

figure(7);

plot(fz1,abs(z1));

axis ([13 14 0 3000]);

title('plot of czt of y magnified from 13-14');

figure(8);

plot(fz1,abs(z1));

axis ([13.6 14 0 3000]);

title('plot of czt of y magnified from 13.6-14');