Dimension error using findpeaks() on Power Spectral Density

1 visualizzazione (ultimi 30 giorni)
I have a set of audio files for which I would like to determine a SNR metric. I tried to implement as follows:
% Calculate the FFT and PSD of each of the signals in the signal vector.
afftvectors = {};
hfftvectors = {};
psdvectors = {};
halffreqvectors = {};
powdbvectors = {};
signalpeaks = {};
signalpeaklocs = {};
noisepsd = {};
for k = 1:numel(signalvectors)
afy = abs(fft(signalvectors{k}));
afftvectors{k} = afy;
% Due to the symmetric nature of FFT, only half the spectrum is actually required.
hfy = afy(1:length(afy)/2+1);
hfftvectors{k} = hfy;
py = (1/(freqarray{k} * length(signalvectors{k}))) * abs(hfftvectors{k}).^2;
% since we take only half of the spectrum, we can conserve the energy by multiplying
% by 2. Zero frequency (DC) (index 1) and the Nyquist frequency (last index, i.e, end)
% do not occur twice so, we'll skip the multiplication operation on them.
py(2:end-1) = 2 * py(2:end-1);
psdvectors{k} = py;
halffreqvectors{k} = 0:freqarray{k}/length(signalvectors{k}):freqarray{k}/2;
powdbvectors{k} = 10 * log10(psdvectors{k});
% Find peaks
[signalpeaks{k},signalpeaklocs{k}] = findpeaks(psdvectors{k});
noisepsd{k} = psdvectors{k} - signalpeaks{k};
end
So, the idea was to get the peaks of Power Spectral Density vector. I hit a dead end when I got the output where 'signalpeaks{1}' is a vector of size 13235x1 but my 'psdvectors{1}' itself is a vector of size 36001x1. All the elements in cell array 'signalvectors' has a sample size of 72000. What exactly is going wrong here? Am I using the wrong function in findpeaks() or something else needs to be done?
  5 Commenti
skrowten_hermit
skrowten_hermit il 13 Ott 2020
Modificato: skrowten_hermit il 13 Ott 2020
Correct. But they are not the same size here. That is because signalpeaks has more peaks than the data points (here, the frequency) itself. Is that possible?

Accedi per commentare.

Risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by