clc
N _ OFDM = 2048% The number of OFDM points is 2048.
f _ delta = 15 E3; % subcarrier spacing is 15k, which is not actually used in the code.
n _ block = 1000; % maximum analog quantity
n _ subcarrier = 1320; Percentage of number of available subcarriers
n _ CP = 144; %CP length
symbol _ number = 14; Percentage of OFDM symbols per transmission
Conv _ Polly =; % convolutional code generating polynomial
k = 5; % convolutional code constraint length
trel=poly2trellis(K,conv _ poly); % generate convolutional code trellis diagram
tail = 0( 1,K- 1); Add% tail bits to zero convolutional code encoder.
mod _ degree = 4; % 16QAM modulation
Code _ rate = 0.5% code rate
Tb _ len = traceback length of 50% Viterbi decoder.
bit _ length = mod _ degree * code _ rate * N _ subcarrier * Symbol _ number-K+ 1; % According to the above parameter configuration, the total number of information bits that can be carried by a data block can be obtained.
SNR _ db = 0: 1: 10; % Set the analog signal-to-noise ratio range.
Signal to noise ratio = 10. ^(snr_db/ 10); % converts the signal-to-noise ratio to a natural value.
Ber = zero (1, length (SNR));); % initialization error rate storage space
Bler = zero (1, length (SNR));); % initialization error rate storage space
h 1=modem.qammod('m',2^mod_degree,'inputtype','bit','symoblorder','gray'); % generates QAM modulation object, the input type is bit input, and the symbol order is gray mapping.
h2=modem.qamdemod(h 1,' OutputType ',' bit ',' DecisionType ',' approximatellr ',...NoiseVariance ', 1); % generates QAM demodulation object, and selects soft decision demodulation form. Because of the noise variance position at this time, it is temporarily set to 1.
For loop_snr= 1: length (snr)
err = 0;
err _ blk = 0;
sigma = sqrt( 1/SNR(loop _ SNR)/2);
For loop_block= 1:N_block%, the code omitted here is the processing procedure of each data frame, which will be described in detail below.
end
ber(loop _ SNR)= err/(bit _ length * loop _ block);
bler(loop _ SNR)= err _ blk/loop _ block;
end
For loop block = 1:N block
source=randsrc( 1,bit_length,[0, 1]); % generated source
code=convenc([source,tail],trel); % convolutional coding, state return to zero
symbol=modulate(h 1,code’); % code sequence is modulated with modulation object h 1
Symbol = symbol/3.1622; Normalization of% subcarrier symbol energy
Transmit _ data = zero (1, symbol _ number * (n _ CP+n _ OFDM)); % send time domain sample initialization
Forloop _ symbol =1:symbol _% OFDM symbol period, and all time-domain samples of an OFDM symbol are generated in each period.
freq_domain=zeros( 1,N _ OFDM); % frequency domain data initialization
freq _ domain((N _ OFDM-N _ subcarrier)/2+ 1:(N _ OFDM-Nsubcarrier)/2+N _ subcarrier)= symbol((loop _ symbol- 1)* N _ subcarrier+ 1:loop _ symbol * N _ subcarrier); % subcarrier mapping, which is mapped on the middle N_subcarrier.
time _ domain = IFFT(freq _ domain)* sqrt(N _ OFDM); %IFFT realizes OFDM modulation and pays attention to energy normalization.
transmit _ data((loop _ symbol- 1)*(N _ CP+N _ OFDM)+ 1:loop _ symbol *(N _ CP+N _ OFDM))=[time _ domain(N _ OFDM-N _ CP+ 1:N _ OFDM),time _ domain]; % plus CP
end
Received _ data = transmit _ data+(randn (1,length (transmit-data))+j * randn (1,length (transmit _ data)))* sigma;; % plus noise to get an acceptable signal.
For cyclic symbol = 1: symbol number
de _ CP = received _ data((loop _ symbol- 1)*(N _ CP+N _ OFDM)+N _ CP+ 1:loop _ symbol *(N _ CP+N _ OFDM)); % delete CP
FFT _ data = FFT(de _ CP)/sqrt(N _ OFDM); %FFT, energy normalization
de mapp _ data((loop _ symbol- 1)* N _ subcarrier+ 1:loop _ symbol * N _ subcarrier)= FFT _ data((N _ OFDM-N _ subcarrier)/2+ 1:(N _ OFDM-N _ subcarrier)/2+N _ subcarrier); % demapping
end
h2。 noise variance = sigma * sigma * 3. 1622 * 3. 1622; % Resets the noise variance parameter of the demodulation object.
Data _ demodulation = demodulation (h2, demapp _ data * 3.1622); % soft demodulation, pay attention to the need to change the signal back to the original constellation according to the requirements of the demodulation object before demodulation.
Temp 1 = size(data _ demodulation);
Data _ demodulation = reshape (data _ demodulated, 1, templ (1) * templ (2)); % Arranges the matrix of soft demodulation input into a row vector.
Decision = vit dex(data _ demodulation, trel, tb_len,' $ term',' unquant'); Viterbi decoding with% dequantization quantization
Decision = Decision (1: length (source)); % truncated position
Err=err+sum (decision ~ = source); % Statistical error number
If(sum(decision~=source)~=0)% counts the number of error blocks.
err _ blk+err _ blk+ 1;
end
if(err _ blk & gt; = 10)% error 10 block stops the simulation under this SNR.
Break;
end
end
semilogy(SNR_dB,ber,'-^')
Grid open
xlabel(' SNR(dB)');
ylable(' BER ');