MATLAB Human Voice Spectrum using Matlab

AI Thread Summary
The discussion centers on a user attempting to compare male and female voice spectra using Matlab but encountering errors related to the obsolete 'spectrum' function. The user receives a warning about the function being outdated and faces a plotting error due to mismatched vector lengths. The provided code attempts to compute and plot the spectrum but fails at the plotting stage. A solution is suggested, indicating that the user should modify line 6 to retrieve frequency as a second output from the 'spectrum' function. By using this frequency variable in the plot command instead of the predefined Freq array, the user can successfully generate the desired spectrum plot.
frenzal_dude
Messages
76
Reaction score
0
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 axisHope you guys can help.
frenzal
 
Physics news on Phys.org
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.
 

Similar threads

Replies
8
Views
2K
Replies
5
Views
2K
Replies
5
Views
2K
Replies
9
Views
5K
Replies
1
Views
2K
Replies
3
Views
8K
Replies
1
Views
358
Replies
4
Views
3K
Replies
12
Views
4K
Back
Top