资源简介
巴特沃斯带通滤波器,简单实用,matlab
代码片段和文件信息
function [filtered_signalfiltbfilta]=bandpass_butterworth(inputsignalcutoff_freqsFsorder)
% Bandpass Butterworth filter
% [filtered_signalfiltbfilta] = bandpass_butterworth(inputsignalcutoff_freqFsorder)
%
% This is simply a set of built-in Matlab functions repackaged for ease of
% use by Chad Greene October 2012.
%
% INPUTS:
% inputsignal = input time series
% cutoff_freqs = filter corner frequencies in the form [f1 f2]
% Fs = data sampling frequency
% order = order of Butterworth filter
%
% OUTPUTS:
% filtered_signal = the filtered time series
% filtb filta = filter numerator and denominator (optional)
%
% EXAMPLE 1:
% load train
% t = (1:length(y))/Fs;
% y_filt = bandpass_butterworth(y[800 1000]Fs4); % cut off below 800 Hz and above 1000 Hz
%
% figure
% plot(ty‘b‘ty_filt‘r‘)
% xlabel(‘time in seconds‘)
% box off
% legend(‘unfiltered‘‘filtered‘)
% sound(yFs) % play original time series
% pause(2) % pause two seconds
% sound(y_filtFs) % play filtered time series
%
%
% EXAMPLE 2:
% load train
% t = (1:length(y))/Fs;
% [y_filtfiltbfilta] =bandpass_butterworth(y[800 1000]Fs4); % cut off below 800 Hz and above 1000 Hz
% [h1f1] = freqz(filtbfilta256Fs);
%
% figure
% subplot(311)
% plot(ty‘b‘ty_filt‘r‘)
% xlabel(‘time in seconds‘)
% box off
% text(0.1‘ time series‘‘units‘‘normalized‘)
%
% subplot(312)
% AX = plotyy(f110*log10(abs(h1))f1angle(h1)‘semilogx‘);
% set(get(AX(1)‘ylabel‘)‘string‘‘gain (dB)‘)
% set(get(AX(2)‘ylabel‘)‘string‘‘phase (rad)‘)
% xlim(AX(1)[min(f1) max(f1)])
% xlim(AX(2)[min(f1) max(f1)])
% text(0.1‘ filter response‘‘units‘‘normalized‘)
% box off
%
% [Pxxf] = pwelch(y512256[]Fs‘onesided‘);
% [Pxxff_f]= pwelch(y_filt512256[]Fs‘onesided‘);
% subplot(313)
% semilogx(f10*log10(Pxx))
% hold on
% semilogx(f_f10*log10(Pxxf)‘r‘)
% xlabel(‘frequency (Hz)‘)
% ylabel(‘PSD (dB)‘)
% xlim([min(f1) max(f1)])
% box off
% legend(‘unfiltered‘‘filtered‘‘location‘‘northwest‘)
% legend boxoff
nyquist_freq = Fs/2; % Nyquist frequency
Wn=cutoff_freqs/nyquist_freq; % non-dimensional frequency
[filtbfilta]=butter(orderWn‘bandpass‘); % construct the filter
filtered_signal=filtfilt(filtbfiltainputsignal); % filter the data with zero phase
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2359 2020-09-27 13:30 bandpass_butterworth.m
评论
共有 条评论