-
Notifications
You must be signed in to change notification settings - Fork 3
/
Signal_Analyser.m
275 lines (241 loc) · 9.62 KB
/
Signal_Analyser.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
function [state] = Signal_Analyser(state, x, y, z, sg_st, dpd_st, adapt_st, par)
% SIGNAL_ANALYSER(STATE, X, Y, Z, SG_STATE)
global Fs;
if isempty(fieldnames(state))
par = RegisterParam(par, 'num_arch', 1);
par = RegisterParam(par, 'arch_ind', 1);
par = RegisterParam(par, 'sa', struct());
par.sa = RegisterParam(par.sa, 'store_psd', 0);
state.store_psd = par.sa.store_psd;
Narch = par.num_arch;
% initialization
state.iter = 0; % iteration
state.iter_num = par.iter_num;
% initialize variables for NMSE, EVM, ACPR
state.mchpwr = zeros(Narch, state.iter_num, 1);
state.nmse = zeros(Narch, state.iter_num, 1);
state.evm = zeros(Narch, state.iter_num, 1);
state.acpr1 = zeros(Narch, state.iter_num, 1);
state.acpr2 = zeros(Narch, state.iter_num, 1);
% reference values
state.nmse_ref = zeros(state.iter_num, 1);
state.evm_ref = zeros(state.iter_num, 1);
state.acpr1_ref = zeros(state.iter_num, 1);
state.acpr2_ref = zeros(state.iter_num, 1);
% FFT spectra
if state.store_psd
state.psd_spect = zeros(Narch, state.iter_num, length(y));
end
% state.x = zeros(Narch, state.iter_num, length(x));
% state.y = zeros(Narch, state.iter_num, length(y));
% state.z = zeros(Narch, state.iter_num, length(z));
% parameters for ACPR calculation
state.acrp_channels = [1/2+0.1, 3/2+0.1, 3/2+0.2, 5/2+0.2];
if isfield(sg_st, 'type')
if strcmp(sg_st.type, 'OFDM')
state.acpr_osf = sg_st.fft_len / (sg_st.num_rb * sg_st.rb_size);
elseif strcmp(sg_st.type, 'QAM')
state.acpr_osf = sg_st.oversample_fact;
end
else
state.acpr_osf = 6;
end
% -------------------------------------------------------------------------
% initialize figures
% -------------------------------------------------------------------------
if par.is_plot
% Main Channel Power at PA output
state.mchpwr_fn = 1;
state.mchpwr_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.mchpwr_fn);
if ~isempty(state.mchpwr_fh); clf(state.mchpwr_fh); end
figure(state.mchpwr_fn);
hold on;
for i = 1:Narch
state.mchpwr_ph{i} = plot(0,0);
end
hold off;
title('Main channel power at PA output');
xlabel('Iteration cycle');
ylabel('Power (dBW)');
axis([0 state.iter_num, -inf, inf]);
% NMSE
state.nmse_fn = 2;
state.nmse_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.nmse_fn);
if ~isempty(state.nmse_fh); clf(state.nmse_fh); end
figure(state.nmse_fn);
state.nmse_ref_ph = plot(0,0);
hold on;
for i = 1:Narch
state.nmse_ph{i} = plot(0,0);
end
hold off;
title('Normalised mean square exrror');
xlabel('Iteration cycle');
ylabel('NMSE (dB)');
axis([0 state.iter_num, -inf, inf]);
% EVM
state.evm_fn = 3;
state.evm_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.evm_fn);
if ~isempty(state.evm_fh); clf(state.evm_fh); end
figure(state.evm_fn);
state.evm_ref_ph = plot(0,0);
hold on;
for i = 1:Narch
state.evm_ph{i} = plot(0,0);
end
hold off;
title('Error Vector Magnitude');
xlabel('Iteration cycle');
ylabel('EVM (%)');
axis([0 state.iter_num, -inf, inf]);
% ACPR1
state.acpr1_fn = 4;
state.acpr1_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.acpr1_fn);
if ~isempty(state.acpr1_fh); clf(state.acpr1_fh); end
figure(state.acpr1_fn);
state.acpr1_ref_ph = plot(0,0);
hold on;
for i = 1:Narch
state.acpr1_ph{i} = plot(0,0);
end
hold off;
title('Adjacent channel power ratio - 1st adj. channel');
xlabel('Iteration cycle');
ylabel('ACPR1 (dB)');
axis([0 state.iter_num, -inf, inf]);
% ACPR2
state.acpr2_fn = 5;
state.acpr2_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.acpr2_fn);
if ~isempty(state.acpr2_fh); clf(state.acpr2_fh); end
figure(state.acpr2_fn);
state.acpr2_ref_ph = plot(0,0);
hold on;
for i = 1:Narch
state.acpr2_ph{i} = plot(0,0);
end
hold off;
title('Adjacent channel power ratio - 2nd adj. channel');
xlabel('Iteration cycle');
ylabel('ACPR2 (dB)');
axis([0 state.iter_num, -inf, inf]);
% AM/AM characteristics
state.amam_fn = 6;
state.amam_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.amam_fn);
if ~isempty(state.amam_fh); clf(state.amam_fh); end
state.amam_fh = figure(state.amam_fn);
switch Narch
case 1
sp_layout = [1 1];
case 2
sp_layout = [1 2];
case {3, 4}
sp_layout = [2 2];
case {5,6}
sp_layout = [3 2];
otherwise
error('Unsupported number of architectures');
end
for i = 1:Narch
subplot(sp_layout(1), sp_layout(2), i);
state.amam_pa_ph{i} = plot(0,0,'.');
hold on;
state.amam_lin_ph{i} = plot(0,0,'.');
state.amam_dpd_ph{i} = plot(0,0,'.');
hold off;
title('AM/AM characteristics');
xlabel('Input Magnitude (-)');
ylabel('Output Magnitude (-)');
axis([0 1, 0, 1]);
end
% constelation diagram
state.iqdiag_fn = 7;
state.iqdiag_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.iqdiag_fn);
if ~isempty(state.iqdiag_fh); clf(state.iqdiag_fh); end
state.iqdiag_fh = figure(state.iqdiag_fn);
state.iqdiag_tx_ph = plot(0,0,'x');
hold on;
for i = 1:Narch
state.iqdiag_rx_ph{i} = plot(0,0,'o');
end
hold off;
title('IQ Constelation Diagram');
xlabel('I (-)');
ylabel('Q (-)');
axis([-1.2 1.2 -1.2 1.2]);
% frequency spectrum
state.fspect_fn = 8;
state.fspect_fh = findobj(allchild(groot), 'flat', 'type', 'figure', 'number', state.fspect_fn);
if ~isempty(state.fspect_fh); clf(state.fspect_fh); end
state.fspect_fh = figure(state.fspect_fn);
state.fspect_ref_ph = plot(0,0);
hold on;
for i = 1:Narch
state.fspect_ph{i} = plot(0,0);
end
hold off;
title('Power Spectrum Density');
xlabel('Frequency (Hz)');
ylabel('PSD (dBm/Hz)');
else
for i = 1:Narch
state.fspect_ph{i} = 0;
end
end
end
i = par.arch_ind;
% increment iteration only once per architectures
if i == 1
state.iter = state.iter + 1;
end
iter = state.iter;
% state.x(i,iter,:) = x;
% state.y(i,iter,:) = y;
% state.z(i,iter,:) = z;
% calculate main channel power and ACPR
[acpr_mat, mchan_pwr] = ACPR(y, state.acpr_osf, state.acrp_channels, 0);
state.mchpwr(i,iter) = mchan_pwr;
state.acpr1(i,iter) = Avg_dB(acpr_mat(1,:), 2, 10);
state.acpr2(i,iter) = Avg_dB(acpr_mat(2,:), 2, 10);
% calculate NMSE
y_norm = lscov(y, z) * y;
state.nmse(i,iter) = NMSE(z, y_norm);
% calculate EVM
[~, ~, rx_symbs] = Signal_Demodulator(sg_st, y, z);
state.evm(i,iter) = EVM(rx_symbs,sg_st.symbs);
if par.is_plot
% update figures
set(state.mchpwr_ph{i}, 'XData', 1:iter, 'YData', state.mchpwr(i,1:iter));
set(state.nmse_ph{i}, 'XData', 1:iter, 'YData', state.nmse(i,1:iter));
set(state.evm_ph{i}, 'XData', 1:iter, 'YData', 100*state.evm(i,1:iter));
set(state.acpr1_ph{i}, 'XData', 1:iter, 'YData', state.acpr1(i,1:iter));
set(state.acpr2_ph{i}, 'XData', 1:iter, 'YData', state.acpr2(i,1:iter));
% update AM/AM figures
set(state.amam_pa_ph{i}, 'XData', abs(x)/dpd_st.in_scaler, 'YData', abs(y)/adapt_st.out_scaler);
set(state.amam_lin_ph{i}, 'XData', abs(z)/dpd_st.in_scaler, 'YData', abs(y)/adapt_st.out_scaler);
set(state.amam_dpd_ph{i}, 'XData', abs(z)/dpd_st.in_scaler, 'YData', abs(x)/dpd_st.in_scaler);
% update constelation diagram
set(state.iqdiag_rx_ph{i}, 'XData', real(rx_symbs), 'YData', imag(rx_symbs));
if i == 1 % update reference values only once
% find reference values for actual main channel power
% for PA without DPD (consequently with power back-off)
[state.nmse_ref(iter), state.evm_ref(iter), state.acpr1_ref(iter), state.acpr2_ref(iter), psd_ref] = ...
Get_Reference_Values(par.sa_no_dpd, mchan_pwr);
% update reference values
set(state.nmse_ref_ph, 'XData', 1:iter, 'YData', state.nmse_ref(1:iter));
set(state.evm_ref_ph, 'XData', 1:iter, 'YData', 100*state.evm_ref(1:iter));
set(state.acpr1_ref_ph, 'XData', 1:iter, 'YData', state.acpr1_ref(1:iter));
set(state.acpr2_ref_ph, 'XData', 1:iter, 'YData', state.acpr2_ref(1:iter));
% reference spectrum
set(state.fspect_ref_ph, 'XData', fftshift(fftfreq(length(psd_ref), Fs, true)), 'YData', fftshift(psd_ref));
% reference constelation
set(state.iqdiag_tx_ph, 'XData', real(reshape(sg_st.symbs,numel(sg_st.symbs),1)), 'YData', imag(reshape(sg_st.symbs,numel(sg_st.symbs),1)));
end
end
% calculate and store psd if required
if par.is_plot || state.store_psd
% update spectrum
[psd_spect, ~] = PSD(y, state.fspect_ph{i});
if state.store_psd
state.psd(i,iter,:) = psd_spect;
end
end