encoding NRZ polar as square wave ?
3 views (last 30 days)
Show older comments
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 ?
0 Comments
Accepted Answer
KALYAN ACHARJYA
on 1 Apr 2019
Edited: KALYAN ACHARJYA
on 1 Apr 2019
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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!