Can you help me out on making the BER vs SNR plot ?

10 次查看(过去 30 天)
Hello
I am trying to make the plot BER (Bit Error Correction ) versus SNR (Signal To Noise Ratio) via the following code:
clc;clear;close all
N=100;
% Number of Bytes
x(1:2:N)=-3;
x(2:2:N)=3;
% Noise Generation
n=randn(1,N)
r=x+n;
hist(r,100)
% Calculation Of Signal
% Calculation Of Noise
% Calculation of SNR
Px=mypower(x)
Pn=mypower(n)
SNR=10*log10(Px./Pn)
for ii=1:length(SNR)
% noise addition
y = x + 10^(SNR(ii)/20)*n; % additive white gaussian noise
ipHat = real(y)>0;
nErr(ii) = size(find([n- ipHat]),2);
end
BER=nErr/N;
figure (1)
plot(SNR,BER,'r*')
mypower function is: function P=mypower(x)
N=length(x);
P=(1/N)*sum(x.^2);
end
Okay , so If I will execute the code I will get only one star at the graph . Can you please tell me if there is anything anything I can change in order to get the graph with all the possible points/stars ?
Thank you .

回答(1 个)

Daniel kiracofe
Daniel kiracofe 2016-12-3
Not 100% sure of the final answer here, but based on your statement that you are only getting 1 star on the graph, I assume that you are expecting SNR and BER to be arrays. Right now they are just scalars, so that is why you are only getting 1 star. The way you have written it, SNR will have the same size as Px. And px has the size of whatever is returned from mypower(). And mypower returns a scalar, because of the sum() function in there. So if you want SNR to be an array, you have two options, depending on what you are trying to do: 1) modify mypower to return an array instead of a scalar 2) add another loop around the entire code (e.g. for j=1:something), vary some parameter of interest with every iteration of j, and then compute SNR(j) = 10*log10(Px./Pn) on each iteration (hope that makes sense).

类别

Help CenterFile Exchange 中查找有关 Array Geometries and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by