Peak detection using MATLAB (signal processing)

In summary: one can use the peak(x) function to get the amplitude, the peak(x,y) function to get the coordinates of the peak, and the diff(x,y) function to get the difference in amplitude between the two peaks.
  • #1
kay310
8
0
I'm doing signal processing using MATLAB.

But facing problem when doing Peak Detection.


This is the signal that I used for the processing:
sample1.jpg



This is what i wish to do:
a) the horizontal line is the threshold point and
b) the circle is the peak detection
sample.jpg



Can anyone help me in this?
1) set a threshold point for the signal
2) detect the peak
 
Physics news on Phys.org
  • #2
ECG?

If x is your signal, you get logical indices for which x is above the threshold simply by
x > threshold;
Eg, x = [1 3 1 4],
x > 2 returns [0 1 0 1], (and x(x > 2) returns [3 4]).

What you should consider is that there might be a couple of successive samples above the threshold. If this is the case, I'd probably do something along the lines of x > threshold, diff, and find the positive values (if for some reason the maximum value above the threshold is important, you'd have to max as well).

I think this came out a bit convoluted, but I tried avoiding completely solving the problem for you.
 
  • #3
I'm actually can't really understand what you means.
Would you mind to explain more to me?
 
  • #4
Well, if x is your ECG, (or whatever signal),
you can threshold with
x > threshold;
Now, this is a vector with zeros and ones.
At ones, the signal is above the threshold.
Do e.g.
ind = x > threshold;
plot(1:length(x), x, find(ind), x(ind), 'o')

This will probably be rather close to the desired output, but if there are successive values of x above the threshold, this won't come out right. You would have to determine the maximum of these successive values. I'd use the diff-command to differentiate as that ought to be quite simple to implement, but you may have other preferences.
 
  • #5
Thanks for help.
But,
what is the 'successive values' means?
 
  • #6
By successive I meant that two values of the signal in a row exceed the threshold value.

E.g.
x = [1 1 1 1 3 4 1 1 1 1], if the threshold is 2, the algorithm is going to tell you there are two peaks, where in reality there is only one.
 
  • #7
oh I get it already.
Thanks for your help. Thanks so much.
 
  • #8
i need MATLAB program of peakdetect program pl help me
 
  • #9
If I have successive values, how should I go about doing that?
 
  • #10
hey i also need some help regarding ecg signal..i need to make an algorithm in MATLAB to find values of r-peaks...so that if i want to have a value of any r-peak i can get it from this algorithm like pan-tomkins algorithm in matlab.can anyone help for it?
 
  • #12
Päällikkö said:
By successive I meant that two values of the signal in a row exceed the threshold value.

E.g.
x = [1 1 1 1 3 4 1 1 1 1], if the threshold is 2, the algorithm is going to tell you there are two peaks, where in reality there is only one.

Hi, I'm also facing same problem, I'm doing a heart signal peak detection project and i attached the plot result , can u tell me how i solve this ?

Thanks
 

Attachments

  • untitled.jpg
    untitled.jpg
    12.9 KB · Views: 1,337
  • #13
satinysol said:
Hi, I'm also facing same problem, I'm doing a heart signal peak detection project and i attached the plot result , can u tell me how i solve this ?

Thanks

Given the above example: x = [1 1 1 1 3 4 1 1 1 1]

peakfinder (http://www.mathworks.com/matlabcentral/fileexchange/25500) gives you the following:

[peak loc] = findpeaks(x)

peak = 4 <-- the amplitude of the peak is 4
loc = 6 <-- the location of the peak is 6

there are also lots of other useful functions included in the package.
 
  • #14
alletsefinn said:
Given the above example: x = [1 1 1 1 3 4 1 1 1 1]

peakfinder (http://www.mathworks.com/matlabcentral/fileexchange/25500) gives you the following:

[peak loc] = findpeaks(x)

peak = 4 <-- the amplitude of the peak is 4
loc = 6 <-- the location of the peak is 6

there are also lots of other useful functions included in the package.

Can tell me how to proceed this code? I'm really new for this ,thanks
 
  • #15
satinysol said:
Can tell me how to proceed this code? I'm really new for this ,thanks

Setting up peakfinder
1. download the peakfinder package from the link above. extract/unzip the folder and put it in a folder under your MATLAB path
2. in matlab, add the peakfinder folder to path (file -> set path, click on set path, select the peakfinder folder by browsing, click on save, then click on close)

Using peak finder
assuming your signal is already in the MATLAB workspace called x, to find the peaks using peakfinder, type in the following in the MATLAB command window:

[peaks, locs] = findpeaks(x)

this would result in two vectors:

peaks = [# # # # # ... ] <-- indicates all the peaks that are found in x
locs = [# # # # # ...] <-- indicates all the locations/positions of the found peaks

to examine the peaks found using this setting, you can type in the following:

plot(x);
hold on;
plot(locs,peaks,'o','MarkerEdgeColor','r')

more functions/setting can be consulted through typing 'help peakfinder' in the MATLAB command window. hope this helps.
 
  • #16
alletsefinn said:
Setting up peakfinder
1. download the peakfinder package from the link above. extract/unzip the folder and put it in a folder under your MATLAB path
2. in matlab, add the peakfinder folder to path (file -> set path, click on set path, select the peakfinder folder by browsing, click on save, then click on close)

Using peak finder
assuming your signal is already in the MATLAB workspace called x, to find the peaks using peakfinder, type in the following in the MATLAB command window:

[peaks, locs] = findpeaks(x)

this would result in two vectors:

peaks = [# # # # # ... ] <-- indicates all the peaks that are found in x
locs = [# # # # # ...] <-- indicates all the locations/positions of the found peaks

to examine the peaks found using this setting, you can type in the following:

plot(x);
hold on;
plot(locs,peaks,'o','MarkerEdgeColor','r')

more functions/setting can be consulted through typing 'help peakfinder' in the MATLAB command window. hope this helps.

This is very helpful ,thank you so much ^^
 
  • #17
alletsefinn said:
Setting up peakfinder
1. download the peakfinder package from the link above. extract/unzip the folder and put it in a folder under your MATLAB path
2. in matlab, add the peakfinder folder to path (file -> set path, click on set path, select the peakfinder folder by browsing, click on save, then click on close)

Using peak finder
assuming your signal is already in the MATLAB workspace called x, to find the peaks using peakfinder, type in the following in the MATLAB command window:

[peaks, locs] = findpeaks(x)

this would result in two vectors:

peaks = [# # # # # ... ] <-- indicates all the peaks that are found in x
locs = [# # # # # ...] <-- indicates all the locations/positions of the found peaks

to examine the peaks found using this setting, you can type in the following:

plot(x);
hold on;
plot(locs,peaks,'o','MarkerEdgeColor','r')

more functions/setting can be consulted through typing 'help peakfinder' in the MATLAB command window. hope this helps.

I'm not sure if i should leave this message here,but I'm doing it, here's my problem,like u said i tried with the code ,it was very nice and very useful,it doing well when i input the data under 1200sampling frequency,but when i tried other data under different sampling frequency the result was not satisfactory, here i attached something related to my issue
 

Attachments

  • result under 256sampling frequency.jpg
    result under 256sampling frequency.jpg
    19.7 KB · Views: 1,407

What is Peak Detection in Signal Processing?

Peak detection in signal processing refers to the process of identifying and locating the local maxima or peaks within a given signal or data series. These peaks represent significant points in the signal, often indicating the presence of important features or events.

How Can I Perform Peak Detection in MATLAB?

Peak detection in MATLAB can be accomplished using various methods and functions. Here's a general approach:

1. Load or Generate Your Signal:

Start by loading your signal data into MATLAB or generating a synthetic signal using appropriate commands.

2. Smoothing (Optional):

Depending on your signal, you may want to apply a smoothing filter to reduce noise and make the peaks more distinguishable.

3. Find Local Maxima:

Use MATLAB functions like findpeaks or peaks to identify local maxima in your signal. These functions typically allow you to specify parameters such as peak prominence, height, or width to fine-tune the detection process.

4. Plot the Detected Peaks:

Plot the original signal and mark the detected peaks to visualize the results. You can use plot and scatter functions for this purpose.

Are There Specific MATLAB Functions for Peak Detection?

Yes, MATLAB provides built-in functions for peak detection. Two commonly used functions are:

findpeaks:

The findpeaks function locates local maxima in a signal and returns their indices and values. It allows you to specify parameters like peak height, prominence, and distance between peaks for more precise detection.

peaks:

The peaks function generates synthetic data with predefined peaks, which can be useful for testing and practicing peak detection algorithms.

What Applications Use Peak Detection in Signal Processing?

Peak detection is widely used in various applications, including but not limited to:

1. Spectral Analysis:

In spectral analysis, peak detection is used to identify and analyze spectral lines in signals, such as those in audio, speech, and vibration data.

2. Chromatography:

In analytical chemistry, peak detection is crucial for identifying compounds in chromatograms, where each peak represents a different chemical component.

3. Medical Imaging:

In medical imaging, peak detection helps identify features in images, such as identifying the location of blood vessels or the peaks of ECG or EEG signals.

4. Environmental Monitoring:

Peak detection is used in environmental monitoring to identify events such as pollution spikes or seismic activity.

5. Financial Analysis:

Financial analysts use peak detection to identify significant price fluctuations or trading patterns in stock market data.

Can Peak Detection Be Customized for Specific Applications?

Yes, peak detection algorithms can often be customized to suit specific application requirements. MATLAB provides flexibility in adjusting parameters like peak height, prominence, and distance between peaks to tailor the detection process to your needs. Additionally, you can develop custom algorithms if the built-in functions do not meet your specific requirements.

Where Can I Find Additional Resources for Peak Detection in MATLAB?

You can find additional resources and documentation on peak detection in MATLAB on the official MATLAB website, user forums, and online tutorials. MATLAB also provides detailed documentation for functions like findpeaks and peaks, which can help you get started with peak detection in your signal processing tasks.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
985
  • Engineering and Comp Sci Homework Help
Replies
7
Views
871
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Electrical Engineering
2
Replies
48
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
721
  • Biology and Chemistry Homework Help
Replies
17
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Atomic and Condensed Matter
Replies
5
Views
2K
Back
Top