%Damon Praefke
%Matlab project 4
%25080241



width1=(0.5*pi)-(0.3*pi);
width2=(0.8*pi)-(0.6*pi);
width=width2;              %width1=width2

As=80;
B=0.1102*(As-8.7)
M=round((As-8)/(2.285*width))

w1c=(0.5*pi+0.3*pi)/2;
w2c=(0.8*pi+0.6*pi)/2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Input signal

n=[0:449];
x=cos(.2*pi*n)+sin(.54*pi*n)+sin(.56*pi*n)+cos(.58*pi*n)+cos(.9*pi*n);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Ideal bandpass filter

t=[-24:25];

hd11=0.2*sinc(0.2*t);
hd12=0.5*sinc(0.5*t);
hd1=hd12-hd11;

hd21=0.7*sinc(0.7*t);
hd22=0.9*sinc(0.9*t);
hd2=hd22-hd21;

hd=hd1+hd2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Kaiser window formation

wkai=kaiser(M,B);
w=wkai';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Multiplication of ideal bandpass filter and Kaiser window

h=hd.*w;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Convultion of input signal and finalized filter

y=conv(x,h);
ty=[0:length(y)];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(1);
[X,f]=fouriert(x,n);
plot(f,abs(X));
title('Fourier transform of input signal x[n]');
xlabel('f');
ylabel('X(f)');

figure(2);
[Hd,f]=fouriert(hd,t);
plot(f,abs(Hd));
title('Fourier transform of bandpass filter hd');
xlabel('f');
ylabel('Hd(f)');


figure(3);
[H,f]=fouriert(h,t);
plot(f,abs(H));
title('Fourier transform of Kaiser windowed filter');
xlabel('f');
ylabel('H(f)');

figure(4);
[Y,f]=fouriert(y,ty);
plot(f,abs(Y));
title('Fourier transform of output signal y[n]');
xlabel('f');
ylabel('Y(f)');

figure(5);
[Xz,w]=freqz(x,1,256);
freqzplot(Xz,w); 
title('Plot of frequency response of input x[n]');

figure(6);
[Yz,w]=freqz(y,1,256);
freqzplot(Yz,w); 
title('Plot of frequency response of output y[n]');

