문제

I'm trying to display a spectrum of a sound sample with the correct frequency-axis, in Hertz, and a log-amplitude y-axis. I thought I had the frequency display right, but the graphs that it produces look rather weird and I've found absolutely nothing regarding displaying the log amplitude on an axis.

The code that I'm using (heavily borrowed from mathsworks fft example) is:

y=x(100:200);
Fs = 10000;                    % Sampling frequency                     
numsamples = 20000;                     % Number of samples in the signal             
NFFT = 2^nextpow2(numsamples); % Next power of 2 from length of y
Y = fft(y,NFFT)/numsamples;
f = Fs/2*linspace(0,1,NFFT/2+1);

plot(f,2*abs(Y(1:NFFT/2+1))) 

And here's one of the graphs that it produced: speech graph

I don't know if that's right or not, but it doesn't look anything like the examples I've seen....

I'm aware this is probably a really stupid question and I'm missing something obvious, or maybe I've actually got it right and don't understand enough to realise it, but this stuff is really doing my head in and I'm not finding the documentation particularly illuminating.

도움이 되었습니까?

해결책

I think the x-axis is correct.

To obtain a logarithmic y-axis replace the plot bysemilogy:

semilogy(f,2*abs(Y(1:NFFT/2+1)))

or equivalently use plot as it stands followed by

set(gca,'YScale','log')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top