%Programme to plot the impulse response and frequency response of a 
%raised cosine filter 

%Written by Andrew Bateman.

%set up figure numbers and location on the screen

figure(1)
close
figure(2)
close
h=figure('position',[90 341 394 369],'color',[1,1,0]);
h=figure('position',[491 341 400 370],'color',[1,1,0]);

%initialise vectors
Xaxis1=[];
Xaxis2=[];
H=[];
h=[];



figure(1)

%calculate magnitude of frequency response
for j=1:4
   alpha=(j-0.9999)/3;
for i=1:200
   %var=frequency*bit duration
   var=i/160;
   Xaxis1(i)=var;
   if (var<(1-alpha)/2)
      H(i)=1;
   end
      if(var>(1-alpha)/2) 
         H(i)=0.5*(1+cos((pi/alpha)*(var-(1-alpha)/2)));
      end
      if(var>(1+alpha)/2)
         H(i)=0.0;
      end
   end
   
   plot(Xaxis1,H,'-b','linewidth',2)
   axis([0 1.2 0 1.2]);
   axis('on');

   hold on

end

figure(1)
xaxis1=[0,1.1];
xaxis2=[0,0];
plot(xaxis2,xaxis1,'-k','linewidth',1)
title('frequency response for raised cosine filter')

%calculate impulse response

figure(2)

for j=1:4
   alpha=(j-0.9999)/3;
for i=1:400
   %var=time/bit duration
   var=(i-200+0.1)/50;
   Xaxis2(i)=var;
   h(i)=(sin(pi*var)/(pi*var))*cos(pi*alpha*var)/(1-4*alpha*alpha*var*var);
end

plot(Xaxis2,h,'-b','linewidth',2)
axis([-4 4 -0.4 1.2]);
axis('on');
hold on


end

figure(2)

xaxis1=[-0.2,1.5];
xaxis2=[0,0];
plot(xaxis2,xaxis1,'-k','linewidth',1)
yaxis1=[0,0];
yaxis2=[-3,7];
plot(yaxis2,yaxis1,'-k','linewidth',1)
title('impulse response for raised cosine filter')
