flat top pam matlab code code example
Example: flat top pam matlab code
t=1;
fs=1000;
n=[0:1/fs:t-1/fs];
m=cos(2*pi*fm*n);
duty=20;
s=0.5*square(2*pi*fc*n , duty)+0.5;
period_samp=length(n)/fc;
in=[1:period_samp:length(n)];
on_samp=ceil(period_samp*duty/100);
pam=zeros(1,length(n));
for i=1:length(in)
pam(in(i):in(i)+on_samp)=m(in(i));
end
dt=s.*pam;
filter=fir1(200,fm/fs,'low');
d=conv(filter,dt);
l=length(d);
t1=linspace(0,1,l);
subplot(4,1,1);
plot(n,m,'r');
title('Message Signal');
xlabel('Time');
ylabel('Amplitude ');
subplot(4,1,2);
plot(n,s,'g');
title('Square Signal');
xlabel('Time');
ylabel('Amplitude ');
subplot(4,1,3);
plot(n,pam,'b');
title('PAM Signal');
xlabel('Time');
ylabel('Amplitude ');
subplot(4,1,4);
plot(t1,d,'m');
title('Demodulated Signal');
xlabel('Time');
ylabel('Amplitude ');