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.
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
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.
0 个评论
回答(1 个)
Sebastian Castro
2015-8-31
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
0 个评论
此问题已关闭。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!