【问题标题】:How do I plot the sum of two discrete time signal for different time index?如何绘制不同时间索引的两个离散时间信号的总和?
【发布时间】:2017-09-17 12:03:55
【问题描述】:

如何将具有不同时间索引的两个离散时间信号相加,即。在时间索引n1=-3:1 处给出第一个信号x=[1 2 3 4 5],在时间索引n2=0:4 处给出第二个信号y=[1 1 2 2 3]。 我不能只添加这两个信号,因为它们的长度不同。到目前为止,我的代码是:

n1=-3:1;
x=input('Enter the value of X:');
y=input('Enter the value of Y:');
subplot(3,1,1);
stem(n1,x);
grid on;
xlabel('Time index');
ylabel('Amplitude');
axis([-10 10 0 10]);
title('signal X');


n2=0:4;
subplot(3,1,2);
stem(n2,y);
grid on;
xlabel('Time index');
ylabel('Amplitude');
axis([-10 10 0 10]);
title('signal Y');

接下来我该怎么做?如何继续添加这两个信号?

【问题讨论】:

  • 您是否会遇到像 n1= 1 : 3 和 n2 = .5 : 3.5 这样的情况?

标签: matlab signals signal-processing matlab-figure


【解决方案1】:

作为一种简化的方法,您可以测量时域的大小并创建一个具有相同大小的最终变量S。此外,创建一个索引校正器m,使我们能够使用n1n2 作为矩阵索引。最后,将 xy 与它们的正确偏移量相加。

m=1-min([n1 n2])
S= zeros(1+max([n1 n2]) - min([n1 n2]),1)
S(m+[n1])= S(m+[n1])+x
S(m+[n2])= S(m+[n2])+y
stem([1:1:size(S,1)]-m,S)

您可以以归纳方式扩展它以与更多时间序列兼容。

【讨论】:

    【解决方案2】:

    我会写一个新的向量n3,它是n1n2 的联合。然后,将xy 附加零,使其长度与n3 的长度匹配,并且它们也正确对齐。

    n3 = min([n1 n2]):max([n1 n2]);
    x = [x 0 0 0];
    y = [0 0 0 y];
    subplot(3, 1, 3);
    stem(n3, x + y);
    grid on;
    xlabel('Time index');
    ylabel('Amplitude');
    axis([-10 10 0 10]);
    title('signal X+Y');
    

    结果是

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      • 2016-09-28
      • 1970-01-01
      • 2014-04-07
      • 2019-03-03
      相关资源
      最近更新 更多