How do plot 2 sine waves on the same plot with different line markers?
显示 更早的评论
sine function (1)
time = 0: 4*pi
amplitude = -1:1
sine function (2)
phase shift of +pi/2 and -pi/2
采纳的回答
I have no idea what you mean by amp = 1:-1.
Anyway, start with this and adapt as needed:
% sine function (1)
% time = 0: 4*pi
t = linspace(0, 4*pi, 50)
period = 2 * pi;
% amp = 1:-1 No idea what this means.
amp = 1; % Let's just say it's 1.
y1 = amp * sin(2 * pi * t / period);
hFig = figure; % Bring up new figure.
plot(t, y1, 'b.', 'MarkerSize', 30);
grid on;
xlabel('t', 'FontSize', 20);
ylabel('y', 'FontSize', 20);
% sine function (2)
% phase shift of +pi/2 and -pi/2
y2 = amp * sin(2 * pi * (t - pi/2) / period);
hold on;
plot(t, y2, 'rs', 'MarkerSize', 10, 'LineWidth', 2);
% sine function (3)
% phase shift of +pi/2 and -pi/2
y3 = amp * sin(2 * pi * (t + pi/2) / period);
plot(t, y3, 'm*', 'MarkerSize', 12, 'LineWidth', 2);
hFig.WindowState = 'maximized'
legend('y1', 'y2', 'y3');

6 个评论
thanks! p.s. amp is amplitude
which is the y-axis, would it still be correct?
Would what still be correct? And how can a signal have two different amplitudes? One signal can only have one amplitude. If you have 2 amplitudes of -1, and 1, and 3 phases of -pi/2, 0, and +pi/2, then that would be 2*3 = 6 different signals to plot if you want all possible combinations.
sorry let me rephrase, if the amplitude ranges from -1 to 1, would the given code give the right graph?
No. You need to define the amplitude. I plotted just for one amplitude. What amplitudes do you have? What does "ranges" mean? You mean -1, -.99, -.98, .... +.98, +.99, 1, so like 201 different amplitudes to give 201 different signals? How about amp = rand(1,5) and you plot 5 different signals with 5 different amplitudes? I have no idea what "ranges" means to you. What was wrong with amp=1 like I did? You have to be specific.
Ok. I understanbd now I was just confused, the code is great. Thank you.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
