Adding noise to a Square wave in Matlab

In summary, the individual has a square wave and a random noise signal of different dimensions. They want to add the noise signal to the square wave using their own function, but are unsure of how to make the noise signal a function of the time vector. They are advised to use the length of the square wave to make the noise signal a function of the time vector.
  • #1
frenzal_dude
77
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
 
Physics news on Phys.org
  • #2
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);
 
  • #3
ahh ofcourse, length(x)! I didn't think about that, thanks for your help!
 

1. How can I add noise to a square wave in Matlab?

To add noise to a square wave in Matlab, you can use the awgn function. This function adds white Gaussian noise to the signal, with the option to specify the signal-to-noise ratio (SNR) and the type of noise distribution.

2. What is the syntax for adding noise to a square wave in Matlab?

The syntax for adding noise to a square wave using the awgn function is y = awgn(x, snr, 'measured'), where x is the input signal, snr is the specified signal-to-noise ratio, and 'measured' indicates that the SNR is measured in decibels (dB).

3. Can I add different types of noise to a square wave in Matlab?

Yes, the awgn function allows you to specify the type of noise distribution to add to the signal. You can choose between 'measured', 'db', 'linear', 'power', and 'voltage'.

4. How does adding noise affect a square wave in Matlab?

Adding noise to a square wave can make it appear more realistic, as real-world signals often contain some level of noise. The amount of noise added can also affect the amplitude and frequency of the square wave, making it more or less distorted.

5. Is it possible to remove the noise from a square wave in Matlab?

Yes, you can remove the noise from a square wave in Matlab using the awgn function again, but this time setting the SNR to a high value. You can also use other filtering techniques, such as a low-pass filter, to remove noise from the signal.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Classical Physics
Replies
4
Views
802
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
999
  • General Math
Replies
22
Views
2K
Back
Top