DSPRelated.com
Forums

find peak of the the ECG signal

Started by Jen September 4, 2006
Hi everybody!!

I am looking for a matlab code/function, that picks the highest peaks
out of a noisy signal, the signal is already baseline corrected. the
peak can be found after y=1, I thought of using diff to differentiat
and get the max of the curve but I wasn't sure how do i go about. Pls
help 
 
Thanks 
 
Jen

A link for the code :
http://www.math.duke.edu/education/ccp/materials/diffeq/mlabtutor/mlabtut8.html

Differentiation is a good idea cos u can find local maximums using the 1st
and 2nd derivatives etc. 

wat you could try is to create 3 vectors :

1. the original ecg signal
2. the 1st derivative
3. 2nd derivative 

calculate the mean of the original signal and go through the
differentiated vector (i.e. 2). If the 1st derivative is zero and the 2nd
derivative at that place is lower than zero. 

Or you can just work with the second vector and check the for the sign on
either side of the zero-intercept.

probably i answered more than i needed to, but it was good refreshing for
me too :-)
Beware:

'diff' does not differentiate except under very special conditions.
Try 'help diff' to see what it does.

Dirk Bell
DSP Consultant

Jen wrote:
> Hi everybody!! > > I am looking for a matlab code/function, that picks the highest peaks > out of a noisy signal, the signal is already baseline corrected. the > peak can be found after y=1, I thought of using diff to differentiat > and get the max of the curve but I wasn't sure how do i go about. Pls > help > > Thanks > > Jen
"dbell" <bellda2005@cox.net> wrote in news:1157388830.974655.208210
@p79g2000cwp.googlegroups.com:

> Beware: > > 'diff' does not differentiate except under very special conditions. > Try 'help diff' to see what it does. > > Dirk Bell > DSP Consultant > > Jen wrote: >> Hi everybody!! >> >> I am looking for a matlab code/function, that picks the highest peaks >> out of a noisy signal, the signal is already baseline corrected. the >> peak can be found after y=1, I thought of using diff to differentiat >> and get the max of the curve but I wasn't sure how do i go about. Pls >> help >> >> Thanks >> >> Jen > >
Dirk, Ya got me! Diff is the difference between adjacent elements. Except for scaling by sample rate, I don't see how this is that much different from a wide-open differentiation for a vector. I prefer a two point central difference (convolution w/ [1 0 -1]*samprate/2 as opposed to convolution with [ 1 -1]*samprate), and I generally follow the operation with an FIR low pass, but aside from that, I don't get your point. -- Scott Reverse name to reply
Jen wrote:

> Hi everybody!! > > I am looking for a matlab code/function, that picks the highest peaks > out of a noisy signal, the signal is already baseline corrected. the > peak can be found after y=1, I thought of using diff to differentiat > and get the max of the curve but I wasn't sure how do i go about. Pls > help
A large peak needn't have a large difference. For example, a differenced profile of Olympus Mons won't show any peaks, yet it is the mother of all peaks :-). Why not just use the max-function to get the peaks straight from the signal? Regards, Andor
"Andor" <andor.bariska@gmail.com> wrote in news:1157394379.943730.6100
@m73g2000cwd.googlegroups.com:

> A large peak needn't have a large difference.
No need to throw out all that we know about an extraordinarily well-known signal. In an ECG (at least a normal ECG), The QRS will have a large derivative compared to the rest of the waveform, but the undifferentiated QRS won't necessarily be the peak on all leads. This is not a new problem, and MANY people have done work along these lines. I'd recommend googling "QRS detection", and making use of some of the 251,000 hits. -- Scott Reverse name to reply
Hi Jen,

you have separately posted the same question in sci.math.num-
analysis. This is bad style. When you want to query the audiences of 
multiple groups, please post to all of them at once. See 
http://en.wikipedia.org/wiki/Crossposting for more information.


Martin

-- 
Quidquid latine scriptum sit, altum viditur.
Jen wrote:
> Hi everybody!! > > I am looking for a matlab code/function, that picks the highest peaks > out of a noisy signal, the signal is already baseline corrected. the > peak can be found after y=1, I thought of using diff to differentiat > and get the max of the curve but I wasn't sure how do i go about. Pls > help > > Thanks > > Jen
If you make a two (like diff function) or three point differentiator (FIR with coeffs [1,0,-1] ) you may have false detections in case the SNR of the ECG is not so high and the threshold design will became not so easier. I recommend you an approach like: http://diec.unizar.es/~laguna/personal/publicaciones/wavedet_tbme04.pdf with wavelets, or with a sintonized (at the QRS freq. 0-50 Hz approx) differentiator filter after a low pass to attenuate high freq noise
>50Hz. Then you can threshold easier the differentiated signal. An open source interesting toolbox can be freely downloaded from:
http://www.physionet.org Hope it helps. Regards, Mariano.
For the first method to be close to ideal, you need for your signal to
be grossly oversampled.  For what you use, it needs to be less grossly
oversampled.

Compare the frequency response of an ideal digital differentiator with
the response of these two alternatives.

Dirk Bell
DSP Consultant




Scott Seidman wrote:
> "dbell" <bellda2005@cox.net> wrote in news:1157388830.974655.208210 > @p79g2000cwp.googlegroups.com: > > > Beware: > > > > 'diff' does not differentiate except under very special conditions. > > Try 'help diff' to see what it does. > > > > Dirk Bell > > DSP Consultant > > > > Jen wrote: > >> Hi everybody!! > >> > >> I am looking for a matlab code/function, that picks the highest peaks > >> out of a noisy signal, the signal is already baseline corrected. the > >> peak can be found after y=1, I thought of using diff to differentiat > >> and get the max of the curve but I wasn't sure how do i go about. Pls > >> help > >> > >> Thanks > >> > >> Jen > > > > > > Dirk, > > Ya got me! Diff is the difference between adjacent elements. Except for > scaling by sample rate, I don't see how this is that much different from > a wide-open differentiation for a vector. I prefer a two point central > difference (convolution w/ [1 0 -1]*samprate/2 as opposed to convolution > with [ 1 -1]*samprate), and I generally follow the operation with an FIR > low pass, but aside from that, I don't get your point. > > -- > Scott > Reverse name to reply
I am sorry, I misread Scott's preferred implementation.  Change 'less'
to 'more' in my previous post to correct it.  Neither one is very good
unless you are grossly oversampled.

Dirk Bell
DSP Consultant

dbell wrote:
> For the first method to be close to ideal, you need for your signal to > be grossly oversampled. For what you use, it needs to be less grossly > oversampled. > > Compare the frequency response of an ideal digital differentiator with > the response of these two alternatives. > > Dirk Bell > DSP Consultant > > > > > Scott Seidman wrote: > > "dbell" <bellda2005@cox.net> wrote in news:1157388830.974655.208210 > > @p79g2000cwp.googlegroups.com: > > > > > Beware: > > > > > > 'diff' does not differentiate except under very special conditions. > > > Try 'help diff' to see what it does. > > > > > > Dirk Bell > > > DSP Consultant > > > > > > Jen wrote: > > >> Hi everybody!! > > >> > > >> I am looking for a matlab code/function, that picks the highest peaks > > >> out of a noisy signal, the signal is already baseline corrected. the > > >> peak can be found after y=1, I thought of using diff to differentiat > > >> and get the max of the curve but I wasn't sure how do i go about. Pls > > >> help > > >> > > >> Thanks > > >> > > >> Jen > > > > > > > > > > Dirk, > > > > Ya got me! Diff is the difference between adjacent elements. Except for > > scaling by sample rate, I don't see how this is that much different from > > a wide-open differentiation for a vector. I prefer a two point central > > difference (convolution w/ [1 0 -1]*samprate/2 as opposed to convolution > > with [ 1 -1]*samprate), and I generally follow the operation with an FIR > > low pass, but aside from that, I don't get your point. > > > > -- > > Scott > > Reverse name to reply