【问题标题】:Interpolate two sine waves with different time points based on cycle percent MATLAB基于循环百分比MATLAB插值两个不同时间点的正弦波
【发布时间】:2017-10-26 15:13:04
【问题描述】:

我有两个不同时间点的正弦波如下:

t1=1:10;
y1=sin(t1);
per1=100./t1;

t2=1:12;
y2=sin(2*t2);
per2=100./t2;

如您所见,y 变量之一有 12 个时间点,而另一个只有 10 个。如果我们将每个范围视为一个周期,并将其表示为百分比,我想将正弦波将 10 和 12 个时间点放在相同的 0-100% 范围内,然后将它们相加。

使用这种技术,我将添加两个正弦波,不是基于时间,而是基于周期的百分比。

【问题讨论】:

    标签: matlab interpolation


    【解决方案1】:

    您应该创建一些公共轴,并使用插值(例如interp1)来近似所有这些点的值。然后你可以添加它们。

    % Your data, but with smaller intervals so it doesn't look like junk!
    t1 = 1:0.01:10; y1 = sin(t1); 
    t2 = 1:0.02:12; y2 = sin(2*t2);
    % Interpolation to the highest number of points
    N = max(numel(t1), numel(t2));
    y1interp = interp1(t1, y1, linspace(min(t1), max(t1), N), 'linear');
    y2interp = interp1(t2, y2, linspace(min(t2), max(t2), N), 'linear');
    % Put on a common percentage axes with N points
    pct = linspace(0, 1, N);
    % Plot (or do whatever else!)
    figure; hold on;
    plot(pct, y1interp, '--r');
    plot(pct, y2interp, '--b');
    plot(pct, y1interp + y2interp, '-k');
    hold off;
    

    输出

    注意:您可能需要阅读有关 Nyquist's theorem 的信息 - 您应该考虑将用于插值的常见样本数 N 增加到我使用的两倍。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多