Trying to understand the MATLAB fft example and how to determine amplitudes of frequencies?

Hey
I have made a plot of a signal using the MATLAB fft example:
L=length(channel1);
NFFT=2^nextpow2(L);
Y=fft(channel1,NFFT)/L;
f=fs/2*linspace(0,1,NFFT/2+1);
figure(3)
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Amplitude spectrum')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
Questions:
1. I don't understand the values of Y: Why is it necessary to expand the vector to the length of the NFFT? And why divide by L?
2. In determining the frequency axis. The code generates a vector with length 32769, but the frequencies only goes to the nyquist frequency: fs/2=22050. Some of the frequencies are represented more than once along the frequency axis, why is that?
3. As far as I understand. The Amplitude of a frequency determines how loud the sound of the frequency is heard in the signal. Is it possible to get the amplitudes of the 10 most significant frequencies from this plot?

 Réponse acceptée

  1. It's not mandatory but FFT is fastest for powers of 2. That used to be much more of a significant issue than now w/ the advent of much faster processors, but the "tradition" lives on...but, since you used the example which does compute the next power of 2 and augments the signal to that length, then that's the length being used and hence the normalization.
  2. The TMW Matlab implementation of fft returns the two-sided fft with the DC component in the middle; negative frequencies to the left, positive to the right (+ indices offset) from that point. Here again, it's just convention as to which to use; the 2-sided is more general.
  3. Use findpeaks

11 commentaires

Undoubtedly showing my age, :) my favorite text for all you need to know and more is Brigham, O. A., The Fast Fourier Transform and Its Applications, Prentice-Hall.
Thank you very much! I am still not to clear on though what the normalisation does? It takes every value of the fft(channel1) and divides by L. Why is this necessary? I have read a lot of books now, and search the internet but I can't find the answer to this problem. I must be overlooking something:-( Does it come from a certain theorem?
Also, maybe you can clarify...When I don't normalise, and just plot the absolute values of the fft(). What am I getting then? As far as I have understood I am getting the "Magnitude" in watt/hz. Is this correct?
dpb
dpb le 17 Août 2015
Modifié(e) : dpb le 17 Août 2015
Look at the example -- the magnitude there of the two peaks for a 0.7 and 1.0 magnitude sine with zero-mean noise turn out to be (roughly, owing to noise) 0.7 and 1. The units presumed were V for the signal and so if you weren't to have normalized by the length of the FFT, the output amplitudes would have been L*V.
The units depend on the units of the input, to get power you must convert whatever it is the input is appropriately.
I am sorry, but I don't quite understand. My data is a sampling of an audio signal, with sampling rate 44100 Hz pr. second. Taking the fft() on my data. What type of Units do I have?
Probably mV; I really don't know for certain whether there's an arbitrary scaling of standard audio formats or whether they're recorded as absolute voltages; I'd presume they're like some scaled voltage representation but I've never investigated...
But "power" for audio is measured in a lot of differing manners depending on what one is interested in, not to mention the complexity if one is interested in actual sound levels as perceived by the ear.
Ok, thank you. You are very helpful:-) I just had another look at the example. And I just thought, couldn't it also be, that the division with length L comes from the equations stated at the beginning of the example? As I understand, the example is trying to reconstruct the amplitudes of the individual frequencies in the signal, and thus using the equation for the signal x(j). Where each fft component X(k) is divided by N. Or am I misinterpreting the information?
Walter Roberson
Walter Roberson le 19 Août 2015
Modifié(e) : dpb le 19 Août 2015
What you get back from reading audio files is always scaled to -1<=x<1 unless you specify the 'native' option for reading, in which case you get whatever value was actually stored. The value actually stored will typically have been scaled already (and possibly recentered as well.) I discussed this in your previous Question http://uk.mathworks.com/matlabcentral/answers/233474#comment_304051
For microphone readings to have any meaning you need to calibrate the entire system. You need to read up on Sound Pressure Level (SPL) and related factors. See https://www.mathworks.com/matlabcentral/newsreader/view_thread/278831 for example.
I kinda' figured that was so but hadn't ever looked specifically, Walter. BTW, I respaced your bracketing expression to fixup the RTF screwed-up interpretation of '<' as the opening of another URL. Ended up having to take out the spaces to get it to render properly.
"...couldn't it also be, that the division with length L comes from the equations stated at the beginning of the example?"
Of course, the normalization is based on the particular definition of the FFT implemented; there are various implementations that may or may not compensate internally but if you want output that represents the magnitude of the input in the same scale it's got to get normalized at some point. Again I refer you to Brigham or some other text on digital signal processing (altho I understand there are competent tutorials available on the web now, I'm of an age preceding that circumstance so I don't know of any in particular to recommend, sorry).

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by