-
Notifications
You must be signed in to change notification settings - Fork 0
/
OFDMrx12_19_test.m
71 lines (68 loc) · 1.69 KB
/
OFDMrx12_19_test.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
clear;clc
%% OFDM modulator(pair)
fs = 200e3; T = 0.1;
CarrierNum = fs*T;
% SymbolTime = CarrierNum/fs;
ofdmmod = comm.OFDMModulator();
ofdmmod.FFTLength = CarrierNum;
ofdmmod.NumGuardBandCarriers = [0;0];
ofdmmod.InsertDCNull = false;
ofdmmod.NumSymbols = 1;
%% OFDM demodulator coefficient
ofdmdemod = comm.OFDMDemodulator(ofdmmod);
demod_size = info(ofdmdemod);
len = demod_size.InputSize(1);
%% USRP RX setting
sps = 10;
rx = comm.SDRuReceiver();
rx.CenterFrequency = 0;
rx.DecimationFactor = 500/sps;
rx.SamplesPerFrame = len*sps;
rx.EnableBurstMode = true;
rx.NumFramesInBurst = 10;
%% Detect and Buffer
% release(slog);
slog = dsp.SignalSink;
Threshold = 2.7e8;
searching = true; cnt = 0;
while 1
seg = rx();
if sum(abs(double(seg)).^2)<Threshold
if searching
continue;
else
break;
end
else
slog(seg); cnt = cnt + 1;
searching = false;
if cnt>2
break;
end
end
end
rsg = double(slog.Buffer);
plot(real(rsg));
%% simulate receive signal
% sps = 10;
% idle = zeros(985,1);
% tail = zeros(10000,1);
% sig_interp = interp(sig,500);
% sig_dn = downsample(sig_interp,500/sps,8);
% rsg = complex([idle;sig_dn;tail]);
%% timing synchronization
% findhead = 0; h = 1;
for i = 1:2*rx.SamplesPerFrame %rx.SamplesPerFrame
win1 = rsg([0:15]*sps+i);
win2 = rsg([len-16:len-1]*sps+i);
tmp = win1'*win2;
findhead(i) = tmp;
% if tmp>findhead
% findhead = tmp;
% h = i;
% end
end
[~,h] = max(abs(findhead));
msg_t = downsample(rsg(h:h+(len-1)*sps),sps);
msg = ofdmdemod(msg_t);
scatterplot(msg(:,1));grid on