File Exchange

image thumbnail

Sound Analysis with Matlab

version (327 KB) by Hristo Zhivomirov
Time and frequency analysis, signal statistics, etc. of a sound signal.


Updated 28 Jun 2020

View Version History

View License

The present code is a Matlab program for signal analysis of a given sound file. The analysis includes:
1) Options for:
- signal detrending;
- signal normalization.
2) Plotting of the:
- signal in the time domain (oscillogram);
- signal in the frequency domain (spectrum);
- signal in the time-frequency domain (spectrogram);
- signal in the time-quefrency domain (cepstrogram);
- amplitude distribution of the signal (histogram);
- autocorrelation function of the signal (correlogram).
3) Displaying of the:
- minimum and maximum value of the signal;
- standard deviation (RMS-value);
- mean value (DC-value);
- crest-factor Q;
- dynamic range D;
- autocorrelation time.

The code is based on the theory described in:

[1] D. Manolakis, V. Ingle. Applied Digital Signal Processing. Cambridge, Cambridge University Press, 2011.

[2] J. Benesty, M. Sondhi, Y. Huang. Springer Handbook of Speech Processing. Berlin, Springer, 2008.

[3] Хр. Живомиров, Д. Пламенова. Изследване някои параметри на аудио сигналите. Национална конференция с м.у. „Акустика 2012”, 12 Октомври 2012, Варна / Списание Акустика, ISSN: 1312-4897, год. XIV, бр. 14, стр. 89-95, 2012.

Cite As

Hristo Zhivomirov (2021). Sound Analysis with Matlab (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (27)

Xiaoyi Hu

Kwaku Owusu

Hello Hristo,
I asked about converting the time domain signal from amplitude to dB. You provided me with a code (i.e. xdB = 20*log10(x) or in dB re 20 μPa as xdB = 20*log10(x/20e-6). Upon trying with the code my signal is completely distorted or miss represented from the original signal.

Please, any help. Thank you.

Assem Nomair

thank you very much for your code.

Hristo Zhivomirov

Hi Kwaku,

Thank you for your interest on my submission!
(1) The amplitude could be transformed in dBV using the expression xdB = 20*log10(x) or in dB re 20 μPa as xdB = 20*log10(x/20e-6). (2) The reason to use a frequency log scale is to give more insight to the low frequency content of the signal and also to form a frequency decades which facilitates the spectral analysis. The scale could be changed if one type plot(f, X, 'r') on line 46.

All best,

Kwaku Owusu

Hello Hristo,

Please I can see that the signal in the Time Domain is in Amplitude. Is there a way to convert it to decibel in the Time domain. And why it the frequency in FFT plotted in the log. Thank you.

Uwe Gaertner

Hristo Zhivomirov

Hello Jasper!

Yes, the code treats only the first sound channel. In order to do the second one, please change line 11 to x = x(:, 2);. And yes, it is long-term-average spectrum, while the spectrogram on lines 26-33 is the short-time one.

All best,

Jasper Ward

Am I right in thinking that this will only do the left channel of an audio file? If so is there a way I can alter the code so it will analyse a stereo? My other query is how the "signal in the frequency domain" section works. Is this a long-term-average-spectrum?

Hristo Zhivomirov

Hi David! Yes, perhaps the frequency of your data is described in kHz...

David Duque

Or do you think it is described in kHz instead of Hz?

David Duque

Unfortunately in my sample the frequencies are between 0 and 25 and they actually should be from 0 to at least 10000. Do you know how I can fix it?

Hristo Zhivomirov

Hi David! I just do not want to restrict the spectral analysis to the human hearing frequency range. For instance, the analysed signal could be infrasound or ultrasound.

Hristo Zhivomirov

Hi Akshat! I use electrical (not sound) level when perform the spectral analysis. I treat the signal itself, regardless of the underlying process. The reference level is 1 V.


what is the reference decibel value for this code in this function?

David Duque

Thank you very much! I still have a question, why is the Frequency Range not from around 16Hz to 20000Hz?

Erica Glidewell

Just what I needed, thank you!

vahid fooladi

Sean Jungst

Thanks a lot! This code helped me create a very interesting GUI project for my Matlab class.

Sueng-Wan Cho

Very nice..
Question) How can i interpret from the autocorrelation graph & value ?

what is the autocorrelation of the music signal?

Özay Özçelik

Hristo Zhivomirov

Hi, Nguyen! The basic reason for a minus sign in front of some dB value is because the logarithm of a number 0<x<1 is negative.

Nguyen Thanh Phong

Why dB have "-"?

Nguyen Thanh Phong

Thank you very much!



Mardare Ionut

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Noise Analysis with Matlab, plotpsd


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!