Can someone please help with creating a program, that will plot two sinusoidal waveforms (amplitude vs. time) on the same graph. The first waveform specifics is 1V amplitude, and 1kHz freq.; second waveform is 2V amplitude and 2kHz freq.
Info
This question is closed. Reopen it to edit or answer.
Show older comments
The program I have created below, doesn't contain any errors once it is ran. However, it does not produce the two sinusoidal waveforms as desired.
t=(0:0.001:1)';
y=sin(2*pi*1000*t)+2*sin(2*pi*2000*t)
rng default;
yn=y+0.5*rand(size(t));
plot(t(1:50), yn(1:50))
"I am fairly new to MATLAB, so Im not sure if the problem lies within my plotting method or time vector." Any help is appreciated, thanks for your time.
Answers (1)
Sebastian Castro
on 31 Aug 2015
What you just did adds both the waveforms together before plotting them. Why not try something like:
t = (0:0.001:1)';
y1 = sin(2*pi*1000*t);
y2 = 2*sin(2*pi*2000*t);
rng default;
yn1 = y1 + 0.5*rand(size(t));
yn2 = y2 + 0.5*rand(size(t));
plot(t(1:50),yn1(1:50),t(1:50),yn2(1:50))
Also, if you're plotting 1000-2000 Hz frequencies, a time interval of 0.001 wouldn't be enough to capture the right dynamics. Try using a smaller one like 1e-4.
- Sebastian
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!