I wish to repeat a sequence a certain amount of time?
Show older comments
%Input signal-------------------------
numBits = input('Enter number of bits: '); %User inputs data
byte = randi([0,1],1,numBits); %Randomizing between 0 and 1
ln = length(byte); %Length of the bit array
de = bi2de(byte,'left-msb'); %Convert Binary to Decimal
%-------------------------------------
%Converting bit 0 to +1
for i=1:ln
if byte(i)== 0 %In the array wherever a '0' appears
byte(i) = -1; %Will change from '0' to '-1'
end %End of 'If' statement
end %End of 'For' loop
%-------------------------------------
%Plotting the Input Signal
subplot (6,1,1);
stairs (byte,'linewidth',2); axis([0 ln -1.25 1.25]);
title ('Input Signal')
grid on
%8-bit Sequence------------------------
k=1;
for i=1:ln
for j=1:8
b(k) = byte(i);
j = j +1;
k = k +1;
end
end
ln1 = length(b);
subplot(6,1,2);
stairs (b,'linewidth',2);axis ([0 ln1 -1.5 1.5]);
title ('8-Bit Sequnce')
grid on
%--------------------------------------------------
This program will generate a random sequence of 1 and -1, however I wish to repeat the 8-bit sequence a certain amount of times. Can anyone help me with the additional code.
Answers (0)
Categories
Find more on Array and Matrix Mathematics 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!