Count the number of "aggregate" peaks in a vector?
3 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1075010/image.png)
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 个评论
采纳的回答
Star Strider
2022-7-23
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.
.
更多回答(1 个)
the cyclist
2022-7-23
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.)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!