Hi
I have to generate a specific type of Pulse position modulation for which i am generating 100 random bits and have to check every two adjacent bits and generate a waveform accordingly.
For example
lets say the generated bits are 11001001
first I need to check the first two bits which are 11 and then the next two bits which are 00 and the following two bits are 10 and the last to bits 01 I have written the following code to check the bits
clear all;
N=10000;
Nbit=100;
t=0:.001:6.4;
% Generate Binary signal
wb=round(rand(1,Nbit));
% wb=wb';
y=size(wb);
i=1:Nbit
j=i+1;
if wb(i) ==0 & wb(j)==0
y(i)=0;
elseif wb(i) ==0 & wb(j)==1
y(i)=1;
elseif wb(i) ==1 & wb(j)==0
y(i)=0;
else
y(i)=0;
end
the output always gives 0.
Would really appreciate if someone could help me with this
Thank you

 채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 9일

0 개 추천

Change the
i=1:Nbit
to
for i=1:Nbit
and add
end
after your the last "end" of your "if" chain.

댓글 수: 1

Mila C
Mila C 2015년 9월 9일
편집: Walter Roberson 2015년 9월 9일
Hi, thank you so much for the help.
I changed the code according to it and modified abit :)
clear all;
N=10000;
Nbit=100;
t=0:.001:6.4;
% Generate Binary signal
wb=round(rand(1,Nbit));
wb=wb';
y=size(wb);
for k=1:Nbit;
i=1:2:Nbit
j=2:2:Nbit;
if wb(i) ==0 & wb(j)==0
y(i)=0;
elseif wb(i) ==0 & wb(j)==1
y(i)=1;
elseif wb(i) ==1 & wb(j)==0
y(i)=0;
else
y(i)=1;
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Software Development에 대해 자세히 알아보기

질문:

2015년 9월 9일

편집:

2015년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by