-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.m
69 lines (57 loc) · 1.55 KB
/
mod.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
clc;
clear all;
close all;
% Generate the carrier signal
Tb=1;
fc=10; % Set the carrier frequency fc to 10 Hz
t=0:Tb/100:1;
c=sqrt(2/Tb)*sin(2*pi*fc*t); % Equation for the carrier signal as a function of time
% Generate the message signal
N=8; % Set the number of data elements N
m=rand(1,N);
t1=0;
t2=Tb;
for i=1:N % To obtain each data element , generate a random number m in [0,1]
t=[t1:.01:t2] % If m > 0.5 assign value of m=1
if m(i)>0.5 % Else assign m=0
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=zeros(1,length(t));
end
message(i,:)=m_s;
% Product of carrier and message
ask_sig(i,:)=c.*m_s; % The modulated signal is the product of the message signal level (dc level) and the carrier signal level (analog level)
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
% Plotting the message signal
subplot(5,1,2);
axis([0 N -2 2]);
plot(t,message(i,:),'r');
title('message signal');
xlabel('t');
ylabel('m(t)');
grid on
hold on
% Plotting the BASK signal (modulated signal)
subplot(5,1,4);
plot(t,ask_sig(i,:));
title('BASK signal');xlabel('t--->');ylabel('s(t)');grid on
hold on
end
hold off
% Plotting the carrier signal
subplot(5,1,3);
plot(t,c);
title('carrier signal');
xlabel('t');
ylabel('c(t)');
grid on
% Plotting the input binary data
subplot(5,1,1);
stem(m);
title('binary data bits');
xlabel('n');
ylabel('b(n)');
grid on