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

Human Voice Spectrum using Matlab

  1. May 9, 2010 #1
    Hi, I'm trying to compare the spectrum of male and female voices using Matlab.
    I'm using this code but I get this error:
    ---------------------------------
    Warning: SPECTRUM is obsolete and will be removed in future versions.
    Use the spectrum objects instead, type "help SPECTRUM".
    > In spectrum at 106
    In fft at 6
    ??? Error using ==> plot
    Vectors must be the same lengths.

    Error in ==> fft at 14
    plot(Freq,10*log10(Y/max(Y)));
    ------------------------------
    I heard that even though 'spectrum' is obsolete it should still work ok.
    But I'm not sure how to plot the frequency domain using plot(Freq,10*log10(Y/max(Y))); even though they are different lengths, (which I assume they should be since my lecturer gave me this code).

    Here's the .m file:

    1. % Record sound and do spectrum analysis
    2. Fs=8000; %sample rate used is 8kHz
    3. N=Fs * 10; %the total number of samples in 10 secs of data
    4. FFTsize=1024;
    5. y=wavrecord(N,Fs); %collect your data
    6. Y=spectrum(y,FFTsize); %compute the spectrum of your data
    7. Freq=[10:Fs/FFTsize:Fs/2]; %frequency scale
    8. Time=[1:N]/Fs;
    9. subplot(2,1,1);
    10. plot(Time,y);
    11. ylabel('Amplitude'); %label the y axis
    12. xlabel('Time(s)') %label the x axis
    13. subplot(2,1,2);
    14. plot(Freq,10*log10(Y/max(Y)));
    15. ylabel('Spectrum(db)');
    16. xlabel('Frequency(Hz)'); %label your x axis


    Hope you guys can help.
    frenzal
     
  2. jcsd
  3. May 17, 2010 #2
    In line 6, you have to get frequency as second output like this,
    [Y, freq]=spectrum(y,FFTsize)
    Now in line 14, if you plot this freq instead of Freq you will get the desired spectrum.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Human Voice Spectrum using Matlab
  1. Thevenin using MATLAB (Replies: 1)

Loading...