Randi Error- Array exceeds max array size preference

2 visualizaciones (últimos 30 días)
Daynah Rodriguez
Daynah Rodriguez el 16 de Dic. de 2020
Respondida: Jeff Miller el 16 de Dic. de 2020
This is the code that I have, however, I get an error and I dont know if theres's a way to fix this:
% Simulate BER of OOK-NRZ
clear;
clc;
close all
q=1.6e-19;
% Charge of Electron
Ib=202e-6;
% Background Noise Current+interfernce
N0=2*q*Ib;
% Noise Spectral Density, 2*q*Ib
R=1;
% Photodetector responsivity
Rb=1e6;
% Bit rate
Tb=1/Rb;
% bit duration
sig_length=1e5;
% number of bits
nsamp=10;
% samples per symbols
Tsamp=Tb/nsamp;
% sampling time
EbN0=1:12;
% signal-to-noise ratio in dB.
SNR=10.^(EbN0./10);
% signal-to-noise ratio
% ********** Simulation of probability of errors. ************
for i=1:length(SNR)
P_avg(i)=sqrt(N0*Rb*SNR(i)/(2*R^2));
% average transmitted optical power
i_peak(i)=2*R*P_avg(i);
% Peak Electrical amplitude
Ep(i)=i_peak(i)^2*Tb;
% Peak energy (Energy per bit is Ep/2)
sgma(i)=sqrt(N0/2/Tsamp);
% noise variance
%sgma(i)=i_peak(i)/sqrt(2)*sqrt(nsamp/(2*SNR(i)));
pt=ones(1,nsamp)*i_peak(i);
% tranmitter filter
rt=pt;
% receiver filter matched to pt
OOK=randi(1,sig_length);
% random signal generation
Tx_signal=rectpulse(OOK,nsamp)*i_peak(i);
% Pulse shaping function (rectangular pulse)
Rx_signal=R*Tx_signal+sgma(i)*randn(1,length(Tx_signal));
% received signal (y=x+n)
MF_out=conv(Rx_signal,rt)*Tsamp;
% matched filter output
MF_out_downsamp=MF_out(nsamp:nsamp:end);
% sampling at end of bit period
MF_out_downsamp=MF_out_downsamp(1:sig_length);
% truncation
Rx_th=zeros(1,sig_length);
Rx_th(find(MF_out_downsamp>Ep(i)/2))=1;
% thresholding
[nerr ber(i)]=biterr(OOK,Rx_th);
% bit error calculation
end
figure;
semilogy(EbN0,ber,'b');
hold on
semilogy(EbN0,qfunc(sqrt(10.^(EbN0/10))),'r-X','linewidth',2);
% theoretical ber, 'mx-');
grid on
legend('simulation','theory');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for OOK modulation')

Respuesta aceptada

Jeff Miller
Jeff Miller el 16 de Dic. de 2020
This looks wrong:
OOK=randi(1,sig_length);
The first parameter (here, 1) is the maximum random integer (the minimum is 1). Since the max is the same as the min, this randi command will only produce 1's.
The second and third parameters give the size of the array you want. So I suspect you really want something like
myMax = 10; % whatever max you want
OOK = randi(myMax,1,sig_length);

Más respuestas (0)

Categorías

Más información sobre Measurements and Feature Extraction en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by