为了处理手机加速度计传感器数据。
function butterworth1D = ButterworthFilter( input1D, D_0, n )
%BUTTERWORTHFILTER 此处显示有关此函数的摘要
% 此处显示详细说明
% 1
% H(x) = ---------------------
% 1+[D / D_0]^(2n)
% input1D : 输入一维信号
% D_0 : 20
% n : 3
% butterworth1D : 巴特沃斯滤波后的输出
butterworth1D=fftshift(fft(input1D));
center=floor(length(input1D)/2);
for iter=1:length(input1D)
D=sqrt((iter-center)^2);
H=1/(1+(D/D_0)^(2*n)); % 低通滤波器
% H=1/(1+(D_0/D)^(2*n)); % 高通滤波器
butterworth1D(iter)=H*butterworth1D(iter);
end
butterworth1D=real(ifft(ifftshift(butterworth1D)));
end
function homomorphic1D = HomomorphicFilter( input1D, D_0, R, RH, C )
%HOMOMORPHICFILTER 此处显示有关此函数的摘要
% 此处显示详细说明
%
% H(x) = (RH - R) * (1 - exp(-C * (D.^2 / D_0.^2))) + R
% input1D : 输入一维信号
% D_0 : 10
% R : 1
% RH : 2
% C : 4
homomorphic1D=fftshift(fft(input1D));
center=floor(length(input1D)/2);
for iter=1:length(input1D)
D=sqrt((iter-center)^2);
H=(RH-R)*(1-exp(-C*(D.^2/D_0.^2)))+R;
homomorphic1D(iter)=H*homomorphic1D(iter);
end
homomorphic1D=real(ifft(ifftshift(homomorphic1D)));
end
使用ButterworthFilter
clc
clear
% [t,x,y,z]=textread('.\acce_200_1_2.txt','%f%f%f%f', 'delimiter', ','); %#ok<*DTXTRD>
[t,x,y,z]=textread('.\acce_200_100.txt','%f%f%f%f', 'delimiter', ','); %#ok<*DTXTRD>
sample = 1;
windowWidth = 500;
iterCount=length(t)-windowWidth+1;
offset=6;
t_sub_windowWidth=t(windowWidth:sample:length(t));
x_sub_windowWidth=x(windowWidth-offset:sample:length(t)-offset);
plot(t_sub_windowWidth, x_sub_windowWidth, 'Color', [1 0 0])
hold on
x_butterworth=zeros(iterCount, 1);
for i=1:iterCount
sub_x=x(i:1:i+windowWidth-1);
sub_x_butterworthFilter=ButterworthFilter(sub_x, 30, 1);
x_butterworth(i,1)=sub_x_butterworthFilter(windowWidth-offset);
end
plot(t_sub_windowWidth, x_butterworth, 'Color', [0 0 0])
% x_butterworth_homomorphic=HomomorphicFilter(x_butterworth, 10, 1, 2, 2);
% plot(t_sub_windowWidth,x_butterworth_homomorphic, 'Color', [0 0 1])
% All_X_Butterworth = ButterworthFilter(x_sub_windowWidth, 100, 1);
% plot(t_sub_windowWidth, x_sub_windowWidth, 'Color', [0 1 1]);
% plot(t_sub_windowWidth, All_X_Butterworth, 'Color', [0 0 1]);
效果图
红色为原始数据 黑色为滤波后数据
手持手机移动
实验室采集