Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Sound Analysis Matlab

  1. Jun 16, 2004 #1
    Hi,
    I need some generous person to help me! I am having problems figuring out how to analyze my recorded sounds in Matlab. I would like to plot a stem graph where my x-axis is the frequencies present in the sound and my y-axis to be the magnitude of these frequencies in dB.
    If there is some one out there with a heart of gold who could help, please do...
    Everything that I have tried has given me one or neither of what I need.

    Thanks
    Jay
     
  2. jcsd
  3. Jun 16, 2004 #2

    enigma

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    The command you want is 'fft' for "fast Fourier transform".

    It analyzes the data you give it and breaks it up into frequencies and magnitudes.

    The tricky part is formatting the data you're sending into the fft.

    I can't find the exact page I used to figure out the code (and I haven't used it for some months now, so I can't recall well enough to explain). This .pdf seems to be a decent explanation of the process. It has some simple examples.

    Give it a shot. If you're still having problems, post your code and we'll take a further look.

    Welcome to the forums!
     
  4. Jun 17, 2004 #3
    Frequencies

    Hey thank you!
    That was very helpful. One problem is that I what I need is to measure the magnitude in dB of the fundamental frequency in Hz. What I mean by frequency in Hz is something that can be translated into a musical note (ex: the note middle C = 261.626Hz). Is there a way to transfer the magnitude of the sinusoid (if I understood correctly: that is what the fft does?) into the magnitude in musical note sense?

    Thanks again.
    Jay
     
  5. Jun 17, 2004 #4

    enigma

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    If you have data of a pure sinusoid with frequency of 261.626Hz (by pure I mean computer generated with no white noise), the fft function will be a single vertical line at 261.626.

    If you add in white noise, either computer generated or from experimental error, you'll have other lines which will be orders of magnitude smaller. If you're doing an experiment, you'll probably also find that the harmonics show up as well.

    I'm not entirely certain, but I'm pretty sure that the length of the lines are the strength of the frequency in dB. If it isn't, you should be able to do a google search to find a way to code the conversion.
     
  6. Jul 5, 2004 #5

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    What you're describing is actually somewhat difficult to do. The FFT is the heart of the process, but there's a bit more to it.

    The FFT returns power values. Depending upon the FFT routine you're using, you might be getting back complex values as well. The first step, if you have complex values, is to take the modulus of each complex value. If your FFT routine already returns real values, don't worry about this step.

    Now, find the largest power value in the FFT. That's the fundamental, which you're going to label as 0 dB. You'll measure the power in the other harmonics as relative to the fundamental. Call the largest value in the FFT, say, fundamental_power.

    To get the values into decibels, first divide each value in the FFT by the power in the fundamental (fundamental_power), then take 20 times the base-10 logarithm of each.

    - Warren
     
  7. Jul 6, 2004 #6
    What your saying may solve the problem I am having, but I don't fully understand. I am new to this sort of thing. I noticed that when I record a sound in x, then run:
    F = abs(fft(x,fs));
    I get a bunch of peeks at what seems to be frequency levels. I was told that the first peek is the fundamental and all the others are harmonics. This does not always seem to be the case though. But you say that it is the peek with the highest amplitude? Are you sure?

    Does this fft return what you say is complex values? if so how do I take the modulus?

    I guess once I understand the above, perhaps I may understand what you wrote about the dB and such.

    Thanks
    Jay
     
  8. Jul 6, 2004 #7

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Since you're taking the absolute value of the fft results, you're seeing real numbers. The highest peak is the normally the fundamental -- your ear hears the loudest component the most, and that defines the basic note that's being played. Of course, if you have two peaks of nearly equal intensity, it'd be hard to say which is really the fundamental. Normally, the lowest frequency component is the fundamental.

    - Warren
     
  9. Jul 7, 2004 #8
    I just thought of something. Is the Fundamental Frequency always the intented frequecny. What I mean is if I hit the low E string on my guitar which should be analyzed at 329.63 Hz (if my sources are correct) could it be possible that the fundamental of this string is something other then 329.63 Hz.
    The reason I say this is because when I record my low E string, I find a peak at the 329.63 Hz mark but it is neither the first nor the highest peak. How can this be?

    Jay
     
  10. Jul 7, 2004 #9
    Low E

    Here is an example of my low E on a guitar after the FFT.
    here you can see what I was talking about.

    Jay
     

    Attached Files:

    • LowE.bmp
      LowE.bmp
      File size:
      16.4 KB
      Views:
      120
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Sound Analysis Matlab
  1. MATLAB histogram (Replies: 3)

Loading...