巴特沃斯滤波与同态滤波

为了处理手机加速度计传感器数据。

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

效果图
红色为原始数据 黑色为滤波后数据
手持手机移动
在这里插入图片描述
实验室采集
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你的问题涉及到 MATLAB 编程实现图像滤波,我可以为你提供代码实现。以下是代码示例: % 加载图像 img = imread('image.jpg'); % 理想低通滤波 D0 = 20; % 截止频率 h1 = lpfilter('ideal', size(img, 1), size(img, 2), D0); out1 = dftfilt(img, h1); % 滤波后的图像 % 理想高通滤波 D0 = 20; % 截止频率 h2 = hpfilter('ideal', size(img, 1), size(img, 2), D0); out2 = dftfilt(img, h2); % 滤波后的图像 % 巴特沃斯低通滤波 D0 = 20; % 截止频率 n = 2; % 阶数 h3 = lpfilter('btw', size(img, 1), size(img, 2), D0, n); out3 = dftfilt(img, h3); % 滤波后的图像 % 巴特沃斯高通滤波 D0 = 20; % 截止频率 n = 2; % 阶数 h4 = hpfilter('btw', size(img, 1), size(img, 2), D0, n); out4 = dftfilt(img, h4); % 滤波后的图像 % 高斯低通滤波 D0 = 20; % 截止频率 h5 = lpfilter('gaussian', size(img, 1), size(img, 2), D0); out5 = dftfilt(img, h5); % 滤波后的图像 % 高斯高通滤波 D0 = 20; % 截止频率 h6 = hpfilter('gaussian', size(img, 1), size(img, 2), D0); out6 = dftfilt(img, h6); % 滤波后的图像 % 同态滤波 c=1; D0=50; n=2; img=im2double(img); H=homoFilter(size(img),D0,n,c); out7=(double(I).*H); out7=uint8(out7); % 显示滤波前后的图像和频谱 figure; subplot(2,3,1),imshow(img),title('原图'); subplot(2,3,2),imshow(out1),title('理想低通滤波'); subplot(2,3,3),imshow(out2),title('理想高通滤波'); subplot(2,3,4),imshow(out3),title('巴特沃斯低通滤波'); subplot(2,3,5),imshow(out4),title('巴特沃斯高通滤波'); subplot(2,3,6),imshow(out5),title('高斯低通滤波'); % 显示滤波前后的频谱 figure; subplot(2,3,1),imshow(log(1+abs(fft2(img))),[]),title('原图的频谱'); subplot(2,3,2),imshow(log(1+abs(fft2(out1))),[]),title('理想低通滤波后的频谱'); subplot(2,3,3),imshow(log(1+abs(fft2(out2))),[]),title('理想高通滤波后的频谱'); subplot(2,3,4),imshow(log(1+abs(fft2(out3))),[]),title('巴特沃斯低通滤波后的频谱'); subplot(2,3,5),imshow(log(1+abs(fft2(out4))),[]),title('巴特沃斯高通滤波后的频谱'); subplot(2,3,6),imshow(log(1+abs(fft2(out5))),[]),title('高斯低通滤波后的频谱');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值