|
| 1 | +# Plotting PSD of several multicarrier waveforms |
| 2 | + |
| 3 | +The purpose is to compre the Power spectral density of several multicarrier waveform. The following module can be used: |
| 4 | + |
| 5 | + module example_PSD_waveform |
| 6 | + # ---------------------------------------------------- |
| 7 | + # --- Modules |
| 8 | + # ---------------------------------------------------- |
| 9 | + using DigitalComm |
| 10 | + # --- External Modules |
| 11 | + using Plots |
| 12 | + gr(); |
| 13 | + using Printf |
| 14 | + using FFTW |
| 15 | + # ---------------------------------------------------- |
| 16 | + # --- Core functions |
| 17 | + # ---------------------------------------------------- |
| 18 | + """ psdWaveform.m |
| 19 | + --- |
| 20 | + Compute the power spectral density (i.e the spectrum here) of the signal parametrized by the waveform structure waveform, for a number of symbol nbSymb. |
| 21 | + The frequency allocation is the one inherited from the waveform structure (i.e waveform.allocatedSubcarriers). |
| 22 | + # --- Syntax |
| 23 | + ( freq,psd ) = psdWaveform(waveform,nbSymb,allocatedSubcarriers); |
| 24 | + # --- Input parameters |
| 25 | + - waveform : Structure associated to transmitted waveform |
| 26 | + - nbSymb : Number of symbol to be transmitted [Int] |
| 27 | + - nbIt : Monte carlo parameter for PSD evaluation (should be > 1) |
| 28 | + # --- Output parameters |
| 29 | + - freq : Vector of frequency evaluation (between -0.5 and 0.5). [Array{Float64,L}] |
| 30 | + - psd : Spectrum evaluated on freq [Array{Complex{Float64}},L] |
| 31 | + # --- Input parameters |
| 32 | + - |
| 33 | + # --- Output parameters |
| 34 | + - |
| 35 | + # --- |
| 36 | + # v 1.0 - Robin Gerzaguet. |
| 37 | + """ |
| 38 | + function psdWaveform(waveform,nbSymb,nbIt) |
| 39 | + # ---------------------------------------------------- |
| 40 | + # --- PSD calculation |
| 41 | + # ---------------------------------------------------- |
| 42 | + # --- Getting frequency allocation |
| 43 | + allocatedSubcarriers = waveform.allocatedSubcarriers; |
| 44 | + # --- Getting number of bits |
| 45 | + # First, frequency size |
| 46 | + nbSubcarriers = length(allocatedSubcarriers); |
| 47 | + # Force a fiven mcs |
| 48 | + mcs = 4; # QPSK. |
| 49 | + # Deduce number of required bits |
| 50 | + nbBits = nbSymb * nbSubcarriers * Int(log2(mcs)); |
| 51 | + # --- Init psd evaluator |
| 52 | + psd = 0; |
| 53 | + # --- Iterative PSD calculation |
| 54 | + for iN = 1 : 1 : nbIt |
| 55 | + # --- Binary sequence |
| 56 | + bitSeq = genBitSequence(nbBits); |
| 57 | + # Mapping |
| 58 | + qamSeq = bitMappingQAM(mcs,bitSeq); |
| 59 | + # --- T/F matrix |
| 60 | + qamMat = reshape(qamSeq,nbSubcarriers,nbSymb); |
| 61 | + # --- Signal |
| 62 | + sigPSD = genSig(qamMat,waveform); |
| 63 | + # --- Mean PSD: |
| 64 | + psd = psd .+ 1/nbIt*1/length(sigPSD)*abs.(fftshift(fft(sigPSD))).^2; |
| 65 | + end |
| 66 | + # --- Calculating sampling frequency |
| 67 | + # Returns Nyquist frequency |
| 68 | + fe = 1; |
| 69 | + Basefe = (0:(length(psd) .-1))./length(psd)*fe .-fe/2; |
| 70 | + return (Basefe,psd); |
| 71 | + end |
| 72 | + # ---------------------------------------------------- |
| 73 | + # --- Main routine |
| 74 | + # ---------------------------------------------------- |
| 75 | + function main() |
| 76 | + # ---------------------------------------------------- |
| 77 | + # --- Overall parameters |
| 78 | + # ---------------------------------------------------- |
| 79 | + # --- Overall PHY parameters |
| 80 | + nbIt = 50; # --- Iteration number |
| 81 | + nbSymb = 14; # --- Number of symbols (one frame) |
| 82 | + nFFT = 1024; # --- Base FFT size |
| 83 | + samplingFreq = 15.36; # --- Frequency value (MHz) |
| 84 | + # --- Frequency allocation |
| 85 | + #allocatedSubcarriers= getLTEAlloc(nFFT); |
| 86 | + #allocatedSubcarriers = (1:12*4); |
| 87 | + # 4 RB alloc. 1 RB space. 4 RB allocated |
| 88 | + allocatedSubcarriers = [1:12*4; 12*5 .+ (1:12*4)]; |
| 89 | + # ---------------------------------------------------- |
| 90 | + # --- Waveform contender |
| 91 | + # ---------------------------------------------------- |
| 92 | + # --- Init OFDM structure |
| 93 | + ofdm = initOFDM( |
| 94 | + nFFT, # --- nFFT : FFT size |
| 95 | + 72, # --- nCP : CP size |
| 96 | + allocatedSubcarriers # --- allocatedSubcarriers : Subcarrier allocation |
| 97 | + ); |
| 98 | + # --- Init SCFDMA structure |
| 99 | + scfdma = initSCFDMA( |
| 100 | + nFFT, # --- nFFT : FFT size |
| 101 | + 72, # --- nCP : CP size |
| 102 | + allocatedSubcarriers, # --- allocatedSubcarriers : Subcarrier allocation |
| 103 | + 12; # --- sizeDFT : DFT preprocessing size |
| 104 | + ); |
| 105 | + # --- Init UF-OFDM structure |
| 106 | + ufofdm = initUFOFDM( |
| 107 | + nFFT, # --- nFFT : FFT size |
| 108 | + 73, # --- L : Filter length (same size +1 due to conv) |
| 109 | + allocatedSubcarriers, # --- allocatedSubcarriers : Subcarrier allocation |
| 110 | + applyPD=1, # --- applyPD : Do predistortion at Tx stage |
| 111 | + attenuation=40, # --- attenuation : Filter attenuation in dB |
| 112 | + ); |
| 113 | + # --- Init BF-OFDM structure |
| 114 | + bfofdm = initBFOFDM( |
| 115 | + 32, # --- nFBMC : PPN size (max number of carriers) |
| 116 | + 64, # --- nOFDM : Precoder size (OFDM sizer) |
| 117 | + 3, # --- K : Overlapping factor |
| 118 | + 9, # --- GI : CP size of precoder |
| 119 | + 0.5, # --- δ : compression factor |
| 120 | + allocatedSubcarriers, # --- allocatedSubcarriers : Subcarrier allocation |
| 121 | + "gaussian", # --- filterName : Pulse shape name |
| 122 | + BT=0.36, # --- BT : Potential BT value for Gaussian |
| 123 | + filterStopBand = 110, # --- filterStopBand : DC stopband value |
| 124 | + fS=[], # --- fS : Potential frequency coefficient for FS filter |
| 125 | + nFFT= 1024, # --- nFFT : associated FFT value in Rx |
| 126 | + nCP= 72, # --- nCP : extended CP size |
| 127 | + ); |
| 128 | + # --- Init WOLA-OFDM structure |
| 129 | + wola = initWOLA( |
| 130 | + nFFT, # --- nFFT : FFT size |
| 131 | + 72, # --- nCP : CP size |
| 132 | + allocatedSubcarriers, # --- allocatedSubcarriers : Subcarrier allocation |
| 133 | + "triangle", # --- Window type @Tx side |
| 134 | + 20, # --- Window size @Tx side |
| 135 | + "triangle", # --- Window type @Rx side |
| 136 | + 20, # --- Window size @Rx side |
| 137 | + ); |
| 138 | + fbmc = initFBMC( |
| 139 | + nFFT, # --- nFFT : FFT size |
| 140 | + 4, # --- K : Overlapping factor |
| 141 | + allocatedSubcarriers # --- allocatedSubcarriers : Subcarrier allocation |
| 142 | + ); |
| 143 | + # ---------------------------------------------------- |
| 144 | + # --- Merging structures |
| 145 | + # ---------------------------------------------------- |
| 146 | + # Create a dictionnary to rule them all |
| 147 | + waveforms = initWaveforms(ofdm, |
| 148 | + scfdma, |
| 149 | + ufofdm, |
| 150 | + bfofdm, |
| 151 | + wola, |
| 152 | + fbmc, |
| 153 | + ); |
| 154 | + # ---------------------------------------------------- |
| 155 | + # --- PSD main calculation |
| 156 | + # ---------------------------------------------------- |
| 157 | + # --- Init plot container |
| 158 | + plt = plot(reuse=false); |
| 159 | + decim = 1; # decimation for light plots |
| 160 | + # --- Iterative PSD generation |
| 161 | + for (name,struc) in waveforms |
| 162 | + # --- Calculate PSD for the configuration |
| 163 | + (fe,psd) = psdWaveform(struc,nbSymb,nbIt); |
| 164 | + # Plot the result |
| 165 | + plot!(plt,fe[1:decim:end].*samplingFreq,10 .* log10.(psd[1:decim:end]/maximum(psd)),label=name,legend=:topleft); |
| 166 | + end |
| 167 | + # --- Update plot and adding labels |
| 168 | + # Purpose is to zoom out on allocated region. |
| 169 | + scsN = (1/1024)*samplingFreq; # Subscarrier spacing (normalized) |
| 170 | + rbV = (12*12); # See several RB for psd fall-off |
| 171 | + ylims!(-120,5); |
| 172 | + xlims!(-rbV*scsN,maximum(allocatedSubcarriers)*scsN+2*12*scsN); |
| 173 | + xlabel!("Frequency [MHz]"); |
| 174 | + ylabel!("Spectrum"); |
| 175 | + display(plt) |
| 176 | + end |
| 177 | + end |
| 178 | + |
| 179 | +By running `example_PSD_waveform.main();` a comparison plot between the different PSD can be obtained |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
0 commit comments