i using matlab filter ecg data. there noise in data , have tried using butterfilter. problem there higher power butter filter, above 3 makes data disappear.
i have looked through matlab's guide on filter design unclear , still confused on how use , implement it.
goal: filter ecg data 0 phase distortion, filter outside 1 20 hz
my code right now:
%takes in 1 channel of data datamatrix, plots it, filters, , plots again in new figure channel = 150; x = datamatrix(:,channel); plot(x) rawtitle = sprintf('raw channel %d ', channel); title(rawtitle) figure [b_pass a_pass] = butter(3, [1/1000 20/1000], 'bandpass'); plot(filtfilt(b_pass, a_pass, x)) channeltitle=sprintf('filtered channel %d ', channel); title(channeltitle)
designing filter
let's start basics of designing butterworth-filter in matlab. here, can define filter using normalized frequencies. therefore need know sampling frequency fs determine normalized frequency fn this: fn = f/fs. need order order , 2 cutoff-frequencies fc1 , fc2. second argument of butter takes 'frequencies' 0 1 1 corresponds nyquist-rate half of sampling frequency fs. therefore have divide fs 2 in second argument.
[b,a] = butter(order, [fc1,fc2]/(fs/2), 'bandpass'); application
now can go code , apply filter. note filtfilt zero-phase , doubles order of original filter. can take sample data here (fs assumed 500hz) , see if works expected.
% load sample data , assign x load('ecg.mat'); fs = 500; x = ecg; % define use op's code channel = 150; % plot raw data figure plot(x) rawtitle = sprintf('raw channel %d ', channel); title(rawtitle) % design filter [b_pass,a_pass] = butter(3,[1,20]/(fs/2), 'bandpass'); % filter data , plot figure plot(filtfilt(b_pass, a_pass, x)) channeltitle=sprintf('filtered channel %d ', channel); title(channeltitle) this result:

Comments
Post a Comment