Adding noise to a Square wave in Matlab

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 10K views
frenzal_dude
Messages
76
Reaction score
0
Hi, I've got a square wave: x = square(2*pi*10*t);
with time vector: t=0:0.001:2;

I've also got a random noise signal: r=randn(1,10000);

I want to add the noise signal to the square wave, but I can't add them because they aren't of the same dimensions. I know I can use awgn(x,snr) but I want to use my r function instead if it's possible.

How can I make the noise signal a function of the time vector?


Thanks in advance.
David
 
on Phys.org
Any reason why you don't just use this:

t=0:0.001:2;
x = square(2*pi*10*t);
r=randn(1,length(x));

plot(t,x.+r);
 
ahh ofcourse, length(x)! I didn't think about that, thanks for your help!