-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifief_OFDM_SuccessRate_send.m
More file actions
329 lines (258 loc) · 9.8 KB
/
Modifief_OFDM_SuccessRate_send.m
File metadata and controls
329 lines (258 loc) · 9.8 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
clc
clear all
close all
%% MIMO-OFDM Precoding with Phased Arrays
s = rng(61); % Set RNG state for repeatability
%% System Parameters
% Single-user system with multiple streams
prm.numUsers = 1;
prm.numSTS = 16;
prm.numTx = 32;
prm.numRx = 16;
prm.bitsPerSubCarrier = 4;
prm.numDataSymbols = 10;
prm.fc = 1e9;
prm.chanSRate = 100e6;
prm.ChanType = 'Scattering';
prm.NFig = 50;
% Array locations and angles
prm.posTx = [0;0;0];
prm.mobileRange = 300;
prm.mobileAngle = [33; 0];
prm.steeringAngle = [30; -20];
prm.enSteering = true;
%%
% Parameters to define the OFDM modulation employed for the system are
% specified below.
prm.FFTLength = 256;
prm.CyclicPrefixLength = 64;
prm.numCarriers = 234;
prm.NumGuardBandCarriers = [7 6];
prm.PilotCarrierIndices = [26 54 90 118 140 168 204 232];
nonDataIdx = [(1:prm.NumGuardBandCarriers(1))'; prm.FFTLength/2+1; ...
(prm.FFTLength-prm.NumGuardBandCarriers(2)+1:prm.FFTLength)'; ...
prm.PilotCarrierIndices.';];
prm.CarriersLocations = setdiff((1:prm.FFTLength)',sort(nonDataIdx));
numTx = prm.numTx;
numRx = prm.numRx;
numSTS = prm.numSTS;
prm.numFrmBits = numSTS*prm.numDataSymbols*prm.numCarriers* ...
prm.bitsPerSubCarrier*1/3-6; % Account for termination bits
prm.modMode = 2^prm.bitsPerSubCarrier; % Modulation order
% Account for channel filter delay
prm.numPadZeros = 3*(prm.FFTLength+prm.CyclicPrefixLength);
% Get transmit and receive array information
prm.numSTSVec = numSTS;
[isTxURA,expFactorTx,isRxURA,expFactorRx] = helperArrayInfo(prm,true);
%%
prm.cLight = physconst('LightSpeed');
prm.lambda = prm.cLight/prm.fc;
% Mobile position
[xRx,yRx,zRx] = sph2cart(deg2rad(prm.mobileAngle(1)),...
deg2rad(prm.mobileAngle(2)),prm.mobileRange);
prm.posRx = [xRx;yRx;zRx];
[toRxRange,toRxAng] = rangeangle(prm.posTx,prm.posRx);
spLoss = fspl(toRxRange,prm.lambda);
gainFactor = 1;
% noise_pow=1:2:10;
% for ss=1:1:length(noise_pow)
% snr_db=noise_pow(ss);
noise_pow=10:10:100;
for ss=1:1:length(noise_pow)
prm.NFig=noise_pow(ss);
% Generate the preamble signal
preambleSigSTS = helperGenPreamble(prm);
% repeat over numTx
preambleSig = zeros(size(preambleSigSTS,1),numTx);
for i = 1:numSTS
preambleSig(:,(i-1)*expFactorTx+(1:expFactorTx)) = ...
repmat(preambleSigSTS(:,i),1,expFactorTx);
end
% Transmit preamble over channel
[rxPreSig,chanDelay] = helperApplyChannel(preambleSig,prm,spLoss);
% Front-end amplifier gain and thermal noise
rxPreAmp = phased.ReceiverPreamp( ...
'Gain',gainFactor*spLoss, ... % account for path loss
'NoiseFigure',prm.NFig, ...
'ReferenceTemperature',290, ...
'SampleRate',prm.chanSRate);
rxPreSigAmp = rxPreAmp(rxPreSig);
rxPreSigAmp = rxPreSigAmp * ... % scale power
(sqrt(prm.FFTLength-sum(prm.NumGuardBandCarriers)-1)/(prm.FFTLength));
% OFDM Demodulation
demodulatorOFDM = comm.OFDMDemodulator( ...
'FFTLength',prm.FFTLength, ...
'NumGuardBandCarriers',prm.NumGuardBandCarriers.', ...
'RemoveDCCarrier',true, ...
'PilotOutputPort',true, ...
'PilotCarrierIndices',prm.PilotCarrierIndices.', ...
'CyclicPrefixLength',prm.CyclicPrefixLength, ...
'NumSymbols',numSTS, ... % preamble symbols alone
'NumReceiveAntennas',numRx);
rxOFDM = demodulatorOFDM( ...
rxPreSigAmp(chanDelay+1:end-(prm.numPadZeros-chanDelay),:));
hD = helperMIMOChannelEstimate(rxOFDM(:,1:numSTS,:),prm);
% Calculate the feedback weights
v = diagbfweights(hD);
%%
encoder = comm.ConvolutionalEncoder( ...
'TrellisStructure',poly2trellis(7,[133 171 165]), ...
'TerminationMethod','Terminated');
% Generate mapped symbols from bits
txBits = randi([0, 1],prm.numFrmBits,1);
encodedBits = encoder(txBits);
% Bits to QAM symbol mapping
mappedSym = qammod(encodedBits,prm.modMode,'InputType','Bit', ...
'UnitAveragePower',true);
gridData = reshape(mappedSym,prm.numCarriers,prm.numDataSymbols,numSTS);
preData = complex(zeros(prm.numCarriers,prm.numDataSymbols,numSTS));
for symIdx = 1:prm.numDataSymbols
for carrIdx = 1:prm.numCarriers
Q = squeeze(v(carrIdx,:,:));
normQ = Q * sqrt(numTx)/norm(Q,'fro');
preData(carrIdx,symIdx,:) = ...
squeeze(gridData(carrIdx,symIdx,:)).' * normQ;
end
end
% OFDM modulation of the data
modulatorOFDM = comm.OFDMModulator( ...
'FFTLength',prm.FFTLength,...
'NumGuardBandCarriers',prm.NumGuardBandCarriers.',...
'InsertDCNull',true, ...
'PilotInputPort',true,...
'PilotCarrierIndices',prm.PilotCarrierIndices.',...
'CyclicPrefixLength',prm.CyclicPrefixLength,...
'NumSymbols',prm.numDataSymbols,...
'NumTransmitAntennas',numSTS);
% Multi-antenna
pilots = helperGenPilots(prm.numDataSymbols,numSTS);
txOFDM = modulatorOFDM(preData,pilots);
txOFDM = txOFDM * (prm.FFTLength/ ...
sqrt(prm.FFTLength-sum(prm.NumGuardBandCarriers)-1)); % scale power
preambleSigD = helperGenPreamble(prm,v);
txSigSTS = [preambleSigD;txOFDM];
txSig = zeros(size(txSigSTS,1),numTx);
for i = 1:numSTS
txSig(:,(i-1)*expFactorTx+(1:expFactorTx)) = ...
repmat(txSigSTS(:,i),1,expFactorTx);
end
%%
% Gain per antenna element
amplifier = phased.Transmitter('PeakPower',1/numTx,'Gain',0);
% Amplify to achieve peak transmit power for each element
for n = 1:numTx
txSig(:,n) = amplifier(txSig(:,n));
end
% Transmit antenna array definition
if isTxURA
% Uniform Rectangular array
arrayTx = phased.URA([expFactorTx,numSTS],[0.5 0.5]*prm.lambda, ...
'Element',phased.IsotropicAntennaElement('BackBaffled',true));
else
% Uniform Linear array
arrayTx = phased.ULA(numTx, ...
'ElementSpacing',0.5*prm.lambda, ...
'Element',phased.IsotropicAntennaElement('BackBaffled',true));
end
% For evaluating weights for steering
SteerVecTx = phased.SteeringVector('SensorArray',arrayTx, ...
'PropagationSpeed',prm.cLight);
% Generate weights for steered direction
wT = SteerVecTx(prm.fc,prm.steeringAngle);
% Radiate along the steered direction, without signal combining
radiatorTx = phased.Radiator('Sensor',arrayTx, ...
'WeightsInputPort',true, ...
'PropagationSpeed',prm.cLight, ...
'OperatingFrequency',prm.fc, ...
'CombineRadiatedSignals',false);
if prm.enSteering
txSteerSig = radiatorTx(txSig,repmat(prm.mobileAngle,1,numTx), ...
conj(wT));
else
txSteerSig = txSig;
end
%% AWGN channel applying
rxPreAmp = phased.ReceiverPreamp( ...
'Gain',gainFactor*spLoss, ... % accounts for path loss
'NoiseFigure',prm.NFig, ...
'ReferenceTemperature',290, ...
'SampleRate',prm.chanSRate);
% Front-end amplifier gain and thermal noise
rxSigAmp = rxPreAmp(rxSig);
rxSigAmp = rxSigAmp * ... % scale power
(sqrt(prm.FFTLength - sum(prm.NumGuardBandCarriers)-1)/(prm.FFTLength));
% Receive array
if isRxURA
arrayRx = phased.URA([expFactorRx,numSTS],0.5*prm.lambda, ...
'Element',phased.IsotropicAntennaElement('BackBaffled',true));
else
arrayRx = phased.ULA(numRx, ...
'ElementSpacing',0.5*prm.lambda, ...
'Element',phased.IsotropicAntennaElement);
end
SteerVecRx = phased.SteeringVector('SensorArray',arrayRx, ...
'PropagationSpeed',prm.cLight);
wR = SteerVecRx(prm.fc,toRxAng);
if prm.enSteering
rxSteerSig = rxSigAmp.*(wR');
else
rxSteerSig = rxSigAmp;
end
%%
demodulatorOFDM = comm.OFDMDemodulator( ...
'FFTLength',prm.FFTLength, ...
'NumGuardBandCarriers',prm.NumGuardBandCarriers.', ...
'RemoveDCCarrier',true, ...
'PilotOutputPort',true, ...
'PilotCarrierIndices',prm.PilotCarrierIndices.', ...
'CyclicPrefixLength',prm.CyclicPrefixLength, ...
'NumSymbols',numSTS+prm.numDataSymbols, ... % preamble & data
'NumReceiveAntennas',numRx);
% OFDM Demodulation
rxOFDM = demodulatorOFDM( ...
rxSteerSig(chanDelay+1:end-(prm.numPadZeros-chanDelay),:));
hD = helperMIMOChannelEstimate(rxOFDM(:,1:numSTS,:),prm);
[rxEq,CSI] = helperMIMOEqualize(rxOFDM(:,numSTS+1:end,:),hD);
scFact = ((prm.FFTLength-sum(prm.NumGuardBandCarriers)-1) ...
/prm.FFTLength^2)/numTx;
nVar = noisepow(prm.chanSRate,prm.NFig,290)/scFact;
rxSymbs = rxEq(:)/sqrt(numTx);
rxLLRBits = qamdemod(rxSymbs,prm.modMode,'UnitAveragePower',true, ...
'OutputType','approxllr','NoiseVariance',nVar);
rxLLRtmp = reshape(rxLLRBits,prm.bitsPerSubCarrier,[], ...
prm.numDataSymbols,numSTS);
csitmp = reshape(CSI,1,[],1,numSTS);
rxScaledLLR = rxLLRtmp.*csitmp;
decoder = comm.ViterbiDecoder(...
'InputFormat','Unquantized', ...
'TrellisStructure',poly2trellis(7, [133 171 165]), ...
'TerminationMethod','Terminated', ...
'OutputDataType','double');
rxDecoded = decoder(rxScaledLLR(:));
% Decoded received bits
rxBits = rxDecoded(1:prm.numFrmBits);
%%
constDiag = comm.ConstellationDiagram( ...
'SamplesPerSymbol',1, ...
'ShowReferenceConstellation',true, ...
'ReferenceConstellation', ...
qammod((0:prm.modMode-1)',prm.modMode,'UnitAveragePower',true), ...
'ColorFading',false, ...
'Position',figposition([20 20 35 40]), ...
'Title','Equalized Symbols', ...
'EnableMeasurements',true, ...
'MeasurementInterval',length(rxSymbs));
% Compute and display bit error rate
ber = comm.ErrorRate;
measures = ber(txBits,rxBits);
fprintf('BER = %.5f; No. of Bits = %d; No. of errors = %d\n', ...
measures(1),measures(3),measures(2));
rng(s);
[noerr,suc_rate] = biterr(txBits,rxBits);
success_rateVEC(1,ss)=suc_rate
end
success_rate_v=success_rateVEC/max(success_rateVEC);
command=1;
result=plotfunc(noise_pow/100,success_rate_v,command);
%% plot ===================================================================
result=plotfunc(SNR_vec/length(SNR_vec),success_rate,command);