In: Electrical Engineering
Matlab
Explain the codes below
% Jake.m
% Generate a frequency selective fading
function [r, iout, qout] = Jake(idata, qdata, nsamp, fs, fc, NN, N1_arr, velocity, counter_arr, delay_time, attn, flat)
%****************************** variables *******************************
% idata input Ich data
% qdata input Qch data
% nsamp Number of samples to be simulated
% fs Sampling frequency (Hz)
% fc Carrier Frequency (Hz)
% NN Number of paths
% N1 Number of waves in order to generate fading
% velocity Mobile speed in Km/h
% counter Fading counter
% delay_time Delay for each fading path (ns)
% attn Attenuation level for different fading paths (dB)
% flat flat fading or not
% r Envelope of fading channel complex impulse response
% iout output Ich data
% qout output Qch data
%************************************************************************
v = velocity./3.6; % m/s
c = 3e8;
fm = fc*v/c; % Maximum doppler frequency (Hz)
delay_samp = round(delay_time.*fs.*1e-9); % normalized delay time in number of samples
total_attn = sum(10.^(-1.0.*attn./10.0)); % normalize the power
tstp = 1/fs; % minimum time resolution
iout = zeros(1,nsamp);
qout = zeros(1,nsamp);
r = zeros(1,nsamp);
theta = zeros(1,nsamp);
for i=1:NN
atts = 10.^(-0.05.*attn(i)); % attenuation for current path
[itmp, qtmp] = delay(idata, qdata, nsamp, delay_samp(i));
[r_single, iout_single, qout_single] = fade2(itmp, qtmp, nsamp, tstp, fm, N1_arr(i), counter_arr(i), flat);
counter_arr = counter_arr+200; % update counter
iout = iout + atts.*iout_single./sqrt(total_attn);
qout = qout + atts.*qout_single./sqrt(total_attn);
end
r = sqrt(iout.^2+qout.^2);
I give the explaination in Bold and Italic:
this code genrate gfunction named Jake
the input to the functions are
% idata input Ich data
% qdata input Qch data
% nsamp Number of samples to be simulated
% fs Sampling frequency (Hz)
% fc Carrier Frequency (Hz)
% NN Number of paths
% N1 Number of waves in order to generate fading
% velocity Mobile speed in Km/h
% counter Fading counter
% delay_time Delay for each fading path (ns)
% attn Attenuation level for different fading paths (dB)
% flat flat fading or not
% r Envelope of fading channel complex impulse response
The output of the Functions
% iout output Ich data
% qout output Qch data
function [r, iout, qout] = Jake(idata, qdata, nsamp, fs, fc, NN, N1_arr, velocity, counter_arr, delay_time, attn, flat)
The following steps are used to explain about variables are used inside the function.. it will not execute while run the code
%****************************** variables *******************************
% idata input Ich data
% qdata input Qch data
% nsamp Number of samples to be simulated
% fs Sampling frequency (Hz)
% fc Carrier Frequency (Hz)
% NN Number of paths
% N1 Number of waves in order to generate fading
% velocity Mobile speed in Km/h
% counter Fading counter
% delay_time Delay for each fading path (ns)
% attn Attenuation level for different fading paths (dB)
% flat flat fading or not
% r Envelope of fading channel complex impulse response
% iout output Ich data
% qout output Qch data
%************************************************************************
v = velocity./3.6; % m/s
c = 3e8;%its light speed 3*10^8
fm = fc*v/c; % Maximum doppler frequency (Hz)
delay_samp = round(delay_time.*fs.*1e-9); % normalized delay time in number of samples
total_attn = sum(10.^(-1.0.*attn./10.0)); % normalize the power
tstp = 1/fs; % minimum time resolution
iout = zeros(1,nsamp);%initalize the iout value
qout = zeros(1,nsamp);%initalize the qout value
r = zeros(1,nsamp);%initalize the r value to zero
theta = zeros(1,nsamp);%initalize the theta value to zero
%Create loop to calculate iout and rout value for all samples which is taken
for i=1:NN
atts = 10.^(-0.05.*attn(i)); % attenuation for current path
[itmp, qtmp] = delay(idata, qdata, nsamp, delay_samp(i));
[r_single, iout_single, qout_single] = fade2(itmp, qtmp, nsamp, tstp, fm, N1_arr(i), counter_arr(i), flat);
counter_arr = counter_arr+200; % update counter
iout = iout + atts.*iout_single./sqrt(total_attn);
qout = qout + atts.*qout_single./sqrt(total_attn);
end
r = sqrt(iout.^2+qout.^2);%its formula to find Envelope of fading channel complex impulse response