0

I am following this example code. I want to add a random noise signal with 2 values per bit. How can I solve that?

The Code looks like:

bits =[1,0,1,0,1,0,1,0];
bitrate = 1; % bits per second

figure;
[t,s] = pnrz(bits,bitrate);
plot(t,s,'LineWidth',3);
axis([0 t(end) -1.1 1.1])
grid on;
title(['Polar NRZ: [' num2str(bits) ']']);
T = length(bits)/bitrate; % full time of bit sequence
n = 200;
N = n*length(bits);
dt = T/N;
t = 0:dt:T;
x = zeros(1,length(t)); % output signal
for i = 0:length(bits)-1
    if bits(i+1) == 1
        x(i*n+1:(i+1)*n) = 1;
    else
        x(i*n+1:(i+1)*n) = -1;
    end
end
1
  • The noise, you are adding, to which variable ? Commented Jul 17, 2015 at 10:45

1 Answer 1

0

if I well understood your question, you can use the random function :

random1or0 = randi(2)-1;

So randi will generate a random integer (in uniformly distributed manner) between 1 and 2, then subtracts 1 to get 0 or 1.

You can relate to this question Generate a random number in a certain range in MATLAB for more details about random numbers in matlab.

Sign up to request clarification or add additional context in comments.

4 Comments

yes it's right, but i want to know how to add 2 values per bit as noise signal?
x(i*n+1:(i+1)*n) = (1+ random1or0) % 2; and that's it. a noise is just random 0 or 1 added to the output, but if you want more details you have to read about noise in signals ...
x(i*n+1:(i+1)*n) = (1+ random1or0) % 2; is another solution @Sanap
@Sanap does this answer your question ? can you please explain what you mean by how to add 2 values per bit ? to add to which variable ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.