-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sync_hao.m
executable file
·147 lines (127 loc) · 4.91 KB
/
test_sync_hao.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
clear all;
close all;
clc;
numFrames = 1;
samplesPerSymbol= 12;
symbolsPerFrame = 16 ;
fSample = 192e6;
fSymbol = 16e6 ;
fs = fSample ;
Ts = 1.0/fs ;
timingOffset = 0;
varDelay = dsp.VariableFractionalDelay;
freqOffset = 5e3;
phaseOffset = 0;
pfo = comm.PhaseFrequencyOffset(...
'FrequencyOffset',freqOffset, ...
'PhaseOffset',phaseOffset, ...
'SampleRate',samplesPerSymbol/Ts);
%EbNo = SNR + 10*log10(samplesPerSymbol);
EbNo = 0 ;
chAWGN = comm.AWGNChannel(...
'NoiseMethod','Signal to noise ratio (Eb/No)', ...
'EbNo',EbNo,...
'SignalPower',1, ...
'SamplesPerSymbol',samplesPerSymbol);
timeSync = comm.MSKTimingSynchronizer(...
'SamplesPerSymbol',samplesPerSymbol, ...
'ErrorUpdateGain',0.02);
phaseSync = comm.CarrierSynchronizer(...
'Modulation','QPSK', ...
'ModulationPhaseOffset','Custom', ...
'CustomPhaseOffset',0, ...
'SamplesPerSymbol',1);
%------------------------------------------------------------------------
% Generate and modulate data
%------------------------------------------------------------------------
%txBits = randi([0 1],symbolsPerFrame,1);
headBits = randi([0 1],1,92);
tailBits = randi([0 1],1,92);
txBits1 = [0 1 0 0 0 1 0 0 1 1 0 0 1 1 0 1] ;
txBits = [headBits txBits1 tailBits] ;
txSym = mskmod(txBits,samplesPerSymbol);
%------------------------------------------------------------------------
% Transmit through channel
%------------------------------------------------------------------------
%
% Add timing offset
rxSigTimingOff = varDelay(txSym,timingOffset*samplesPerSymbol);
%
% Add carrier frequency and phase offset
rxSigCFO = pfo(rxSigTimingOff);
%
scatterplot(txSym(1:samplesPerSymbol:end));
scatterplot(rxSigCFO(1:samplesPerSymbol:end)) ;
% Pass the signal through an AWGN channel
rxSig = chAWGN(rxSigCFO);
%
% Save the transmitted signal for plotting
plot_rx = rxSig;
plot(abs(fft(rxSig.^4,256)));
rx_demod=mskdemod(rxSig,12);
figure;plot(rx_demod(93:93+15)-txBits1);
for i=1:(length(rx_demod)-16)
%%rx_mult(i)=(rx_demod(i:i+15)*txBits1');
%%rx_mult(i)=xcorr(rx_demod(i:i+15),txBits1);
rx_mult(i)=0;
for j=1:16
if (rx_demod(i+j-1)==txBits1(j))
rx_mult(i)=rx_mult(i)+1;
else
rx_mult(i)=rx_mult(i)-1;
end
end
end
figure;plot(rx_mult);
%
% % %------------------------------------------------------------------------
% % % Timing recovery
% % %------------------------------------------------------------------------
% % recoverTimingPhase = 1;
% % if recoverTimingPhase
% % % Recover symbol timing phase using fourth-order nonlinearity
% % % method
% % [rxSym,timEst] = timeSync(rxSig);
% % % Calculate the timing delay estimate for each sample
% % timEst = timEst(1)/samplesPerSymbol;
% % else
% % % Do not apply timing recovery and simply downsample the received
% % % signal
% % rxSym = downsample(rxSig,samplesPerSymbol);
% % timEst = 0;
% % end
% %
% % % Save the timing synchronized received signal for plotting
% % plot_rxTimeSync = rxSym;
% %
% % %------------------------------------------------------------------------
% % % Carrier frequency and phase recovery
% % %------------------------------------------------------------------------
% % recoverCarrier = 1;
% % if recoverCarrier
% % % The following script applies carrier frequency and phase recovery
% % % using a second order phase-locked loop (PLL), and removes phase ambiguity
% % [rxSym,phEst] = phaseSync(rxSym);
% % removePhaseAmbiguityMSKSignalRecoveryEx;
% % freqShiftEst = mean(diff(phEst)/(Ts*2*pi));
% % phEst = mod(mean(phEst),360); % in degrees
% % else
% % freqShiftEst = 0;
% % phEst = 0;
% % end
% %
% % % Save the phase synchronized received signal for plotting
% % plot_rxPhSync = rxSym;
% % %------------------------------------------------------------------------
% % % Demodulate the received symbols
% % %------------------------------------------------------------------------
% % rxBits = mskdemod(rxSym,1);
% % %------------------------------------------------------------------------
% % % Calculate the bit error rate
% % %------------------------------------------------------------------------
% % errorStats = BERCalc(txBits,rxBits);
% % %------------------------------------------------------------------------
% % % Plot results
% % %------------------------------------------------------------------------
% % plotResultsMSKSignalRecoveryEx;
keyboard ;