%Programme to plot the impulse response and frequency response of a 
%modified 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:51
   %var=frequency*bit duration
   var=(i-26)/25;
   Xaxis1(i)=var;
   H(i)=abs(2*sin(2*pi*var));
   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-2)))/(pi*(var-2));
end



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



figure(2)
plot(Xaxis2,h,'-b','linewidth',2)
   xlabel('bit periods')
axis([-3 7 -1.1 1.3]);
axis('on');
hold on
xaxis1=[-1.1,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 modified duobinary system')



