Matlab sound Analysis
Reply #8 – 2004-06-18 15:29:45
Thanks for your reply, I'll try what you suggest. Time is not important (if I must give one up for the other), but I would like to know the amplitude of each frequency(even if it is just by comparing it to the other frequencies present in the sound.). How can this be done? Just use an FFT, or one of the routines you've already been pointed to. You know you can look at the source code for most MATLAB functions, and see exactly what they're doing? That should help. If not, see below...Also, why is it that one cannot be accurate in both freq. and time? I already answered that because in a very short time, you simply don't have enough information on frequency. At the extreme, in a single sample, you don't have any frequency information at all.And when you say that freq. and loudness is logarithmic and Matlab plots are not: Do you mean that I would have to scale the plots logarithmically and not use the default setting? IME (with an _old_ version of MATLAB) you can't plot spectrograms with a log frequency scale in MATLAB automatically. log amplitude is easy though - just 20*log10 the data. It's not essential, but it might help you to see what's in the audio file. If you have your mono audio in an array called my_tone, then try this:window_length=4096; freq_my_tone=fft(my_tone(1:window_length).*hanning(window_length)); frequency_scale=(1:window_length/2)*fs/window_length; semilogx(frequency_scale,20*log10(abs(freq_my_tone(1:window_length/2)))) axis([20 20000 -20 80]) xlabel('frequency / Hz') ylabel('amplitude / dB') (for stereo audio, just select one channel in the second line, replacing my_tone(1:window_length) with my_tone(1,1:window_length) or mytone(1:window_length,1) depending on which way you've loaded data into the array). The one thing that's missing from this is any calibration of the amplitude scale. For a given window length and window function, you have to take a full scale sine wave (I use +/-1 range with MATLAB, as do the built-in wav functions), pass it through the above function, note the peak amplitude, and then subtract this from all subsequent plots to get figures relative to 0dB FS. This correction factor will change if you change the window function or window length. You'll have to change the axis statement as appropriate. Hope this helps. Cheers, David.