在MATLAB中重新采样时间信号

时间:2017-12-13 09:45:06

标签: matlab signals signal-processing resampling

我想用新时间重新采样我的信号。目前,我信号的采样时间为0.01s,信号和时间数组的大小为1*90001

我正在尝试在MATLAB中使用resample(x,p,q),但我有点困惑。

有人可以建议使用此功能的正确方法以及如何将我的数据重新采样为0.02s而不是0.01s吗?

代码 - 这就是我尝试使用resample和示例数据的方法。

t = [0:0.03:1];
x = sin(4*pi*t);
y = resample(x, 1, 2);
ty = resample(t,1,2);

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

更新代码:

t = [0 2 3 7 8 9 10 11 12 17 18 19 20 24 25 26 27 28 29 31 32 33 35 37 41 ];
A = [0 0 1 2 3 5.2 0 -1.4 0 2 2.7 2 2.3 6 7.3 0 0 -8.6 0 1 1 2.5 3 4.8 2];
plot(t,A)
% Tx = min(diff(t));
Tx = 1:0.1:25;
B = interp1(t,A,Tx); %re-make example data to have decimal points on the x-axis
 y = resample(B, 2, 1); 
 T = 0.05;
 Ty = T / (2 / 1); 
 ty = (0:length(y)-1)*Ty;
% A = interp1(t,ref,t2);
% A = ref;
figure 
plot(Tx,B,'b')
hold on
plot(ty,y,'r')
plot(t,A,'g')
hold off

3 个答案:

答案 0 :(得分:1)

以10 ms的均匀采样间隔对原始信号进行采样,并且您希望将采样减少到20 ms。为什么不用你原始信号的每秒数据点?

y = x(1:2:end);
ty = t(1:2:end);

<强>更新

对于非规则间隔的数据集,可以使用函数resample,如下所示:https://au.mathworks.com/help/signal/ref/resample.html#bungoxs

你可以尝试

fs = 1/0.02;
[y, ty] = resample(x, t, fs, 1, 2)

答案 1 :(得分:1)

首先,您不需要重新采样时间线。 定义时间采样间隔变量或采样频率变量要容易得多: T = 0.03; Fs = 1/T;

因此, x 重新采样您的行为正确: y = resample(x, 1, 2);

但必须通过调整的采样间隔重建新的时间线: Ty = T / (1 / 2); ty = (0:length(y)-1)*Ty;

resample 函数仅适用于统一时间分布的数据点。如果您的原始点分布不均匀,则需要:

  1. 将您的 x 信号插入到统一时间线,其中原始时间线的采样间隔最小: Tx = min(diff(t)); 。请参阅示例 interp1 函数。
  2. 将插值的均匀时间分布(采样)信号重新采样到新的采样间隔( resample 函数)。

答案 2 :(得分:1)

还有另一种方法可以较低频率重新采样数据。 使用此代码

fs=1/(timesignal(2)-timesignal(1)); %for example 48000Hz
fs_resampled=100; % [Hz] example goal value 
t_original = [0:1/fs:(1/fs*(length(signal)-1))];%current time signal
t_resampled = [0:1/fs_resampled:max(t_original)];%new time signal
Signal_resampled = interp1(t_original,signal,t_resampled,'spline');

我希望那是您想要的。 问候