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

조회 수: 1 (최근 30일)
Cameron
Cameron 2014년 4월 15일
댓글: Walter Roberson 2014년 4월 15일
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
  댓글 수: 2
Image Analyst
Image Analyst 2014년 4월 15일
Look at this to format your code properly: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup Or else just attach your m-file with the paper clip icon.
Walter Roberson
Walter Roberson 2014년 4월 15일
Have you considered, e.g.,
Tb = Tr >= 0.5;
instead of looping?

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

답변 (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