필터 지우기
필터 지우기

Count the number of "aggregate" peaks in a vector?

조회 수: 4 (최근 30일)
Shovnik Paul
Shovnik Paul 2022년 7월 23일
댓글: Star Strider 2022년 7월 24일
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.
  1. 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.
  2. 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!

채택된 답변

Star Strider
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.
.
  댓글 수: 2
Shovnik Paul
Shovnik Paul 2022년 7월 24일
Thanks, that was very helpful. I will look into this more.
Star Strider
Star Strider 2022년 7월 24일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
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.)
  댓글 수: 1
Shovnik Paul
Shovnik Paul 2022년 7월 24일
Thanks for the reply. I actualy thought of doing something like that too in order to smoothen out the spikey regions - I used a first order filter of the form 1/(1 + T*s) from the Control System Toolbox by changing T - it wasnt of much help but I am also not an expert in signal processing - I will definitely try out the functions in the link you have provided. Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by