%Programme to plot the impulse response and frequency response of a duo-binary 
%baseband signalling system.

%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=[];


%calculate magnitude of frequency response

for i=1:21
   %var=frequency*bit duration
   var=(i-11)/10;
   Xaxis1(i)=var;
   H(i)=2*pi*cos(2*pi*var/2);
   if(var<-0.5) 
      H(i)=0.0;
      end
   if(var>0.5)
      H(i)=0.0;
      end
end

%calculate impulse response

for i=1:100
   %var=time/bit duration
   var=(i-30+0.1)/10;
   Xaxis2(i)=var;
   h(i)=(sin(pi*var))/(pi*var) + (sin(pi*(var-1)))/(pi*(var-1));
end



figure(1)
plot(Xaxis1,H,'-b','linewidth',2)
hold on
xaxis1=[0,8];
xaxis2=[0,0];
plot(xaxis2,xaxis1,'-k','linewidth',1)
title('frequency response for duobinary system')


figure(2)
plot(Xaxis2,h,'-b','linewidth',2)
axis([-3 7 -0.2 1.3]);
axis('on');
hold on
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 duobinary system')
