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 ?

 Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Avr 2019
Modifié(e) : KALYAN ACHARJYA le 1 Avr 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 commentaires

Index exceeds matrix dimensions.
Error in Untitled15 (line 12)
y(j)=a(i);
KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Avr 2019
Modifié(e) : KALYAN ACHARJYA le 1 Avr 2019
Yes you definitely get the error, because length of j is 192 and length of data (a) have 12 only
>> length(j)
ans =
192
To avoid this error in same loop, the length of j and length of data (a) must have same. Chose the length of t is such a way that it doesnt have more than a (For logic you have to check).
t=0:Ts:Tb*length(a)-Ts;
Please note that length of j is same as length of t.
Willim
Willim le 1 Avr 2019
Thank you I have generate a different code that works for me
KALYAN ACHARJYA
KALYAN ACHARJYA le 1 Avr 2019
Modifié(e) : KALYAN ACHARJYA le 1 Avr 2019
Welcome !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Mobile dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by