Matlab program to generate Random bit stream by using standard uniform distribution (rand) function.
Matlab code
clc;clear all;
close all;
n=input(''Enter the no of bit= ');
r=input('Enter the Bite Rate (In bits/sec) = ');
tpb=1/r; % Time duration for per bit
x=rand(1,n); % Standard uniform distribution on the open interval (0,1)
disp('x='); disp(x); % Displays text or array
for i=1:length(x)
if x(i)>=0.5
B(i)=1;
else
B(i)=0;
end;
end;
disp('Random bit stream = ');disp(B);
t1=0; %Temporary variable for time
Time=[]; %Variable for store time
Bitstream=[]; %Variable for store Bit stream
for i=1:length(B)
if B(i)==0 % When bit is 0 --
t=t1:0.001:t1+tpb; % for time duration tpb behaviour of--
Bs=zeros(1,length(t)); % Bit stream.
else
t=t1:0.001:t1+tpb;
Bs=ones(1,length(t));
end;
Time=[Time t]; %storing tpb duration of time
Bitstream=[Bitstream Bs]; %storing Bit stream in tpb duration
t1=t1+tpb; %initial value of next tpb duration for iteration
end;
plot(Time,Bitstream);
axis([0 tpb*n -2 2])
xlabel('Time');
ylabel('Amplitude');
title('Random bit stream');
Command window
Enter the no of bit= 15
Enter the Bite Rate (In bits/sec) = 1
x=
Columns 1 through 9
0.6491 0.7317 0.6477 0.4509 0.5470 0.2963 0.7447 0.1890 0.6868
Columns 10 through 15
0.1835 0.3685 0.6256 0.7802 0.0811 0.9294
Random bit stream =
1 1 1 0 1 0 1 0 1 0 0 1 1 0 1
No comments:
Post a Comment