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

Sound Processing in Matlab: I need help

  1. Sep 30, 2004 #1
    I need help in extracting the fundamental frequency from a recorded wav file. The input is an A-chord from the guitar sampled at 44100 Hz using mono.

    my source code is as follows. The variable framed is components of the signal required to be processed. So if the waveform of chord A starts at time 1.2 seconds and starts to dissipate at 3.4 seconds, framed would be the signal components from 1.2 until approximately 2.5 seconds.

    y = fft(framed);
    m = abs(y); % absolute value to eliminate the imaginary components
    blocksize = 8000;

    % Avoid taking the log of 0.
    index = find(m == 0);
    xfft(index) = 1e-17;

    mag = 20*log(m); % take the magnitude of the fft in dB
    mag = mag(1:floor(blocksize/2));
    f = (0:length(mag)-1)*Fs/blocksize;
    f = f(:);

    % Now create a frequency vector for the x-axis and plot the magnitude and phase.
    %f = (0:length(framed)-1)'*100/length(framed);
    ylabel('Abs. Magnitude'), grid on
    xlabel('Frequency [Hertz]')
    [ymax,maxindex]= max(mag); % takes the max values

    When running this program, the desired output waveform does not show the frequency of chord A (440 Hz) but rather something else. Please help me! Our thesis doesnt seem to be progressing anymore because of this minor but irritable problem. If anyone can please help me on this. Thanks!



  2. jcsd
  3. Sep 30, 2004 #2

    Or an alternative method would be a simpler way in extracting the fundamental frequency from a sound file... my syntax doesn't seem to give me the desired results...
  4. Oct 1, 2004 #3

    You can't dilucidate the fundamental frequency by selecting the peak frequency as you are doing.
    Moreover when you have a chord with several fundamental frequency mixed

    (you have not a self coherent signal)
    but a signal composed by three fundamental (temperated and therefore
    non congruent) frequencies

    good luck , Im afraid that the process you wish to program is somewhat more complex.
  5. Oct 4, 2004 #4
    we were able to display the right frequencies already. but now its just a matter of determining the right chord after recognizing the many harmonics present in one chord... do u think i can teach the program to recognize a series of harmonics that would yield the right chord? Like the D chord has D3, A3, D4, F#4,A4, D5 and F#5... if i teach the program to learn this progression it could possibly detect the correct chord... is this a good approach or does it involve a bit more than simpy looking for a chord's harmonics?
  6. Oct 7, 2004 #5
    The temperated grid in which you try to locate the armonics of the notes that make up the chord are too coarse to reflect the armonc composition of the notes (due to the fact that armonics are growing lineary and temperated notes are growing logaritmically)
    I think the problem you are trying to solve are quite more complex and you'd better do trying some autoscalar logaritmic transformation as wavelet o something similar.
    Anyway, you could use (linear) Fourier transform but then you'd need to solve a difficult coherence problem ( that is extracting the Maximun Common Divisor of all the significant frecuencies in the signal) but this is more easy to say that to solve because if you have some noise in each frequency, you'll end up saying that the fundamental frecuency is the lower in the system; that ist the inverse of the duration of the sample.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Sound Processing in Matlab: I need help
  1. I need help in Matlab (Replies: 0)