绘制连续信号

时间:2014-07-21 15:59:02

标签: matlab plot line signal-processing

我正在尝试按照下面的图像精确打印连续信号:

enter image description here

以下是我的代码:

x=[0 0 0 1 1 1 1 1 1 -1 -1 0 0];
n=[6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 ];
subplot(2,2,2);
axis([min(n)-10,max(n)+10,min(x)-10,max(x)+10]);
plot(n,x); 
grid on;
xlabel('Time');
ylabel('x2(t)');
title('Continous Signal');

但是输出的情节数字并不符合预期:

enter image description here

在MATLAB中我们不能正确显示连续信号吗?如果是,我需要在代码中进行哪些更改。

为什么信号值不是通过直线连接的 - 它是一条曲线(或斜线)?

1 个答案:

答案 0 :(得分:6)

您正在寻找stairs功能:

x = [0 0 0 1 1 1 1 1 1 -1 -1 0 0];
n = [-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 ];

stairs(n,x); 

enter image description here