How can I put three different tau_rms in this code and draw them in one picture? (each tau_rms = 5*10^(-9), 30*10^(-9), 80*10^(-9), when SNR_MMSE is same as 30.)

2 views (last 30 days)
No_PKT = 3000; % Number of packets for simulation
NSYM_PKT = 50; % Number of OFDM symbols in a packet for information data
FFT_SIZE = 64; % FFT size
BW = 20 * 10^(6); % System bandwidth, 20MHz, fixed
Ts = 1/BW; % Sampling interval in second unit
GI_LEN = 16; % Guard interval in Ts unit, fixed
subcarrier_spacing = 1/(FFT_SIZE * Ts); % Subcarrier spacing in Hz unit
N_data_subcarrier = 48; % Number of data subcarriers, fixed
N_pilot_subcarrier = 4; % Number of pilot subcarriers, fixed
pilot = [1 1 -1 1]; % pilot symbols
modulation = '16QAM'; % BPSK, QPSK, 16QAM, 64QAM
%===================================== Channel Environments ======================================
Channel_type = 'Rayleigh'; % 'Rayleigh' for Rayleigh channel and 'AWGN' for AWGN channel
Ch_est_mode = 'LS'; % 'Perfect' for perfect channel estimation, 'MMSE', 'LS'
%============================= MMSE filter parameters ==============================
SNR_MMSE = 30; % SNR for MMSE filter in dB
beta = 1; % beta = E[x^2] * E[1/x^2]
tau_rms = 100 * 10^(-9); % rms delay for MMSE filter in second unit
%===================================================================================
SNR = [10: 2: 30]; % SNR or Es/No for simulation
switch Channel_type
case 'AWGN'
No_Path = 1;
PATH_DELAY = 0; % Relative delay in nano second unit
PATH_GAIN = 0; % in dB
case 'Rayleigh'
No_Path = 4; % Number of multi-paths
PATH_DELAY = [0, 50, 200, 350]; % Relative delays in nano second unit
PATH_GAIN = [0, -5.4, -10.3, -17.6]; % Relative gains in dB unit, 33ns
PATH_DELAY = round( PATH_DELAY * 10^(-9) / Ts); % Relative delays in Ts unit
end
switch modulation
case 'BPSK'
Mod_level = 1;
normalize_factor = 1;
case 'QPSK'
Mod_level = 2;
normalize_factor = sqrt(2);
case '16QAM'
Mod_level = 4;
normalize_factor = sqrt(10);
case '64QAM'
Mod_level = 6;
normalize_factor = sqrt(42);
end
% MMSE filter generation based on exponential delay profile models
[MMSE_filter] = MMSE( SNR_MMSE, tau_rms, subcarrier_spacing, beta );
[preamble ifft_input_LTS ] = preamble_gen( FFT_SIZE ); % preamble generation
length_preamble = length(preamble);
for isnr = 1 : length(SNR) % loop for SNR or Es/No
Es = 10 ^ ( SNR(isnr) / 10 ); % symbol energe in linear scale
seed = 1;
randn('seed',seed);
bit_err_total = 0;
for ifn = 1 : No_PKT % loop for packet
data = randn(1, N_data_subcarrier * NSYM_PKT * Mod_level) > 0; % binary data generation for each packet
% symbol mapping and frame formating by modulation level
[ifft_input] = symbol_mapping( data, pilot, FFT_SIZE, N_data_subcarrier, NSYM_PKT, Mod_level, normalize_factor );
% Inverse FFT
[ifft_sig] = inverse_fft( ifft_input, FFT_SIZE, NSYM_PKT );
% Guard insertion and parallel to serial conversion
[tx_sig] = guard_insertion( ifft_sig, FFT_SIZE, NSYM_PKT, GI_LEN );
tx_sig = [ preamble tx_sig ]; %cascading preamble and ofdm signals
% Generating fading signals
[fade] = fading_gen( Channel_type, PATH_GAIN, PATH_DELAY );
% Generating a received signal
[rx_sig, rx_sig_no_noise] = rx_sig_gen( tx_sig, fade, Es, FFT_SIZE, GI_LEN, NSYM_PKT, length_preamble, Ts );
% Guard removal
[guard_removed_sig, guard_removed_sig_no_noise, guard_removed_LTS] = guard_removal( rx_sig, rx_sig_no_noise, FFT_SIZE, NSYM_PKT, GI_LEN );
% FFT at the receiver
[fft_sig, fft_sig_no_noise, fft_LTS] = forward_fft( guard_removed_sig, guard_removed_sig_no_noise, guard_removed_LTS, FFT_SIZE, NSYM_PKT );
% Channel estimation
[est_channel] = channel_est( fft_LTS, ifft_input_LTS, fft_sig_no_noise, ifft_input, Ch_est_mode, MMSE_filter, NSYM_PKT );
% Channel compensation and symbol demapping
[est_data] = symbol_demapping( fft_sig, est_channel, NSYM_PKT, Mod_level, normalize_factor );
% Counting the number of error bits
bit_err = sum(data ~=est_data);
bit_err_total = bit_err_total + bit_err;
if mod(ifn, 10) == 0
Accumulated_BER = bit_err_total / ( N_data_subcarrier * NSYM_PKT * Mod_level * ifn )
end
end
BER(isnr) = bit_err_total / (N_data_subcarrier * NSYM_PKT * Mod_level * No_PKT)
end
semilogy(SNR,BER,'r-o');
xlabel('Es/No (dB)');
ylabel('BER');
axis([10 30 10^(-4) 10^(0)]);
grid on

Answers (1)

Jeffrey Clark
Jeffrey Clark on 1 Nov 2022
Edited: Jeffrey Clark on 1 Nov 2022
@zoopzdd, as in most cases where you want to apply multiple values in code methods invoked that aren't intended to receive multiple values in one call, you need to:
  1. change the variable to a vector of the values; and
  2. find where/how the variable is currently used and decide where/how you can loop over the vector values; and
  3. if this results in generating more outputs than you currently accumulate how will you keep track of the new ones or will a max/min/mean etc be used.
So maybe 1:
tau_rms = [5,30,80] * 10^(-9); % rms delays for MMSE filter in second unit
maybe 2 and 3:
% MMSE filter generation based on exponential delay profile models
[preamble ifft_input_LTS ] = preamble_gen( FFT_SIZE ); % preamble generation
length_preamble = length(preamble);
BER = zeros(length(SNR),length(tau_rms)); % predefine outputs for known lengths
figure % use one for all plots
for itau = 1 : length(tau_rms) % loop over tau
[MMSE_filter] = MMSE( SNR_MMSE, tau_rms(itau), subcarrier_spacing, beta );
for isnr = 1 : length(SNR) % loop for SNR or Es/No
% ...
BER(isnr,itau) = bit_err_total / (N_data_subcarrier * NSYM_PKT * Mod_level * No_PKT);
end
semilogy(SNR,BER(:,itau),'-o'); % use auto color assignment within one plot
hold on
end
% ...

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!