whats wrong in that program?

14 vues (au cours des 30 derniers jours)
itsik
itsik le 10 Mai 2011
im trying to write a matlab cod that find in random two varabels if its 00 --> 1 01 --> 1+i 10 --> -1 11 --> -1-i and the matrix ipMod gets the value in matched like if : ip= [0,1] then c= 1+i ? tried to make it with " if not equal" but i cant find my mistake thank u so much!! and this is the cod:
clear all
j=sqrt(-1)
nBit=2500
ip1 = rand(1,nBit) >0.5;
ip2=rand(1,nBit) >0.5;
ip=[ip1;ip2]
% QBPSK modulation
% bit00 --> 1
% bit01 --> 1+j
% bit10 -->-1
% bit11 -->-1-j
for q1=1:nBit
q2=1:nBit
if ip1(q1)~=1 & ip2(q2)~=1
ipMod=1
else
if ip1(q1)~=1 & ip2(q2)~=0
ipMod=1+j
else
if ip1(q1)~=0 & ip2(q2)~=1
ipMod=-1
else
if ip1(q1)~=0 & ip2(q2)~=0
ipMod=-1-j
end
end
end
end
end

Réponses (2)

Walter Roberson
Walter Roberson le 10 Mai 2011
You are not using a "for" loop over q2, so q2 is being set to a vector of values. Your "if" statements are then trying to process a vector of true and false conditions. The rule for "if" statements is that a vector (or matrix) of logical values is considered true if and only if all() of the vector (or matrix) is true. For example your statement
if ip1(q1)~=1 & ip2(q2)~=1
is interpreted as
if all(ip1(q1)~=1 & ip2(q2)~=1)
Glancing at your code, I think you want q2=q1
  2 commentaires
Walter Roberson
Walter Roberson le 10 Mai 2011
Also, you keep overwriting ipMod, so with your code only the final loop will have effect. You would want to store in to ipMod(q1).
By the way, the entire encoding loop can be replaced with:
ipMod = 1 - 2 * ip1 - 1i * ip2;
That's all that is needed, no "if" and no looping, just one statement.
itsik
itsik le 11 Mai 2011
thanks!!!!

Connectez-vous pour commenter.


Andrei Bobrov
Andrei Bobrov le 11 Mai 2011
more variant
nBit = 2500;
ipMod = zeros(1,nBit);
ip1 = rand(1,nBit) >0.5;
ip2 = rand(1,nBit) >0.5;
t1 = ip1==1;
t2 = ip2==1;
ipMod(t1 & t2) = -(1+1i);
ipMod(~t1 & t2) = 1+1i;
ipMod(t1 & ~t2) = -1;
ipMod(~t1 & ~t2) = 1;
  1 commentaire
itsik
itsik le 11 Mai 2011
thank u so much!!! u really helped me!!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by