Adding noise to a Square wave in Matlab

Click For Summary
SUMMARY

The discussion centers on adding a random noise signal to a square wave in MATLAB. The user initially attempts to combine a square wave generated by the function square(2*pi*10*t) with a random noise signal created using randn(1,10000). The solution provided involves adjusting the dimensions of the noise signal to match the square wave by using randn(1,length(x)), ensuring compatibility for addition. This method effectively allows the user to overlay noise on the square wave.

PREREQUISITES
  • Understanding of MATLAB programming
  • Familiarity with signal generation functions like square and randn
  • Knowledge of vector dimensions and operations in MATLAB
  • Basic concepts of signal processing and noise addition
NEXT STEPS
  • Explore MATLAB's awgn function for adding white Gaussian noise to signals
  • Learn about signal processing techniques for noise reduction
  • Investigate the effects of different noise levels on signal integrity
  • Study MATLAB's plotting functions for visualizing signal modifications
USEFUL FOR

Engineers, researchers, and students involved in signal processing, particularly those working with MATLAB for simulating and analyzing waveforms and noise effects.

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
 
Physics news 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!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K