All All: For If
All All: For If
2
0
-2
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
message signal
amplitude
1
0
-1
time in sec
modulated signal
amplitude
2
0
-2
4
time in sec
1
0.5
0
clc;
clear all;
close all;
Tb=1;
N=8;
m=rand(1,N);
t=0:Tb/100:1;
A=2;f=10;
c=A*sin(2*pi*f*t);
subplot(4,1,1);
plot(t,c);
title('carrier signal');
t1=0;
t2=Tb;
for i=1:N;
T=t1:0.01:t2
if m(i)>0.5;
m(i)=1;
msg=ones(1,length(T));
else
m(i)=-1;
msg=-1*ones(1,length(T));
end
d(i,:)=msg;
ask_sig(i,:)=d(i,:).*c
t1=t1+(Tb+0.01);
t2=t2+(Tb+0.01);
subplot(4,1,2);
plot(T,d(i,:));
title('message signal');
xlabel('time in sec');
ylabel('amplitude');
hold on
subplot(4,1,3);
plot(T,ask_sig(i,:));
title('modulated signal');
xlabel('time in sec');
ylabel('amplitude');
hold on
end
hold off;
t1=0;t2=Tb;
for i=1:N;
x=sum(ask_sig(i,:).*c);
%decision
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+0.01);
t2=t2+(Tb+0.01);
end
subplot(4,1,4);
stem(demod);