encoding NRZ polar as square wave ?

조회 수: 6 (최근 30일)
Willim
Willim 2019년 4월 1일
편집: KALYAN ACHARJYA 2019년 4월 1일
Hello I have tried to encode my binary information over specific interval in time
fb= 1e3; % the channel date rate
Tb=1/fb; % the bit period or bit interval
fs=16*fb; %Sampling frequency
Ts=1/fs;
a=[0 1 0 1 1 0 1 1 0 0 0 1]
t=0:Ts:Tb*length(a)-Ts;
i=1;
%nrzData
for j = 1:length(t)
if t(j)<=i
y(j)=a(i);
else
y(j)=a(i);
i=i+1;
end
end
I have got all them as -1 , even if I have try a_e=[-1 1 -1 1 1 -1 1 1 -1 -1 -1 1] instead of a.
Could you please help to generate the encoding array ?

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 4월 1일
편집: KALYAN ACHARJYA 2019년 4월 1일
Note: This same can be easily done without using for loop (recomended), but first try to understand the issue, where you did wrong.
have got all them as -1 , even if I have try a_e=[-1 1 -1 1 1 -1 1 1 -1 -1 -1 1] instead of a.
Yes, see you have defined
i=1;
Evertime you just exucating the following only
y(j)=a(i);
%Whaever j value, i value is 1 alwayas so y(j)=a(1) so its gives -1 everywhere
Every irerations you used the same i, as a(1)
for j = 1:length(t)
if t(j)<=i
y(j)=a(i);
else
y(j)=a(i);
i=i+1;
end
end
Always if coldition is true (all elements of t ovectors are less than 1), there is no i increment, as i increment assgnment inside the else condition part.
Wayout: Make the i=i+1 outside the if elase condition
for j = 1:length(t)
if t(j)<=i
.....
else
....
end
i=i+1;
end
Second Probable Error after considering i outside the if else condition:
Index exceeds matrix dimensions.
y(j)=a(i);
In for loop j having length
>> length(j)
ans =
192
When i pass through 192 ierated, it aslo incremented to 192, but as "a" length is 12 only therefore it shows error, when j length more than 12.
as you assigned y value as a(j)
therefore a(1) data avaliable
a(2)...data avaliable
.....
a(12) data avaliable
..after a(13) data not avaliable as you defines as as a_e
a=[-1 1 -1 1 1 -1 1 1 -1 -1 -1 1]
If any isuue let me know here.
Hope it helps!
  댓글 수: 4
Willim
Willim 2019년 4월 1일
Thank you I have generate a different code that works for me
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 4월 1일
편집: KALYAN ACHARJYA 2019년 4월 1일
Welcome !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Antenna and Array Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by