Help me find out what I'm doing wrong in this project

1 次查看(过去 30 天)
My assignment is to make a monte carlo simulation of a binary code of +/- 3 volts going through Gaussian noise and then to determine the bit error probability and signal to noise ratio and plot them vs each other. However when I run my program and get my plot it looks completely random and there is no noticeable trend or curve. I have my code done and I know it is at least half right because my BEPs were working fine before. If anyone sees what I am doing wrong I would love some input.
close all;clear all;clc;
sigma = 1;
Tb = zeros(1,100000);
Tv = zeros(1,100000);
Rb = zeros(1,100000);
BEP = zeros(1,100);
MSTv = zeros(1,100);
MSN = zeros(1,100);
SNR = zeros(1,100);
SNRdb = zeros(1,100);
n = 1;
while n <= 100
Tr = rand(1,100000);
i = 1;
while i <= 100000
if Tr(1,i) >= 0.5
Tb(1,i) = 1;
else
Tb(1,i) = 0;
end
i = i + 1;
end
Tbbins = [0 1];
Tbcounts = hist(Tb,Tbbins);
j = 1;
while j <= 100000
if Tr(1,j) >= 0.5
Tv(1,j) = 3;
else
Tv(1,j) = -3;
end
j = j + 1;
end
N = sigma * randn(1,100000);
R = Tv + N;
k = 1;
while k <= 100000
if R(1,k) > 0
Rb(1,k) = 1;
else
Rb(1,k) = 0;
end
k = k + 1;
end
errors = 0;
m = 1;
while m <= 100000
if Rb(1,m) ~= Tb(1,m)
errors = errors + 1;
end
m = m + 1;
end
BEP(1,n) = errors / 100000;
MSTv(1,n)= var(Tv) + (mean(Tv)*mean(Tv));
MSN(1,n) = var(N) + (mean(N)*mean(N));
SNR(1,n) = MSTv(1,n)/MSN(1,n);
SNRdb(1,n) = 10 * log10(SNR(1,n));
n = n + 1;
end
figure(1)
semilogy(SNRdb,BEP,'m-<', 'linewidth' ,2.0);
axis tight

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Wireless Communications 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by