加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
applyHighPassFilter.m 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
function [filteredData, b, a] = applyHighPassFilter(data, Fs, varargin)
% APPLYHIGH PASSFILTER Applies a 300 Hz high-pass filter to input data.
%
% filteredData = applyHighPassFilter(data, Fs) filters the input 'data'
% sampled at 'Fs' Hz and returns the result. The cutoff frequency is
% fixed at 300 Hz.
%
% [filteredData, b, a] = applyHighPassFilter(data, Fs) also returns the
% filter coefficients 'b' and 'a' for potential further use.
%
% Optional Parameters (Name-Value Pairs):
% 'Order' - Filter order (default: 5)
% 'PlotResult' - Flag to plot original and filtered data (default: false)
% Defaults
order = 5;
plotResult = false;
% Parse Optional Input Arguments
ii=1;
while ii<length(varargin)
if strcmpi(varargin{ii}, 'Order')
order = varargin{ii+1};
ii = ii + 2;
elseif strcmpi(varargin{ii}, 'PlotResult')
plotResult = logical(varargin{ii+1});
ii = ii + 2;
else
error('Unknown option %s', varargin{ii});
end
end
% High-Pass Filter Parameters
Fc = 300; % Cutoff Frequency in Hz
% Normalize the cutoff frequency to Nyquist frequency (Fs/2)
Wc = Fc / (Fs / 2);
% Design a high-pass Butterworth filter
[b, a] = butter(order, Wc, 'high');
% Apply the Filter
filteredData = filtfilt(b, a, data);
% Optional Plotting
if plotResult
figure;
subplot(2,1,1);
plot(data);
title('Original Signal');
xlabel('Sample Index'); ylabel('Amplitude');
subplot(2,1,2);
plot(filteredData);
title(['Filtered Signal (High-Pass > ', num2str(Fc), ' Hz)']);
xlabel('Sample Index'); ylabel('Amplitude');
end
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化