How to write a program for Pseudo Random Binary sequence in matlab?

28 views (last 30 days)
i need a program on PRBS

Accepted Answer

Walter Roberson
Walter Roberson on 12 Jul 2016
PRBS = @(N) randi([0 1], 1, N);
This takes one parameter, which is the number of values to generate, and returns a PRBS of that length.

More Answers (1)

anu chauhan
anu chauhan on 15 Jul 2016
Edited: Walter Roberson on 15 Jul 2016
I am doing my research on OFDM in LONG HAUL COMMUNICATION and made a program but when i am varying its values i am not able to obtain the results can you help me regarding improvising the new values i am attaching the program
clear all;
clc;
clf;
cputime;
tic;
%--------------------------USER INPUTS-----------------------
total_length=40; % ENTER IN KM
numberbits=4; % ENTER (if changing this change nobits)
nobit = [1 0 1 1]; % ENTER (consider numberbits)
%------------------------------------------------------------
%-----------------------SMF Characteristics------------------
gamma=0.31; %Non-linear coefficient of SMF
alpha=0.2;%Attenuation of SMF (db/km)
beta2=-16e-24; %2nd order GVD of SMF(ps^2/km)
%------------------------------------------------------------
i=sqrt(-1);
Po=0.517; %Input Power
Ao=sqrt(Po); %Amplitude
PPo=0.00012;
AAo=sqrt(PPo);
n=8192;
to=10e-12; %Initial Pulse Width in second (10ps)
dt=10e-15; %Ten femto-seconds, difference between 2 consecutive samples
pi=3.1415926535;
Ld=(to^2)/(abs(beta2)); %Dispersion length
Ln=1/(gamma*Po); %Nonlinear length
N=Ld/Ln;
h=0.1; %in km
tp=n*dt;
tt=tp/2;
step_size=2*h;
L=total_length/step_size;
%--------------Defining tau2 for the numberbits--------------
new=n*numberbits;
tp1=dt*new;
tt1=tp1/2;
for j=1:1:new
t1(j)=-tt1+((j-1)*((2*tt1)/new));
tau2(j)=t1(j)/to;
end;
%------------------------------------------------------------
%-----------------------Gaussian wave------------------------
for j=1:1:n
t(j)=-tt+((j-1)*((2*tt)/n));
tau(j)=t(j)/to;
f(j)=Ao*exp(-tau(j).^2);
end;
%------------------------------------------------------------
%------------------------Zerowave----------------------------
for j=1:1:n
t(j)=-tt+((j-1)*((2*tt)/n));
tau(j)=t(j)/to;
zerowave(j)=AAo*exp(-tau(j).^2);
end;
%------------------------------------------------------------
%-----------------------calculating w -----------------------
wp=1/(2*tt);
for j=1:1:n
if j<(n/2)
w(j)=2*pi*wp*(j-1);
else
w(j)=2*pi*wp*(j-(n+1));
end;
end;
%------------------------------------------------------------
q8=f;
qq8=zerowave;
%-----------------------------SMF----------------------------
%for 1
zz=1;
for k=1:1:L;
q1=fft(q8);
q2=q1.*exp(((-alpha/2)+i*(beta2/2)*(w.^2))*(h/2));
q3=ifft(q2);
q4=q3.*exp(i*gamma*(abs(q3).^2)*h);
q5=fft(q4);
q6=q5.*exp(((-alpha/2)+i*(beta2/2)*(w.^2))*(h/2));
q7=ifft(q6);
q8=q7;
figure(1), plot (tau, f, tau, q8);
xlabel('Time (tau)');
ylabel('Amplitude');
hleg1 = legend('Input Gaussian Wave','SMF O/P');
grid on;
q8dummy(zz,:)=abs(q8);
zz=zz+1;
k;
end;
zz=zz-1;
figure(2), mesh(q8dummy(1:1:zz,:));
xlabel('Time');
ylabel('Distance*200(m)');
zlabel('Amplitude');
%for 0
zz=1;
for k=1:1:L;
qq1=fft(qq8);
qq2=qq1.*exp(((-alpha/2)+i*(beta2/2)*(w.^2))*(h/2));
qq3=ifft(qq2);
qq4=qq3.*exp(i*gamma*(abs(qq3).^2)*h);
qq5=fft(qq4);
qq6=qq5.*exp(((-alpha/2)+i*(beta2/2)*(w.^2))*(h/2));
qq7=ifft(qq6);
qq8=qq7;
zerowavedummy(zz,:)=abs(qq8);
zz=zz+1;
k;
end;
zz=zz-1;
%--------------------Concatenating the bits------------------
x=[];
x1=[];
x3=[];
for p=1:1:numberbits
if nobit(p)==1
x=[x f]; %initial input
x1=[x1 q8]; %after EDFA (Final)
x3=[x3 q8dummy];
else
x=[x zerowave];
x1=[x1 qq8];
x3=[x3 zerowavedummy];
end;
p;
end;
%------------------------------------------------------------
figure(3), plot (tau2, x, tau2, x1);
xlabel('Time (tau)');
ylabel('Amplitude');
hleg1 = legend('Input Bit Sequence','SMF O/P');
grid on;
figure(4), mesh(x3(1:1:zz,:));
xlabel('Time');
ylabel('Distance*200(m)');
zlabel('Amplitude');
%------------------------------------------------------------
toc;
cputime=toc;
disp('CPU time:'), disp(cputime);
  1 Comment
Walter Roberson
Walter Roberson on 15 Jul 2016
When you are varying which values, you are not able to obtain what results?
I do not see any use of PRBS in this code, so it would appear to be a completely new Question rather than a follow-on question.

Sign in to comment.

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!