Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 加速度数据中的速度_Matlab - Fatal编程技术网

Matlab 加速度数据中的速度

Matlab 加速度数据中的速度,matlab,Matlab,我测量了加速度计的加速度数据。我想通过使用MATLAB对数据进行积分得到速度。这是我的密码: %clear clc; %Create a baseline sinusoidal signal ch1_100mss = ch1_100ms xdata = ch1_100mss; y0 = sin(xdata); %Add noise to the signal noise = 2*y0.*randn(size(y0)); % Response-dependent ydata = y0 + no

我测量了加速度计的加速度数据。我想通过使用MATLAB对数据进行积分得到速度。这是我的密码:

%clear
clc;

%Create a baseline sinusoidal signal
ch1_100mss = ch1_100ms xdata = ch1_100mss; y0 = sin(xdata);

%Add noise to the signal
noise = 2*y0.*randn(size(y0)); % Response-dependent
ydata = y0 + noise; % Gaussian noise

%Fit the noisy data with a custom sinusoidal model
f = fittype('a*sin(b*x)'); fit1 = fit(xdata,ydata,f,'StartPoint',[1 1]);

%Find the integral of the fit at the predictors
int = integrate(fit1,xdata,0);

%Plot the data, the fit, and the integral
subplot(2,1,1) plot(fit1,xdata,ydata) % cfit plot method subplot(2,1,2) plot(xdata,int,'m') % double plot method grid on legend('integral') plot(fit1,xdata,ydata,{'fit','integral'})
当我运行代码时,会出现下面的警告

Warning: Minimum step size reached; singularity possible.
> In quad at 103
  In cfit.integrate at 42
  In integration at 23

Warning: Minimum step size reached; singularity possible.
> In quad at 103
  In cfit.integrate at 40
  In cfit.plot at 138
  In integration at 33

Warning: Minimum step size reached; singularity possible.
> In quad at 103
  In cfit.integrate at 42
  In cfit.plot at 138
  In integration at 33

我的结果是否有效?

您可能希望在此处添加一个matlab标记。我可能知道集成,但不知道Matlab的API。您确认过拟合数据看起来像它应该的样子吗?因为您的代码没有生成样本信号,所以我使用了
xdata=linspace(0,20*pi,1000)。”。这样,您的算法运行良好,集成时不会出现任何警告。问题来自您的原始信号。正如Patrick提到的,在尝试集成之前,请仔细检查原始数据和拟合度。好的。mathworks论坛帮助我理解了奇点。绘制的数据并不那么令人信服