Mathes Mathlab Final 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1 Simulation Paramete rs

2 sampleRate50OkHz = 500e3; % Sample rate of 500K Hz


3 sampleRate20kHz =20e3; % Sample rate of 20K Hz
4 maxDopplerShift = 200; % Maximum Doppler shift of diffuse components (Hz)
5 delay Vector = (0:5:15) *le -6; % Disc rete delays of four-path channel (s)
6 gainVector = [0 -3 -6 -9]; % Average pathgains (dB)
7 KFactor = 10; % Linear ratio of specular power to diffuse power
8 specDopplerShift = 100; % Doppler shift of specular component (Hz)
10 % Rayleigh Channel Configu ration
11 rayleighChannel = comm.RayleighChannel ( . .

12 'SampleRate', sampleRate500kHz,
13 'PathDelays', delayVec to r,
14 'Ave ragePathGains', gainVector,
15 'MaximumDopple rShift', maxDopplerShift,
16 'RandomSt ream 'mt19937ar with seed', ...
17 'Seed',10,
18 'PathGainsOutputPort', true );
19
20 % Ric ian Channel Configu ration
21 ricianChannel = comm.RicianChannel (
22 'SampleRate', sampleRate500kHz ,
23 'PathDelays', delayVec tor,
24 'Ave ragePathGains', gainVector,
25 'KFac to r', KFactor,
26 'DirectPathDopple rShift', specDopplerShift, . . .

27 'Max imumDopple rShift', maxDopplerShift,


28 'RandomSt ream', 'mt19937ar with seed',
29 'Seed', 100,
3 'PathGainsoutputPort', true);
31
32 % QPSK Modulato r Configuration
33 gpskModulator = comm.QPSKModulator(
34 'BitInput', true,
35 'Phase0ffset', pi/4) ;
36
37 % Number of bits transmitted per f rame
38 bitsPe rF rame = 1000;
39
40 % Gene rate Random Message
41 msg = randi([O 1],bitsPerF rame, 1);
42
43 % Modulate data for transmission over Rayleigh channel
44 modSignal = qpskModulator(msg);
45 rayleighChannel (modSignal ) ;
46
47 % Modulate data for transmission over Rician channel
48 ricianChannel (modS ignal);
49
50 % Release channel objects
51 release(rayleighChannel);
52 release (ricianChannel);
53
53
54 % Visualize Rayleigh Channel Responses
55 rayleighChannel. Visualization = 'Impulse and frequency responses';
56 rayleigh Channel.Samples ToD isplay = '100%' ;
57
58 % Display impulse and frequency responses for 2 frames
59 for i = 1:2
60 msg = randi( [01],bitsPerFrame,1);
61 modSignal = qpskModulator(msg);
62 rayleighChannel (modSignal );
63 end
64
65 % Release Rayleigh channel
66 release (rayleighChannel );
67
68% Visual ize Doppler Spectrum
69 rayleighChannel.Visualization = 'Doppler spectrum';
70
71 % Display Doppler spect rum from 5000 frame transmission
72 fori = 1:5000
73 msg = randi( [0 1],bitsPerFrame,1) ;
74 modSignal = qpskModulator(msg) ;
75 rayleighChannel(modSignal);
76 end
77
78 % Release Rayleigh channel
79 release (rayleighChannel) ;
80
81 % Modify Rayleigh channel settings for simplified visualization
82 rayleighChannel.Visualization = 'Impulse and frequency responses';
83 rayleigh Channel.SampleRate = sampleRate20kHz;
84 rayleighChannel. SamplesToDisplay = '25%';
85
86 % Display impulse and frequency responses for 2 frames
87 for i = 1:2
88 msg = randi( [O 1],bitsPerFrame, 1) ;
89 modSignal = qpskModulator (msg);
90 rayleighChannel (modS ignal );
91 end
92
93 % Release Rayle igh channel
94 release ( rayleigh Channel );
95
96 % Configu re Rayleigh channel with a single fading path
97 rayleighChannel.PathDelays = 0;
98 rayleighChannel .AveragePathGains = 0;
99
100 % Display impulse and frequency responses for 2 frames
101 for i = 1:2
102 msg = randi( [0 1],bitsPerF rame, 1);
103 modSignal = qpskModulator (msg);
104 rayleighChannel (modS ignal );
105 end
106
107 % Release Rayleigh channel
108 release (rayleighChannel );
109
110% Turn off System object's visualization
111 rayle igh Channel.Visualization = '0ff':
112 ricianChannel. Visualization = "0ff';
113
1 LTE Configuration
2 enb.NDLRB = 15;
3 enb.CellRe fP = 1;
4 enb.NCellID = 10;
5 enb.CyclicP refix = "No mal' ;
6 enb.DuplexMode = 'FDD';
7
8% Channel and Fading Configu ration
9 SNRdB = 22;
10 SNR = 10^(SNRdB/20);
11 rng('default');
12 cfg.Seed = 1;
13 cfg.NRxAn ts = 1;
14 cfg.DelayP rofile = 'EVA';
15 cfg.DopplerF req = 120;
16 cfg.MIMOCorrelation = 'Low';
17 cfg. InitTime = 0;
18 cfg.NTe ms = 16;
19 cfg.ModelType = 'GMEDS';
20 cfg. InitPhase = 'Random':
21 cfg.No rmalizePathGains = 'On';
22 cfg.No malizeTxAnts = '0n';
23
24 % Channel Estimation and Equalization Configu ration
25 cec.PilotAve rage = 'UserDefined' ;
26 cec.FreqWindow = 9;
27 cec.TimeWindow = 9;
28 cec. InterpType = 'Cubic';
29 cec. Inte rpWinSize = 3;
30 cec. Inte rpWindow = 'Centred';
31
32% Resou rce Grid Setup and Bit Generation
33 grids ize = lteDLResourceGridSize (enb);
34 K = gridsize (1) ;
35 L = gridsize (2);
36 P = gridsize (3);
37 txGrid = [0:
38 numbe rofBits = K*L*p*2;
39 inputBits = randi([O 1], numbe rofBits, 1):;
40 inputSym = lteSymbolModulate(inputBits, 'QPSK');
41
42 % LTE Transmiss ion Loop
43 for sf = 0:10
44 enb.NSubf rame = mod (sf, 10);
45 subframe = lteDLResourceGrid (enb) ;
46 subframe (:) = inputSym;
47 pssSym = ltePSS (enb) ;
48 sSsSym = lteSSS (enb);
49 pss Ind = ltePSS Indices (enb) ;
50 SssInd = lteSSS Indices (enb );
51 subf rame (pss Ind) = pssSym;
52 subframe (sss Ind) = sssSym;
53 cellRsSym = lteCellRS (enb);
54 cellRsInd = lte CellRS Indices (enb) ;
55 subframe (cellRs Ind) = cellRsSym;
56 txGrid= [txGrid subframe ];
57 end
58
59% Transmission and Channel Fading
60 [txWavefo m, info] = lte0FDMModulate (enb, txGrid) ;
61 txGrid = txGrid (: ,1:140);
62 cfg.SamplingRate = info.SamplingRate;
63 rxWavefo m = lteFadingChannel (c fg, txWavefo m) ;
64
65 % Noise Addition and Signal PrOcessing
66 NO = 1/(sqrt (2.0*enb.CellRe fP*double (info.Nfft) )*SNR);
67 noise = NO*complex (randn (size (rxWavefom) ), randn (size (rxWavefo m)));
68 rxWavefom = rxWavefo m + noise;
69 offset = lteDLF rame0ffset (enb, rxWavefo m);
70 rxWavefo m = rxWavefo m (1+0ffset: end, :);
71 rxGrid = lteOFDMDemodulate (enb, rxWavefo m);
72 enb.NSubframe = 0;
73
74 % Channel Estimation, Equalization, and Error Calculation
75 [estChannel , noiseEst] = lteDLChannelEstimate (enb,cec, rxGrid) ;
76 eqGrid = lteEqualizeMMSE (rxGrid, estChannel, noiseEst);
77 egError = txGrid eqGrid;
78 rxError = txGrid - rxGrid;
79
80 % Error Vector Magnitude (EVM) Calculation and Display
81 EVM = comm.EVM;
82 EVM.Ave ragingDimens ions = [1 2];
83 preEqualisedEVM = EVM (txGrid, rxGrid ) ;
84 fprintf ('Percentage RMS EVM of Pre-Equalized signal:%0.3f°;%\n', preEqualisedEVM)
85 postEqualisedEVM = EVM (txGrid, eqGrid) ;
86 fprintf ('Percentage RMS EVM of Post-Equalized signal:%0.3f%% \n', postEqual.isedE\
87
88% Results Visualization
89 hDownlinkEst imationEqualizationResults(rxGrid, eqGrid) ;

You might also like