clc;
clear all;
close all;
SNR=[0:1:14];
snr=10.^(SNR/10);
BER1=zeros(length(SNR),1);
BER2=BER1;
BER3=BER1;
Nmax=1000;
Nerr=100;
for k=1:length(SNR)
for l=1:Nmax
Ns=100;
data=2*round(rand(Ns,1))-1;
if l==1 && k==1
plot(data);title('data');axis([0 Ns -1.1 1.1]);
pause
end
bpsk=data;
n=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
if l==1 && k==1
var_n=norm(n)^2;
end
bpsk=sqrt(snr(k))*data+n;
if l==1 && k==1
plot([real(bpsk) data]);
legend('real part of signal','data');
title('BPSK signal in noise');
pause
end
taps=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
bpsk_r=sqrt(snr(k))*abs(taps).*data+n;
if l==1 && k==1
plot([real(bpsk_r) data])
legend('real part of signal','data');
title('BPSK signal in noise & fading channel');
pause
end
if l==1 && k==1
plot(abs([bpsk bpsk_r]))
legend('AWGN','RAYLEIGH');
title('BPSK in AWGN & Rayleigh fading channel');
pause
end
r1=real(bpsk);
r2=real(bpsk_r);
if l==1 && k==1
plot([r1 r2])
legend('AWGN','Rayleigh');
title('demodulated symbols');
pause;
end
d1=find(r1>=0);d2=find(r1<0);
r1(d1)=1;r1(d2)=-1;
d1=find(r2>=0);d2=find(r2<0);
r2(d1)=1;r2(d2)=-1;
if l==1 && k==1
plot([r1 r2])
legend('AWGN','Rayleigh');
axis([0 Ns -1.1 1.1]);
title('demodulated symbols after hard decisions');
pause;
end
Ber1=length(find((data-r1)~=0));
Ber2=length(find((data-r2)~=0));
if k==1 && l==1
errors=[Ber1 Ber2];
end
BER1(k)=BER1(k)+Ber1;
BER2(k)=BER2(k)+Ber2;
if BER1(k)>Nerr && BER2(k)>Nerr
break
end
end
BER1(k)=BER1(k)/Ns/l;
BER2(k)=BER2(k)/Ns/l;
end
BER=[SNR BER1(k) BER2(k)];
The_awgn=.5*erfc(sqrt(2*snr)/sqrt(2));
The_rayl=.5*(1-sqrt(snr./(1+snr)));
semilogy(SNR,[The_awgn The_rayl BER1(k) BER2(k)]);
xlabel('SNR [dB]');
ylabel('BER');
axis([0 SNR(length(SNR)) 1e-4 .5]);
grid on;
legend('Theor AWGN','Theor Rayl.','AWGN','Rayl.');

댓글 수: 2

Supratik Das
Supratik Das 2019년 6월 14일
at the end their is an error in using semilogy
"Vectors must be of same length"
Supratik Das
Supratik Das 2019년 6월 14일
please help......

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

 채택된 답변

Star Strider
Star Strider 2019년 6월 14일

1 개 추천

Try this instead:
semilogy(SNR,[The_awgn; The_rayl; BER1'; BER2']);

댓글 수: 4

Supratik Das
Supratik Das 2019년 6월 14일
Thank you....
could you please explain what changes you have performed it will be helpfull for me....
Star Strider
Star Strider 2019년 6월 14일
As always, my pleasure.
Sure.
You were trying to plot a matrix of two row vectors and two scalars as a function of a row vector. My changes created your dependent variables as a (4x15) matrix by changing them all to row vectors (eliminating the subscripts of the last two and transposing them) and then concatenating them.
Supratik Das
Supratik Das 2019년 6월 14일
Thank you for your explanation...it helped me a lot
Star Strider
Star Strider 2019년 6월 14일
As always, my pleasure.

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

추가 답변 (0개)

질문:

2019년 6월 14일

댓글:

2019년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by