Borrar filtros
Borrar filtros

I have two loops, how can i get rid of the inner loop "for j=1:nSym"?

1 visualización (últimos 30 días)
for i=1:length(EsN0dB),
for j=1:nSym
%
%-----------------Transmitter--------------------
%---Generating a uniformly distributed random numbers in the set
%[0,1,2,..,M-1] i.e from [0 to 15]
info = ceil(M.*rand(1,Ntot))-1; % the reason we subtract '1' is because we want to go from '0' to '15 instead of
% '1' to '16'.
%
% 16QAM constellation maping
x=RefPoint(info+1); % The reason we add 1 to info is because the array must be positive and since we have a '0'in info, we need add '1'.
%
%--- Reference Constellation for demodulation and Error rate computation--
refI = real(RefPoint);
refQ = imag(RefPoint);
%
%--------------Channel Modeling ----------------
%Adding noise with variance according to the required Es/N0
Esym=sum(abs(ofdm_signal).^2)/(length(ofdm_signal)); %Calculate actual symbol energy from generated samples
N0=Esym/(10.^(EsN0dB(i)/10)); %Find the noise spectral density
noiseSigma = sqrt(N0/2); %Standard deviation for AWGN Noise
n = noiseSigma*(randn(1,length(ofdm_signal))+1i*randn(1,length(ofdm_signal))); %Add noise in IQ plane.
%noise=1/sqrt(2)*(randn(1,length(ofdm_signal))+1i*randn(1,length(ofdm_signal)));
%r= sqrt((N+Ncp)/N)*ofdm_signal + n;
r= ofdm_signal + n;
%
%-----------------Receiver----------------------
%Removing cyclic prefix
r_Parallel=r(Ncp+1:(N+Ncp));
%
%FFT Block
r_Time=1/sqrt(N)*(fft(r_Parallel,N));
%Extracting the data carriers from the FFT output
R_Freq=r_Time([(2:Ntot/2+1) (Ntot/2+13:Ntot+12)]);
%
% %-------------I-Q Branching---------------
r_i = real(R_Freq);
r_q = imag(R_Freq);
%
%Detection in the receiver - Euclidean distance Method
[estimatedTxSymbols,dcap]= iqOptDetector(R_Freq,RefPoint);
%
numErrors = sum((info~=dcap-1)); %Count number of errors
%Accumulate bit errors for all symbols transmitted
errors(i)=errors(i)+numErrors;
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Abr. de 2016
The line
Esym=sum(abs(ofdm_signal).^2)/(length(ofdm_signal)); %Calculate actual symbol energy from generated samples
does not depend upon i or j or upon any data that is being changed in the nested loops. Move that line to before both loops.
The line
N0=Esym/(10.^(EsN0dB(i)/10)); %Find the noise spectral density
does not depend upon j, so it can be moved to before the "for j" loop. It could be further vetorized to
all_N0 = Esym/(10.^(EsN0dB/10)); %Find the noise spectral density
and then in the "for i" loop,
N0 = all_N0(i);
However, N0 is only used in
noiseSigma = sqrt(N0/2); %Standard deviation for AWGN Noise
so instead that could be vectorized,
all_noiseSigma = sqrt(all_N0/2);
and then inside the the "for i" loop,
noiseSigma = all_noiseSigma(i);
... and so on. Keep picking at the code and finding places that do not change inside a loop and move those to before the loop. Places where you operate on one element at a time, move to before the loop and operate on as a vector and then (if necessary) index the vector result inside the loop.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by