主要内容

upsample

R2026b

按整数倍数提高采样率

描述

y = upsample(x,n) 通过在采样之间插入 n - 1 个零来提高 x 的采样率。如果 x 是矩阵,该函数将每列视为一个单独序列。

示例

y = upsample(x,n,phase) 用于指定对上采样序列偏移多少个采样。

示例

示例

全部折叠

将序列的采样率提高 3 倍。

x = [1 2 3 4];
y = upsample(x,3)
y = 1×12

     1     0     0     2     0     0     3     0     0     4     0     0

将序列的采样率提高 3 倍,并增加相位偏移量 2。

x = [1 2 3 4];
y = upsample(x,3,2)
y = 1×12

     0     0     1     0     0     2     0     0     3     0     0     4

将矩阵的采样率提到 3 倍。

x = [1 2;
     3 4;
     5 6];
y = upsample(x,3)
y = 9×2

     1     2
     0     0
     0     0
     3     4
     0     0
     0     0
     5     6
     0     0
     0     0

自 R2026b 起

生成一个长度为 101 秒的正弦波形,基频为 0.01 Hz,连续采样之间间隔 5 秒。

ts = 5;
tx = (1:ts:101)';
x = sin(2*pi*0.01*tx);

使用上采样因子 3 对信号进行上采样。比较原始信号和上采样后的信号。为生成上采样信号,upsample 函数在正弦采样之间插入两个零。

n = 3;
ty = (1:ts/n:ts*numel(x))';
y = upsample(x,n);
plot(tx,x,"o",ty,y,".")
legend(["Original" "Upsampled"])

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Original, Upsampled.

使用上采样因子 3 和相位偏移 1 对信号进行上采样。比较原始信号和上采样后的信号。由于指定的相位偏移,原始信号的第一个采样与上采样信号上的第二个采样匹配。

p = 1;
ty = (1:ts/n:ts*numel(x))';
y = upsample(x,n,p);
plot(ts/n*p+tx,x,"o",ty,y,".")
legend(["Original" "Upsampled"])

Figure contains an axes object. The axes object contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Original, Upsampled.

输入参数

全部折叠

输入数组,指定为向量或矩阵。如果 x 是矩阵,该函数将列视为独立通道。

示例: cos(pi/4*(0:159)) + randn(1,160) 用于指定嵌入高斯白噪声中的正弦波。

示例: cos(pi./[4;2]*(0:159))' + randn(160,2) 用于指定双通道含噪正弦波。

上采样因子,指定为正整数。

数据类型: single | double

偏移量,指定为从 0 到 n - 1 的正整数。

数据类型: single | double

输出参量

全部折叠

上采样数组,以向量或矩阵形式返回。y 有 x×n 个采样。

提示

要从上采样输出 y 中去除成像伪影,请对 y 应用归一化截止频率为 pi/n 弧度/采样点的低通滤波器。或者,使用 interp 函数。

扩展功能

全部展开

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

GPU 代码生成
使用 GPU Coder™ 为 NVIDIA® GPU 生成 CUDA® 代码。

版本历史记录

在 R2006a 之前推出

全部展开