English 中文(简体)
MATLAB: filter noisy EKG signal
原标题:

What is the best filter to use to remove noise from an ECG signal with matlab?

问题回答

If you have access to the Signal Processing Toolbox, then check out the Savitzky-Golay filter, namely the function sgolay. There s an accompanying demo, just run sgolaydemo.


The following is an example to show the various ways you can apply filtering and de-noising to a signal. Note some of these functions requires certain toolboxes to be present:

% load ecg: simulate noisy ECG
Fs=500;
x = repmat(ecg(Fs), 1, 8);
x = x + randn(1,length(x)).*0.18;

% plot noisy signal
figure
subplot(911), plot(x), set(gca,  YLim , [-1 1],  xtick ,[])
title( noisy )

% sgolay filter
frame = 15;
degree = 0;
y = sgolayfilt(x, degree, frame);
subplot(912), plot(y), set(gca,  YLim , [-1 1],  xtick ,[])
title( sgolayfilt )

% smooth
window = 30;
%y = smooth(x, window,  moving );
%y = smooth(x, window/length(x),  sgolay , 2);
y = smooth(x, window/length(x),  rloess );
subplot(913), plot(y), set(gca,  YLim , [-1 1],  xtick ,[])
title( smooth )

% moving average filter
window = 15;
h = ones(window,1)/window;
y = filter(h, 1, x);
subplot(914), plot(y), set(gca,  YLim , [-1 1],  xtick ,[])
title( moving average )

% moving weighted window
window = 7;
h = gausswin(2*window+1)./window;
y = zeros(size(x));
for i=1:length(x)
    for j=-window:window;
        if j>-i && j<(length(x)-i+1) 
            %y(i) = y(i) + x(i+j) * (1-(j/window)^2)/window;
            y(i) = y(i) + x(i+j) * h(j+window+1);
        end
    end
end
subplot(915), plot( y ), set(gca,  YLim , [-1 1],  xtick ,[])
title( weighted window )

% gaussian
window = 7;
h = normpdf( -window:window, 0, fix((2*window+1)/6) );
y = filter(h, 1, x);
subplot(916), plot( y ), set(gca,  YLim , [-1 1],  xtick ,[])
title( gaussian )

% median filter
window = 15;
y = medfilt1(x, window);
subplot(917), plot(y), set(gca,  YLim , [-1 1],  xtick ,[])
title( median )

% filter
order = 15;
h = fir1(order, 0.1, rectwin(order+1));
y = filter(h, 1, x);
subplot(918), plot( y ), set(gca,  YLim , [-1 1],  xtick ,[])
title( fir1 )

% lowpass Butterworth filter
fNorm = 25 / (Fs/2);               % normalized cutoff frequency
[b,a] = butter(10, fNorm,  low );  % 10th order filter
y = filtfilt(b, a, x);
subplot(919), plot(y), set(gca,  YLim , [-1 1])
title( butterworth )

screenshot

Two filter design tools/demos that you may want to check out:

These should give you a chance to try out different filters and filter parameters to see how they perform with EKG/ECG data.





相关问题
Least squares optimal scaling

I have two waveforms which are linked by a numerical factor. I need to use optimal scaling (least squares) between the two waveforms to calculate this factor in Matlab. Unfortunately I have no idea ...

How to Get a Quantitative Comparison of Two Signals

I’m trying to implement a Blind Source Separation (BSS) algorithm and I’m running into trouble determining the efficacy of the algorithm. I’m trying to create test cases where I work backwards and ...

数字过滤器设计

采用什么最佳方法选择马特拉布数字过滤器设计特性与全球数据分析仪的过滤器? 更具体地说,如果我有信号,我如何确定哪些过滤价值......。

DSP Algorithms Book [closed]

I m looking for a book similar to "Introduction to Algorithms" by Thomas Cormen geared towards DSP algorithms. Is there anything as thorough as Cormen on the DSP market? EDIT I should say I m ...

Digital Sound Processing in C# (and possibly SilverLight)

I need to do some basic and non basic DSP programming in C#. At its core, it includes the generation of a sin wave deciding its frequency in Hertz. Then I d like to Frequency Modulate it and maybe ...

Basic DSP - level adjustment

I m new to DSP programming, and I m wondering how best to carry out the seemingly basic operation of level adujustment. Say I have an 8 bit number that represents the amplitude I want a signal to be ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

热门标签