Count the number of "aggregate" peaks in a vector?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shovnik Paul
el 23 de Jul. de 2022
Comentada: Star Strider
el 24 de Jul. de 2022
I have some data in a vector in matlab called voltage collected from a sound sensor. When plotted against a time vector containing every instant of time these values were recorded at, I get the figure below:
As you can see, the data is "spikey" but there are some "spikes" that clearly larger and more noticesable than the surrounding - here I can count 10 of them. The sensor recorded sounds from a nearby buzzer - when the buzzer was silent, the voltage stayed at (around) the midway level (2.5V) but when it buzzed, it jumped to 5V, then to 0V and back, resulting in these larger spikes. This means that the buzzer beeped 10 times.
I want to count the number of these larger spikes which will tell me the number of times, the buzzer beeped.
- My first thought was to set some arbitrary threshold like 5V and do a linear search of the voltage vector to check how many samples reached 5V but there were many samples within the same peak that did this - so that would be overcounting.
- I also tried using the findpeaks functions which unfortunately also counts local maxima and returned many false positives even in the noisy regions around 2.5V where the buzzer is supposed to be silent.
Is there any good way to go about this? I am struggling to figure out what mathematical approach to take to analyse this. I have attached the .mat file containing the voltage and time vectors. Any help is appreciated. Thanks!
0 comentarios
Respuesta aceptada
Star Strider
el 23 de Jul. de 2022
I am not certain what result you want.
Here, findpeaks finds 21 distinct spikes (and their locations)
LD = load('buzzerData.mat');
time = LD.time;
voltage = LD.voltage;
[pks,locs] = findpeaks(voltage, 'MinPeakProminence',4.5);
mdl = mean(diff(locs));
figure
plot(time, voltage)
hold on
plot(time(locs), pks, '^r')
hold off
xlabel('time')
ylabel('voltage')
ylim([-1 6])
figure
histogram(diff(locs), 50)
The histogram is optional, and simply looks at how the differences in the ‘locs’ values are clustered.
The ‘time’ vector has irregular sampling intervals, so it will not be possible to do any sort of signal processing on these data as they currently exist. One way to deal with that is to use the resample funciton, however this results in strange ‘voltage’ values. However if you want to use it, one approach would be:
Fs = 1/mean(diff(time));
[voltagers,timers] = resample(voltage,time,Fs);
The approximate sampling frequency (calcualted from the mean of the differences in the ‘time’ vector) is about 83.9925 Hz (assuming the ‘time’ units are seconds).
This works in R2022a, and should procduce reliable results in R2018a.
.
2 comentarios
Más respuestas (1)
the cyclist
el 23 de Jul. de 2022
I am absolutely positively NOT an expert in this, but I think what might be helpful here is putting your signal through a low-pass filter. (You need the Signal Processing Toolbox for that.)
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!