■ ■ ■ ■ ■ ■
unit08_bf/labPartial/FDMIMOChan.m
| 1 | + | classdef FDMIMOChan < matlab.System |
| 2 | + | % Frequency-domain MIMO multipath channel |
| 3 | + | properties |
| 4 | + | % Configuration |
| 5 | + | carrierConfig; % Carrier configuration |
| 6 | + | waveformConfig; % Waveform parameters |
| 7 | + | |
| 8 | + | % Path parameters |
| 9 | + | gain; % Relative path gain in dB |
| 10 | + | dly; % Delay of each path in seconds |
| 11 | + | aodAz, aodEl; % Angle of departure of each path in degrees |
| 12 | + | aoaAz, aoaEl; % Angle of arrival of each path in degrees |
| 13 | + | |
| 14 | + | % Derived path parameters |
| 15 | + | fd; % Doppler shift for each path |
| 16 | + | gainComplex; % Complex gain of each path |
| 17 | + | svTx, svRx; % Steering vectors for each path |
| 18 | + | elemGainTx, elemGainRx; % Element gains |
| 19 | + | |
| 20 | + | % Other parmaters |
| 21 | + | fc = 28e9; % Carrier freq in Hz |
| 22 | + | rxVel = [30,0,0]'; % RX velocity vector in m/s |
| 23 | + | txVel = [0,0,0]'; % TX velocity vector in m/s |
| 24 | + | Enoise = 0; % Noise energy per sample in dBmJ |
| 25 | + | |
| 26 | + | % Symbol times |
| 27 | + | symStart; % symStart(i) = start of symbol i relative to subframe |
| 28 | + | |
| 29 | + | % TX and RX array platforms |
| 30 | + | txArrPlatform = []; |
| 31 | + | rxArrPlatform = []; |
| 32 | + | |
| 33 | + | end |
| 34 | + | methods |
| 35 | + | function obj = FDMIMOChan(carrierConfig, varargin) |
| 36 | + | % Constructor |
| 37 | + | |
| 38 | + | % Save the carrier configuration |
| 39 | + | obj.carrierConfig = carrierConfig; |
| 40 | + | |
| 41 | + | % Set parameters from constructor arguments |
| 42 | + | if nargin >= 1 |
| 43 | + | obj.set(varargin{:}); |
| 44 | + | end |
| 45 | + | |
| 46 | + | % Check all the required fields are specified |
| 47 | + | fields = {'txArrPlatform', 'rxArrPlatform', 'gain', 'dly', ... |
| 48 | + | 'aoaAz', 'aodAz', 'aoaEl', 'aoaAz' }; |
| 49 | + | nfields = length(fields); |
| 50 | + | for i = 1:nfields |
| 51 | + | fstr = fields{i}; |
| 52 | + | if isempty(obj.(fstr)) |
| 53 | + | e = MException('FDMIMOChan:missingParam', ... |
| 54 | + | 'Parameter %s not speficied', fstr); |
| 55 | + | throw(e); |
| 56 | + | end |
| 57 | + | end |
| 58 | + | |
| 59 | + | % Complex gain for each path using a random initial phase |
| 60 | + | % The gains are normalized to an average of one |
| 61 | + | npath = length(obj.gain); |
| 62 | + | phase = 2*pi*rand(npath, 1); |
| 63 | + | obj.gainComplex = db2mag(obj.gain).*exp(1i*phase); |
| 64 | + | |
| 65 | + | % Symbol times relative to the start of the subframe |
| 66 | + | obj.waveformConfig = nrOFDMInfo(obj.carrierConfig); |
| 67 | + | nsym = obj.waveformConfig.SymbolLengths; |
| 68 | + | obj.symStart = nsym/obj.waveformConfig.SampleRate; |
| 69 | + | obj.symStart = cumsum([0 obj.symStart]'); |
| 70 | + | |
| 71 | + | % Get Doppler shift for RX |
| 72 | + | vc = physconst('Lightspeed'); |
| 73 | + | [ux, uy, uz] = sph2cart(deg2rad(obj.aoaAz), deg2rad(obj.aoaEl), 1); |
| 74 | + | obj.fd = [ux uy uz]*obj.rxVel*obj.fc/vc; |
| 75 | + | |
| 76 | + | % Get Doppler shift for TX |
| 77 | + | [ux, uy, uz] = sph2cart(deg2rad(obj.aodAz), deg2rad(obj.aodEl), 1); |
| 78 | + | obj.fd = obj.fd + [ux uy uz]*obj.txVel*obj.fc/vc; |
| 79 | + | end |
| 80 | + | |
| 81 | + | function computePathSV(obj) |
| 82 | + | % Computes the element gains and steering vectors of each path |
| 83 | + | |
| 84 | + | % Call the array platform objects to get the steering vectors |
| 85 | + | % and element gains |
| 86 | + | [obj.svTx, obj.elemGainTx] = ... |
| 87 | + | obj.txArrPlatform.step(obj.aodAz, obj.aodEl); |
| 88 | + | [obj.svRx, obj.elemGainRx] = ... |
| 89 | + | obj.rxArrPlatform.step(obj.aoaAz, obj.aoaEl); |
| 90 | + | |
| 91 | + | end |
| 92 | + | |
| 93 | + | |
| 94 | + | end |
| 95 | + | methods (Access = protected) |
| 96 | + | |
| 97 | + | |
| 98 | + | function [chanGrid, noiseVar] = stepImpl(obj, frameNum, slotNum) |
| 99 | + | % Applies a frequency domain channel and noise |
| 100 | + | % |
| 101 | + | % Parameters |
| 102 | + | % ---------- |
| 103 | + | % frameNum: The index of the frame (1 frame = 10ms) |
| 104 | + | % slotNum: The index of the slot in the frame |
| 105 | + | % This should be 0,...,waveformConfig.SlotsPerFrame |
| 106 | + | % |
| 107 | + | % Outputs |
| 108 | + | % ------- |
| 109 | + | % chanGrid: Grid of the channel values |
| 110 | + | % noiseVar: Noise variance |
| 111 | + | |
| 112 | + | % Compute the steering vectors and element gains |
| 113 | + | obj.computePathSV(); |
| 114 | + | |
| 115 | + | % Get the number of TX and RX elements |
| 116 | + | ntx = obj.txArrPlatform.getNumElements(); |
| 117 | + | nrx = obj.rxArrPlatform.getNumElements(); |
| 118 | + | |
| 119 | + | % Get the number of sub-carriers |
| 120 | + | nscPerRB = 12; |
| 121 | + | nsc = obj.carrierConfig.NSizeGrid * nscPerRB; |
| 122 | + | nsym = obj.carrierConfig.SymbolsPerSlot; |
| 123 | + | |
| 124 | + | % Compute the frequency of each carrier |
| 125 | + | f = (0:nsc-1)'*obj.carrierConfig.SubcarrierSpacing*1e3; |
| 126 | + | |
| 127 | + | % Compute slot in sub-frame and sub-frame index |
| 128 | + | sfNum = floor(slotNum / obj.waveformConfig.SlotsPerSubframe); |
| 129 | + | slotNum1 = mod(slotNum, obj.waveformConfig.SlotsPerSubframe); |
| 130 | + | |
| 131 | + | % Compute the time for each symbol |
| 132 | + | framePeriod = 0.01; |
| 133 | + | sfPeriod = 1e-3; |
| 134 | + | t = frameNum*framePeriod + sfPeriod*sfNum + ... |
| 135 | + | obj.symStart(slotNum1+1:slotNum1+nsym); |
| 136 | + | |
| 137 | + | % Initialize the channel grid to zero |
| 138 | + | chanGrid = zeros(nrx, ntx, nsc, nsym); |
| 139 | + | npath = length(obj.gain); |
| 140 | + | |
| 141 | + | |
| 142 | + | % TODO: Set the channel: |
| 143 | + | % |
| 144 | + | % chanGrid(j,k,n,t) = MIMO channel matrix from |
| 145 | + | % RX antenna j, TX antenna k, sub-carrier n, |
| 146 | + | % symbol t. |
| 147 | + | % |
| 148 | + | % This should be a sum of the paths |
| 149 | + | % |
| 150 | + | % chanGrid(j,k,:,:) |
| 151 | + | % = \sum_i exp(1i*phase)*svRx(j,i)*svTx(k,i) |
| 152 | + | % |
| 153 | + | % where |
| 154 | + | % |
| 155 | + | % phase = 2*pi*(f*obj.dly(i) + t'*obj.fd(i)); |
| 156 | + | |
| 157 | + | |
| 158 | + | % Compute noise variance |
| 159 | + | noiseVar = db2pow(obj.Enoise); |
| 160 | + | |
| 161 | + | |
| 162 | + | end |
| 163 | + | |
| 164 | + | end |
| 165 | + | end |
| 166 | + | |
| 167 | + | |