-
Notifications
You must be signed in to change notification settings - Fork 0
/
octave_FSK.m
48 lines (37 loc) · 868 Bytes
/
octave_FSK.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
clc; #... Clear command line
clear all; #... Clear variables
close all; #... Clear figures
bits = [1 0 1 1 0 0 1];
#... Modulation
bitrate = 1;
sampling_rate = 100;
sampling_time = 1/sampling_rate;
end_time = length(bits)/bitrate;
time = 0:sampling_time:end_time;
a = 3; #... Amplitude
signal_one = a*sin(2*pi*4*time);
modulation = a*sin(2*pi*2*time);
index = 1;
for i = 1:length(time)
if bits(index) == 1
modulation(i) = signal_one(i);
endif
if time(i)*bitrate >= index
index = index+1;
endif
endfor
plot(time, modulation);
axis([0 end_time -2*a 2*a]);
grid on;
#... Demodulation
index = 1;
for i = 1:length(modulation)
demodultaion(index) = 1;
if modulation(i) != signal_one(i)
demodultaion(index) = 0;
endif
if time(i)*bitrate >= index
index = index+1;
endif
endfor
disp(demodultaion);