-
Notifications
You must be signed in to change notification settings - Fork 5
/
vco.m
81 lines (69 loc) · 1.41 KB
/
vco.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
70
71
72
73
74
75
76
77
78
79
80
81
close all;
clear all;
clf;
graphics_toolkit ("gnuplot");
% ---- ---- Simulation Paramters ---- ---- %
Ts = 1e-3;
dt = 1e-6;
fs = 1/dt;
end_t = 1e-3;
t = 0:dt:Ts-dt;
lt = length(t);
fc = 1e3;
delay = 0.0;
phase_rx = 0;
phase_tx = 0;
fc_tx = fc;
fc_rx = fc;
SNR = 100;
% first order pll
alpha = 0.005;
% VCO voltage which controlls the frequency. at v=0 it's exactly at f.
v = 0;
% cosine output
c = 1;
% delayed cosine by one timestep
c_delay = 0;
% sine output
s = 0;
% delayed sine by one timestep
s_delay = 0;
% data from the VCO for debugging purposes
sine = zeros(Ts,1);
cosine =zeros(Ts,1);
vco = zeros(Ts,1);
for step = 1:dt/dt:Ts/dt
% this is part of the PLL
% "voltage" controlled oscillator
f0 = fc_rx/fs + v*alpha;
c_delay = c;
s_delay = s;
c = c_delay * cos(2*pi*f0) - s_delay * sin(2*pi*f0);
s = s_delay * cos(2*pi*f0) + c_delay * sin(2*pi*f0);
% let's save everything in handy vectors for plotting
sine(step) = s;
cosine(step) = c;
vco(step) = v
% end VCO
% save our carriers
% !!! 90 degree phase shift so the sine becomes the inphase
% signal and the cosine the quadrature signal
carrier_inph(step) = c;
carrier_quad(step) = s;
endfor
figure(1);
subplot(3,1,1);
plot(cosine);
ylabel('Amplitude');
title('cosine');
grid on;
subplot(3,1,2);
plot(sine);
ylabel('Amplitude');
title('sine');
grid on;
subplot(3,1,3);
plot(vco);
ylabel('Amplitude');
title('vco');
grid on;