Matlab findpeaks

Find and report the list of peaks in a signal?

2023.01.20 19:44 Mikhail_Faustin08 Find and report the list of peaks in a signal?

say in matlab one has an x array and another called udata
to find the locations of the peaks I use
[pks, locs] = findpeaks(udata); x(locs)
How might I do this in Python? I tried
from scipy.signal import find_peaks import numpy as np
pks, locs = find_peaks(np.sqrt(np.abs(u)**2)) x[locs]
submitted by Mikhail_Faustin08 to learnpython [link] [comments]

2022.11.16 20:03 BossGandalf Peak Detection on Accelerometer Data

Peak Detection on Accelerometer Data
I need to develop a real-time algorithm on a microcontroller to perform peak/impact detection using the 3-axis accelerometer data (100Hz). I've read several posts and algorithms like this one which use z-score approach and this one I found in a research article.
Let's say I want to detect an impact on an object, but I don't know where the impact is coming from. This means that sometimes the accelerometer data is positive first on some axis and other times the accelerometer data is negative first because the impact direction is coming from the opposite direction of the accelerometer axis. In the image below this situation is represented where the first two peaks/impacts came from the same direction of the accelerometer axis X and the third peak/impacts came from the opposite direction of the axis X:
Also, sometimes the impact is align with one of the accelerometer axis so probably I should focus the algorithm on samples of just one axis, but other times the impact is align with other accelerometer axis. As you can see in the next image below the first impact has a lot more acceleration in axis X while the second impact has a lot more acceleration in axis Y. So how should I approach this problem? Run a peak-detection algorithm in both axis and see which one has more magnitude in the moment of the peak? Or should I calculate the module first and run the algorithm in the module data?
Other situation I face is that some times the result acceleration after the impact is bigger than the acceleration in the moment of the impact and I need to detect the peak in the moment of the impact and in this situations the first peak has less magnitude than the second one. I tried to solve this using a LPF first as you can see in the image below:
Any sugestions?
  1. Should I use an LPF to smooth the time-series acceleration data upon impact and apply the peak detection algorithm to the filtered data?
  2. Should I use an HPF to accentuate the peaks on the time-series acceleration data and then run the algorithm for the filtered data?
  3. Should I apply the algorithm to just the X-axis or the Y-axis, both at the same time, or calculate the modulus of acceleration and run the algorithm on the modulus?
  4. I've read about adaptive algorithms where the threshold can increase or decrease based on the last few samples. Can this approach help me ensure that only the first spike is detected, as the threshold will increase and likely allow subsequent spikes in the object's acceleration to go undetected?
  5. What approach I should use to detect the first peak (positive or negative)?
Note that I want to implement this real-time as I keep reading the samples periodically every 10ms. So post-processing techniques using built-in functions like findpeaks() in matlab or python are not what I'm looking for.
submitted by BossGandalf to DSP [link] [comments]

2022.11.16 18:00 BossGandalf Good books, online courses or other source of knowledge with focus on REAL TIME DSP?

I have an EE degree and during my course in the Digital Signal Processing class we learned about sample rate, anti-aliasing, FIR and IIR Filters, Fourier Transform and so on... but all hands-on and lab classes were implemented using python or matlab and built-in functions where we change only the input arguments like thresholds, orders of filters... But running a DSP algorithm like a digital filter or a peak detection algorithm using built-in functions like findpeaks() in matlab is completely different from implementing algorithms in REAL-TIME on microcontrollers for example, where memory is a constraint and we have to run the algorithm almost at the same time we keep getting new samples.
Quick example: let's say we want to calculate a heart rate from an ECG signal. Save the samples and run the post processing using matlab or python where we can use built in functions to denoise and find peaks is completely different If I want to create a realtime heart rate measurement where my microcontrollers are continuously receiving samples and I need to run filtering algorithms and real-time peak detection algorithms.
So the big question is: where can I learn more about REAL-TIME DSP and all the things we have to take into account like data structures, buffers...
submitted by BossGandalf to DSP [link] [comments]

2022.03.28 09:01 potatoiko findpeaks function?

I'm making an app using Flutter that will count the number of peaks from a set of accelerometer data. I don't need the plot to be shown to the end user, just the final counted number. The data analysis team in my senior design group has developed a simple few lines of MatLAB code that essentially runs the data points through a buttersworth filter and then uses MatLAB's findpeaks function to return the count, which is cool, but difficult if not impossible to translate to Flutter. I recognize that Flutter is more for UI than data analysis, and I've found a Flutter package that will allow me to use Python and all its libraries. The only problem is that the package doesn't support the Matplotlib library, which is necessary for doing the above analyses. If anyone has any other workarounds that could be relatively easy to implement (I have a very short deadline), I would be incredibly grateful. Thanks!
submitted by potatoiko to learnprogramming [link] [comments]

2021.07.20 10:08 bak_one How to stretch out smaller vector to the size of larger vector?

I have a noisy ecg signal with the length of 1x5000. Using empirical mode decomposition (not allowed to use the function emd()) i want to decompose the signal and later remove its baseline wander. First i find all the extrema from the ECG and then calculate the average from max and min values.
Up=findpeaks(ecg); Low=findpeaks(-ecg); Low=-Low; Aver=(Up+Low)/2;
Now i have to subtract the ECG signal with that average array (Aver). Problem is they have different length (1x2778). I tried to stretch the average signal using interp1, but the function seems to shift the position of the peaks from its original, thus the result from subtraction not as clean as when i use the function emd() as comparison. I want to stretch the aver signal to have 5000 data points, while hold the position of the found peaks in the same position as the original ecg signal (i hope this make sense). I am new to Matlab and wondering if anyone can help me with this.
submitted by bak_one to matlab [link] [comments]

2020.10.20 09:52 Manasmw333 Calculating the time period of a signal

I want to calculate the time period of a signal x = sin(8*pi*t) for example. Theoretically, we do that by comparing with sin(2pi*fc*t) but I want to display this in MATLAB.
I referred to some forums that used findpeaks() but the results are not satisfactory. Please help me with the MATLAB code
submitted by Manasmw333 to matlab [link] [comments]

2020.08.27 15:31 rfltips Find peaks algorithm giving incorrect peak values

I'm writing my own find peaks algorithm, because it needs to go into an .exe file and MATLAB won't support the findpeaks from signal processing in an .exe file (sucks I know).
So in my code it identifies peaks location (to a decent degree of accuracy) and then when I come to take the values using the indexes previously calculated, it works for the first few but after the first "difficult" one (I think this is typically a complicated peak), it then correctly identifies the locations, but the peak value is incorrect.
Moving on a few peaks further the values there seem to be what they should've been previously.
I can attach code if needs be, but it's not the shortest, hence why I haven't done it initially.
submitted by rfltips to matlab [link] [comments]

2020.04.01 18:36 borisak2 How to segment and subplot signal peaks

Hello, I want to segment the following peaks and plot them into subplots with respect to the original time. Could you propose me some viable solution?
dataFull = xlsread('E:\Škola\DP\mereni\test_MATLAB.xlsx','test_MATLAB'); %load file time = dataFull(:,1); %set time variable data = dataFull(:,2); %set y variable [pos_pks,pos_loc] = findpeaks(data,time,'MinPeakDistance',2,'MinPeakHeight',20); %find signal maxima and save its position (pos_loc) and amplitude (pos_pks) [neg_pks,neg_loc] = findpeaks(-data,time,'MinPeakDistance',2,'MinPeakHeight',5); %find signal minima and save its position (neg_loc) and amplitude (neg_pks) figure(1) plot(time, data, '-b') %plot original signal hold on plot(pos_loc, pos_pks, '^r') %plot peaks plot(neg_loc, -neg_pks, 'vg') %plot valleys hold off grid legend('Data', 'Peaks', 'Valleys') 
the data file is attached right here:
submitted by borisak2 to matlab [link] [comments]

2019.08.18 17:50 earthcakey Issues with cumtrapz + cwt for acceleration data

Issues with cumtrapz + cwt for acceleration data
Hi everyone! I'm currently trying to follow the pseudocode in this paper here:
The steps I'm trying to follow are:
  • (i) Numerical integration of the raw vertical acceleration (av) with the function cumtrapz
  • (ii) Differentiation of the integrated signal with the cwt function (Wavelet ToolboxTM Matlab┬«) resulting in signal S1, Figure 2b
  • (iii) Find S1 local minima times, which equate to IC, through the use of the findpeaks function, Figure 2b
  • (iv) Differentiate signal S1 with cwt function to get signal S2,
  • (v) Find local maxima (FC) times of signal S2 by using findpeaks, Figure 2b
So I have acceleration data from a person walking, and I'm trying to find the initial foot-to-ground contact time and final foot-from-ground contact time.
After I pass the data through the cumtrapz function, I get the below result:
right side is raw vertical acceleration, left side is plotted cumtrapz result
This doesn't make any sense, right? Technically the result of the integration should actually be velocity, which wouldn't be a straight line.
Furthermore, when I pass my data through cwt to differentiate the signal, I end up with something like this:
And the matrix itself has 860 columns.
Any ideas on what I might be possibly doing wrong?

Thanks so much in advance! (I'm a total beginner with this stuff btw lol)
submitted by earthcakey to matlab [link] [comments]

2019.06.20 02:55 urwelcome971620 How come findpeaks() is giving me the error: Error in findpeaks (line 136) = parse_inputs(isInMATLAB,Yin,varargin{:}); I want to get the first peak of an envelope I made...

%%This fucntion will graph waveforms and their hilbert transform from one
%%waveform .csv file
%%must add labeling for first peak and this function needs an input

function g = graphData(file)

newStr = extractBetween(file,"_","_"); %get transducer name

table = readtable(file); %read the data into a table

xr = table2array(table); %convert the table into an array(matrix)
x = xr(:,1);
y = xr(:,2);

[up,lo] = envelope(y); %attain the hilbert envelope fo the amplitude
Y = [up,lo];

% M = find([up,lo] == max(m)); %find the max amplitude of the hilbert transform envelope

[pks,locs] = findpeaks(Y);

g = plot( x,y, x, up,'-p','MarkerIndices',...
'MarkerSize',10 ); %plot time vs. amplitude vs. hilbert and mark max amplitude of hilbert
xlabel('Time (seconds)');
title("Peak in Hilbert Transform of Signal");
legend("Transducer" + " " + newStr);

submitted by urwelcome971620 to matlab [link] [comments]

2016.09.29 17:37 EngineeringPrincess How do I get a plot from Teensy LC to Matlab in numeric form?

I am trying to analyze data from Teensy LC to matlab. arduino=serial('COM4','BaudRate',38400);
for i=1:length(x) y(i)=fscanf(arduino,'%d'); end
fclose(arduino); disp('making plot..') data = plot(x,y); pks = findpeaks(data)
That is my code and I findpeaks is giving me the error that my y axis is not in numeric form. How do I fix this?
submitted by EngineeringPrincess to AskEngineers [link] [comments]