For loop to repeat the loop with different set of value

6 views (last 30 days)
Hi guys, I'm trying to run the simulation with multiple set of value,
SNRDB=6:2:16;
but what I got one same result for the whole row, I'm guessing it uses the same set of value to run the whole progress. Any suggestion on this??
clc
clear
format long
N=100000;
SNRDB=6:2:16;
I_da=sign(rand(1,11)-0.5);
Q_da=sign(rand(1,11)-0.5);
s=I_da+1i*Q_da;
ber_zf=zeros(1,length(SNRDB));
ber_mmse=zeros(1,length(SNRDB));
ber_n=zeros(1,length(SNRDB));
for i=1:length(SNRDB)
for j=1:N
n=1/sqrt(2*10^(SNRDB(i)/10))*(randn(1,11)+1i*randn(1,11));
h=(1/sqrt(2))*(randn(1,11)+1i*randn(1,11));
y=h.*s+n;
for k=1:3
if k==1
W(1,:) = ones(size(h));
elseif k==2
W(2,:)= 1./h;
elseif k==3
W(3,:)= conj(h)./((abs(h)).^2+n);
else
error('Unimplemented Equalizer');
end
end
z = W .* y;
z_=sign(real(z))+1i*sign(imag(z));
ber_n=ber_n+sum(s~=z_(1,:))/11;
ber_zf=ber_zf+sum(s~=z_(2,:))/11;
ber_mmse=ber_mmse+sum(s~=z_(3,:))/11;
end
end
ber_n=ber_n/N;
ber_zf=ber_zf/N;
ber_mmse=ber_mmse/N;

Answers (1)

Bob Thompson
Bob Thompson on 11 Mar 2020
You are seeing only the final results because you do not have your output variables indexed.
for i=1:length(SNRDB)
for j=1:N
n=1/sqrt(2*10^(SNRDB(i)/10))*(randn(1,11)+1i*randn(1,11)); % Might get an error with 1i
h=(1/sqrt(2))*(randn(1,11)+1i*randn(1,11));
y=h.*s+n;
for k=1:3
if k==1
W(1,:) = ones(size(h));
elseif k==2
W(2,:)= 1./h;
elseif k==3
W(3,:)= conj(h)./((abs(h)).^2+n);
else
error('Unimplemented Equalizer');
end
end
z = W .* y;
z_=sign(real(z))+1i*sign(imag(z));
ber_n(i,:)=ber_n+sum(s~=z_(1,:))/11;
ber_zf(i,:)=ber_zf+sum(s~=z_(2,:))/11;
ber_mmse(i,:)=ber_mmse+sum(s~=z_(3,:))/11;
end
end
  5 Comments

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!