For loop to repeat the loop with different set of value

조회 수: 10(최근 30일)
salad9996
salad9996 2020년 3월 11일
댓글: salad9996 2020년 4월 7일
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;

답변(1개)

Bob Thompson
Bob Thompson 2020년 3월 11일
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
salad9996
salad9996 2020년 4월 7일
Thanks man, appreciate it

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by