Binary Number Transmitter

14 次查看(过去 30 天)
Will
Will 2011-11-15
I need to create a transmitter that generates 100000 binary bits encoded as +/-3 volts using rand() but it doesn't seem to recognize the if just goes to the else. I know its something dumb any help would be appreciated I have:
x = rand(1,100000)
bit=(x>.5)
if bit==0
bit = bit-3
else x == 1
bit = bit+3
end

采纳的回答

Sven
Sven 2011-11-15
The "if" statement is only executed once, however you have 100000 elements. Essentially, if any elements in a vector are false, the "if" statement will return false. That's why you never enter the "true" portion of the if statement. Here's what I think you were trying:
x = rand(1,100000)
bit = double(x>.5);
bit(bit==0) = -3;
bit(bit==1) = 3;
Or, in a single line statement:
bit = (rand(1,100000)>0.5)*6 - 3;
  2 个评论
Walter Roberson
Walter Roberson 2011-11-15
The single-line statement will work, but the separate statements will not work in the form stated. bit = x>.5 will set bit to be of type logical, and once it is type logical all assignments to part of the vector will saturate to 0 or 1.
This would fix the problem, though:
bit = 0 + (x>.5);
Then bit would be of type double and assigning -3 or +3 to it would not be a problem.
Sven
Sven 2011-11-15
True, Walter. Updated accordingly.

请先登录,再进行评论。

更多回答(1 个)

Will
Will 2011-11-15
Is there a way to calculate bit error rate with this system?
  2 个评论
Sven
Sven 2011-11-15
I'm not quite sure what you mean here, Will.
Your best bet will be to accept an answer to this question and write a new question about bit error rates. I'm afraid the short sentence above is a little unclear to me. Your original question here was well written: clearly written, well described, and you showed the code you were running. If you can do that again with this next question I'm sure you'll get an answer quickly.
Walter Roberson
Walter Roberson 2011-11-15
The bit error rate with this system is 0.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by