在MATLAB中对时间信号进行重采样 [英] Resampling of time signal in MATLAB

查看:1040
本文介绍了在MATLAB中对时间信号进行重采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to resample my signal with to new time. Currently the sampling time of my signal is 0.01s, and the size of my signal and time array is 1*90001.

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

I am trying to use resample(x,p,q) in MATLAB, but I am a little bit confused.

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

Can somebody suggest the right way to use this function and how to resample my data to rate of 0.02s instead of 0.01s?

代码-这就是我尝试将resample与示例数据一起使用的方式.

Code - this is how I am trying to use resample, with example data.

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

推荐答案

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

There is another way to resample in a lower frequency your data. Use this code:

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');

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

I hope that's what you wanted. Greetings

这篇关于在MATLAB中对时间信号进行重采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆