clc; clear; close; t=linspace(0,1,1000); //f=input('enter the message frequency'); f=1; m=0.5+0.5*cos(2*%pi*f*t); subplot(3,1,1); plot(t,m); title('message signal'); c=zeros(1,1000); v=1:100:1000; for i=1:length(v) c(v(i):v(i)+30)=1; end subplot(3,1,2); plot(t,c); title('carrier pulse'); pam=zeros(1,1000); for i=1:length(v) pam(v(i):v(i)+30)=c(v(i))*m(v(i)); end subplot(3,1,3); plot(t,pam); title('pulse amplitude modulation'); figure; subplot(4,1,1); plot(t,m); title('message signal'); c1=0.5+0.5*cos(2*%pi*10*t); subplot(4,1,2); plot(t,c1); title('carrier signal'); pwm=zeros(1,1000); for i=1:1000 if(m(i)>=c1(i)) pwm(i)=1; end end subplot(4,1,3); plot(t,pwm); title('pulse width modulation'); ppm=zeros(1,1000);j=1; for i=2:1000 if(pwm(i-1)==1 & pwm(i)==0) s(j)=i; j=j+1; end end for i=1:length(s) ppm(s(i):s(i)+25)=1; end subplot(4,1,4); plot(t,ppm); title('pulse position modulation');