plot fails with -Inf
16 ビュー (過去 30 日間)
I need to plot a fft of an audio file. It appears that if any of the fft bins are zero, the conversion to dB produces an -Inf. Then the plot function does draw the figure but does not plot any data.
Is there an efficent way to trap the 0 value bins in the conversion to dB? For my work -Inf PSD would be equiv to zero.
The test audio file was a code generated audio file, 100Hz Sine for 10 seconds. Since only one fft bin will have a value, all the other bins are zero.
[yS, Fs] = audioread(PathFN,'double');
L = length(yS);
Y = fft(yS,L);
% Version One
Px = Y.*conj(Y); % PSD Power of each freq components
Px = Px(1:L/2);
Px = 10*log10(Px); % Convert to dB
fVals = Fs * (0:(L/2)-1)/L;
plot(fVals, Px); % Plot