Function for getting only 30 peaks per sec of signal not working properly
Mostra commenti meno recenti
[y, fs] = audioread('tonev2018.mp3');
% resizing of signal
y = mean(y,2);
y = y - mean(y);
% resampling
new_fs = 8000;
y = resample(y,new_fs,fs);
% spectrogram
window = 0.064 * new_fs;
noverlap = 0.032 * new_fs;
nfft = window;
[S, F, T] = spectrogram(y,window,noverlap,nfft,new_fs);
S = log(abs(S));
% peak detection
gs = 9;
peaks = zeros('like', S);
for shiftx=ceil(-gs/2):ceil(gs/2)
for shifty=ceil(-gs/2):ceil(gs/2)
CS = circshift(S, [shifty shiftx]);
peaks = peaks + ((S-CS)>0);
end
end
P = peaks==max(peaks(:));
%thresholding of peaks
tpeaks = [];
for i=1:16:size(P,2)
istart = i;
iend = i+15;
if iend > size(P, 2)
iend = size(P, 2);
end
sec = P(:, istart:iend);
flatten = reshape(sec, 1, size(sec,1)*size(sec,2));
sorted = sort(flatten, 'descend');
threshold = sorted(30);
sec(sec<threshold) = 0;
tpeaks = [tpeaks, sec];
end
So my code for thresholding peaks should leave out only 30 values for each second (which is 0.064 * 16) of signal but for some reason it doesn't do anything and I get same array as P. Any insight would be much apprappreciated. Thanks in advance.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Get Started with Signal Processing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
