代码拉取完成,页面将自动刷新
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。