使用MATLAB进行信号的上采样

Using MATLAB to perform upsampling of signal

我正在搜索将信号上采样 3 倍的代码,我发现了以下步骤

dataSize = size(datain,2);
upsamp = [datain.' zeros(dataSize,1) zeros(dataSize,1)];
len = size(upsamp,1) * size(upsamp,2);
upsamp = reshape(upsamp.',1,len);

我不确定这些步骤应该如何执行?我只是在寻找直觉

复制自Wikipedia

Interpolation by an integer factor, L, can be explained as a 2-step process, with an equivalent implementation that is more efficient:

  1. Create a sequence, x_L[n], comprising the original samples, x[n], separated by L-1 zeros.
  2. Smooth out the discontinuities with a lowpass filter, which replaces the zeros.

您还可以阅读更多详细信息here and here

函数upsample executes only the first step, while function resample 执行它们。看一下下面的代码,注意两个数字的区别:

close all; clear all; clc;

t = [0:0.03:1];
x = sin(4*pi*t);

% function resample performs interpolation
y = resample(x, 3, 1);
ty = [0:0.01:1.01];

figure;stem(ty, y, 'r*');
hold on;stem(t, x);

% function upsample adds zeros
z = upsample(x,3);
tz = [0:0.01:1.01];

figure;stem(tz, z, 'r*');
hold on;stem(t, x);