Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Altin Guberi
Altin Guberi le 3 Déc 2016
Commenté : Altin Guberi le 3 Déc 2016
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 commentaire
Tamir Suliman
Tamir Suliman le 3 Déc 2016
what is the function mypower(x) is not defined correctly ?

Connectez-vous pour commenter.

Réponses (1)

Daniel kiracofe
Daniel kiracofe le 3 Déc 2016
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).

Catégories

En savoir plus sur Communications Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by