对此可以用滤波的方法将大的趋势项去掉。

测试的代码如下

% 测试积分对正弦信号的作用

clc

clear

close all

%% 原始正弦信号

ts = 0.001;

fs = 1/ts;

t = 0:ts:1000*ts;

f = 50;

dis = sin(2*pi*f*t); % 位移

vel = 2*pi*f.*cos(2*pi*f*t); % 速度

acc = -(2*pi*f).^2.*sin(2*pi*f*t); % 加速度

% 多个正弦波的测试

% f1 = 400;

% dis1 = sin(2*pi*f1*t); % 位移

% vel1 = 2*pi*f1.*cos(2*pi*f1*t); % 速度

% acc1 = -(2*pi*f1).^2.*sin(2*pi*f1*t); % 加速度

% dis = dis + dis1;

% vel = vel + vel1;

% acc = acc + acc1;

%

结:频域积分正常恢复信号,时域积分恢复加入的高频信息有误差

% 加噪声测试

acc = acc + (2*pi*f).^2*0.2*randn(size(acc));

% 结:噪声会使积分结果产生大的趋势项

figure

ax(1) = subplot(311);

plot(t, dis), title('位移')

ax(2) = subplot(312);

plot(t, vel), title('速度')

ax(3) = subplot(313);

plot(t, acc), title('加速度')

linkaxes(ax, 'x');

% 由加速度信号积分算位移

[disint, velint] = IntFcn(acc, t, ts, 2);

axes(ax(2)); hold on

plot(t, velint, 'r'), legend({'原始信号',

'恢复信号'})

axes(ax(1)); hold

on

plot(t, disint, 'r'), legend({'原始信号', '恢复信号'})

%% 测试积分算子的频率特性

n = 30;

amp = zeros(n, 1);

f = [5:30 40:10:480];

figure

for i = 1:length(f)

fi = f(i);

acc = -(2*pi*fi).^2.*sin(2*pi*fi*t); % 加速度

[disint, velint] = IntFcn(acc, t, ts, 2); % 积分算位移

amp(i) = sqrt(sum(disint.^2))/sqrt(sum(dis.^2));

plot(t, disint)

drawnow

% pause

end

close

figure

plot(f, amp)

title('位移积分的频率特性曲线')

xlabel('f')

ylabel('单位正弦波的积分位移幅值')

以上代码中使用IntFcn函数实现积分,它是封装之后的函数,可以实现时域积分和频域积分,其代码如下

%

积分操作由加速度求位移,可选时域积分和频域积分

function [disint, velint] = IntFcn(acc, t, ts, flag)

if flag == 1

% 时域积分

[disint, velint] = IntFcn_Time(t, acc);

velenergy = sqrt(sum(velint.^2));

velint = detrend(velint);

velreenergy = sqrt(sum(velint.^2));

velint =

velint/velreenergy*velenergy; disenergy = sqrt(sum(disint.^2));

disint = detrend(disint);

disreenergy = sqrt(sum(disint.^2));

disint = disint/disreenergy*disenergy; %

此操作是为了弥补去趋势时能量的损失

% 去除位移中的二次项

p = polyfit(t, disint, 2);

disint = disint - polyval(p, t);

else

% 频域积分

velint = iomega(acc, ts, 3, 2);

velint = detrend(velint);

disint = iomega(acc, ts, 3, 1);

% 去除位移中的二次项

p = polyfit(t, disint, 2);

disint = disint - polyval(p, t);

end

end

其中时域积分的子函数如下

% 时域内梯形积分

function [xn, vn] = IntFcn_Time(t, an)

vn = cumtrapz(t, an);

vn = vn - repmat(mean(vn), size(vn,1), 1);

xn = cumtrapz(t, vn);

xn = xn - repmat(mean(xn), size(xn,1), 1);

end

频域积分的子函数如下(此代码是一个老外编的,在频域内实现积分和微分操作)

function dataout = iomega(datain, dt,

datain_type, dataout_type)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%

% IOMEGA is a

MATLAB script for converting displacement, velocity, or

% acceleration

time-series to either displacement, velocity, or

% acceleration

times-series. The script takes an array of waveform data

% (datain),

transforms into the frequency-domain in order to more easily

% convert into

desired output form, and then converts back into the time

% domain

resulting in output (dataout) that is converted into the

desired

% form.

%

% Variables:

% ----------

%

% datain = input waveform

data of type datain_type

%

% dataout = output waveform

data of type dataout_type

%

% dt = time increment

(units of seconds per sample)

%

% 1 - Displacement

% datain_type = 2 -

Velocity

% 3 - Acceleration

%

% 1 - Displacement

% dataout_type

= 2 -

Velocity

% 3 - Acceleration

%

%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Make sure that

datain_type and dataout_type are either 1, 2 or 3

if (datain_type < 1 || datain_type >

3)

error('Value for datain_type must be a 1, 2 or 3');

elseif (dataout_type < 1 || dataout_type

> 3)

error('Value for dataout_type must be a 1, 2 or 3');

end

% Determine

Number of points (next power of 2), frequency increment

% and Nyquist

frequency

N = 2^nextpow2(max(size(datain)));

df = 1/(N*dt);

Nyq = 1/(2*dt);

% Save frequency

array

iomega_array = 1i*2*pi*(-Nyq : df : Nyq-df);

iomega_exp = dataout_type - datain_type;

% Pad datain

array with zeros (if needed)

size1 = size(datain,1);

size2 = size(datain,2);

if (N-size1 ~= 0 && N-size2 ~=

0)

if size1 > size2

datain = vertcat(datain,zeros(N-size1,1));

else

datain = horzcat(datain,zeros(1,N-size2));

end

end

% Transform

datain into frequency domain via FFT and shift output (A)

% so that

zero-frequency amplitude is in the middle of the array

% (instead of the

beginning)

A = fft(datain);

A = fftshift(A);

% Convert datain

of type datain_type to type dataout_type

for j = 1 : N

if iomega_array(j) ~= 0

A(j) = A(j) * (iomega_array(j) ^ iomega_exp);

else

A(j) = complex(0.0,0.0);

end

end

% Shift new

frequency-amplitude array back to MATLAB format and

% transform back

into the time domain via the inverse FFT.

A = ifftshift(A);

datain = ifft(A);

% Remove zeros

that were added to datain in order to pad to next

% biggerst power

of 2 and return dataout.

if size1 > size2

dataout = real(datain(1:size1,size2));

else

dataout = real(datain(size1,1:size2));

end

return

matlab加速度转化为位移,matlab数值积分实现加速度、速度、位移的转换(时域频域积分)...相关推荐

  1. matlab频域积分,matlab数值积分实现(时域频域积分) | 学步园

    最近做有关加速度的数据处理,需要把加速度积分成位移,网上找了找相关资料,发现做这个并不多,把最近做的总结一下吧! 积分操作主要有两种方法:时域积分和频域积分,积分中常见的问题就是会产生二次趋势.关于积 ...

  2. matlab图像转化为索引图,matlab - 将RGB图像转换为索引图像并保存 - 堆栈内存溢出...

    您可以执行以下操作: 将图像从RGB转换为2种颜色的索引图像:[X, cmap] = rgb2ind(RGB, 2); 将彩色图的索引替换为黑白:cmap(1, 1:3) = [0, 0, 0]; % ...

  3. matlab加速度转化为位移,加速度转换成位移的matlab代码及说明

    加速度转换成位移的matlab代码及说明 由测量的加速度离散数据数据转化成位移数据一般不直接在时域进行积分处理,而是由时域转换成频域在频域中进行二次积分再转化到时域中得到位移结果. 相关matlab处 ...

  4. 在matlab中怎样把图片转化为数据类型,matlab图像数据类型转换

    uint 8:无符号的8位(8bit)整型数据(unit 都是存储型) int :整型数据 1.在MATLAB中,数值一般都采用double型(64位)存储和运算. 2.为了节省存储空间,MATLAB ...

  5. 信号相角位移量的计算与信号位移计算-附Matlab代码

    一.初始相角的位移量 在信号处理中正弦信号经常表示为 x ( n ) = A cos ⁡ ( 2 π f 0 n / f s + θ ) x\left( n \right)=A\cos (2\pi { ...

  6. 华式摄氏度转化为摄氏度matlab

    数学公式 C=(F-32)*5/9 代码部分 function C=F2C(F) while 1F=input('输入℉')C=(F-32).*5/9if isempty(F)breakend end ...

  7. MATLAB学习笔记2:MATLAB基础知识(下)

    阅读前请注意: 1. 该学习笔记是华中师范大学HelloWorld程序设计协会2021年寒假MATLAB培训的学习记录,是基于培训课堂内容的总结归纳.拓展阅读.博客内容由 @K2SO4钾 撰写.编辑, ...

  8. matlab中function c=li,matlab 函数表

    Matlab库函数命令大全 附录 MATLAB函数参考 附录1 常用命令 附录1.1 管理用命令 函数名 功能描述 函数名 功能描述 addpath 增加一条搜索路径 rmpath 删除一条搜索路径 ...

  9. matlab的优势和特点,MATLAB优势特点

    <matlab工程计算及分析> 第1讲 matlab基础入门 1 1.1 matlab简介 1 1.1.1 matlab的历史 1 1.1.2 matlab的主要功能 4 1.2 matl ...

最新文章

  1. 如何关闭华为自动杀进程_手机自动扣费该如何删除,教你正确关闭,我们要知道!...
  2. 浅谈阀控型铅酸蓄电池在数据中心的应用与日常管理
  3. SSL certificate problem, verify that the CA cert is OK. Details:
  4. 转 Fragment 和 FragmentActivity的使用
  5. Django入门-项目创建与初识子应用
  6. Android-ndk编译osgdb_3ds静态库
  7. [转贴]暴雪的霸王条款是否合理?
  8. 《天天数学》连载05:一月五日
  9. mysql一次更新内容大于4M时报错修改max_allowed_packet变量
  10. 看上90亿的当当,海航的眼光是极好的
  11. 苹果发布会新品曝光 这款软件肯定用得上
  12. 07. Declare destructors virtual in polymorphic base classes
  13. 揭秘Windows Server 2008新功能
  14. opencv 图像平滑处理(python)
  15. Excel快速删除空白行与调整行高列宽的方法,学会了很实用
  16. Ubuntu18.04创建快捷方式
  17. windows 程序设计 第一章
  18. 断言(Assertion)
  19. 2021单招十类计算机试题,2021年河北省高职单招考试十类和高职单招对口电子电工类、对口计算机类联考文化素质考试(数学)考试大纲...
  20. c语言间隔输出菱形图案,c语言输出菱形图案

热门文章

  1. 三维重建 | 关键技术及建模流程综述「AI核心算法」
  2. PAC脚本语法(代理自动配置)
  3. 业务“多面手”,基于低代码平台的CRM系统
  4. 《马伯庸笑翻中国简史》
  5. 2022数模校赛一等奖部分优秀论文学习观摩心得总结
  6. c#连接读取mysql内容(报警无法连接处理方法)
  7. java脏字过滤_分享JavaWeb中filter过滤器的案例妙用 - 脏话过滤/编码过滤/代码过滤...
  8. 精品软件 推荐 微软官方出品的 杀毒软件 MSE Microsoft Security Essentials
  9. Leetcode904
  10. 教你如何拷贝IE浏览器的网址收藏夹