Skip to main content

University of Salford home

Acoustics

  • Acoustics Research Centre
  • Commercial testing
  • Acoustic PhD opportunities
  • Research subject areas
  • Acoustics Research Staff
  • Acoustics Research Contacts
  • Seminars
  • Acoustics & Audio Taught Programme Employer and Alumni Surveys
  • Acoustics and Audio Courses
  • Future Homes (Acoustics)
  1. Home
  2. An introduction to Sound Quality testing
  3. Sound quality – making products sound better
  4. Private: Psychoacoustics
  5. MATLAB codes

MATLAB codes

Calculating the Metrics

Download the MATLAB codes

These are MATLAB codes provided to calculate values for the following metrics: Third octave band levels, loudness and sharpness. Before using the MATLAB codes 2-channel .wav files should be separated into two 1-channel .wav files. The left and right channels can be extracted separately to .wav file as described using Adobe audition, the codes DO NOT work for 2-channel .wav files.

In order to use the MATLAB codes all codes and .wav files should be in the current MATLAB directory. The .wav file must be imported as a matrix to be used by the sound quality functions ‘filter_third_octaves_downsample’, ‘loudness_1991’, ‘sharpness_Fastl’ and ‘roughness4’. This can be done by typing ‘[x Fs] = wavread(‘’)’ at the console. ‘x’ then becomes the .wav file and ‘Fs’ the sample rate. When analysing data using the metrics bear in mind that the filters to obtain a third octave spectrum and the loudness metric are the only standardised metric listed (Zwicker). For calculations involving a metric such as sharpness (in this case Fastl’s method has been used), using different methods than these listed to calculate metrics may result in different answers which are therefore not directly comparable with these results.

Third Octave Spectrum

To calculate the powers in the third octave bands we require: x and Fs (see above), Fmin and Fmax which are the lowest and the highest third octave bands for which a power value is required (usually these would be 25 Hz and 12.5 kHz respectively), Pref which is a reference value (this can be calculated by inputting a reference tone into the filters Pref is then the difference between the level of the tone and the value returned by the filters), and N which is the steepness of the third octave filters (usually this would be 8). Typing ‘[Ptotal,P,F]=filter_third_octaves_downsample(x,Pref,Fs,Fmin,Fmax,N)’ at the console then returns the values Ptotal which is the total power of the sound, P which is a matrix of power values for each of the corresponding third octave centre frequencies in the matrix F. A bar chart of these values is also plotted.

Loudness

To calculate loudness we require: x and Fs (see above), and Pref which is a reference value (this can be calculated by inputting a reference tone into the third octave filters function described above, in this case N should be input as ‘4’, Pref is then the difference between the level of the tone and the value returned by the filters) and Mod which is 0 for a free field and 1 for a diffuse field. Typing ‘[N_entire,N_single] = loudness_1991(x,Pref,Fs,Mod)’ at the console returns the values N_entire which is the total loudness of the sound (in sones) and N_single which is a matrix of 240 specific loudness values spaced at 0.1 Bark intervals (in sones/Bark). A graph of these values is also plotted.

Sharpness

To calculate the sharpness we must first calculate the loudness using the function above. Then typing ‘[sharp] = sharpness_Fastl(loudspec)’ at the console returns the value sharp which is the sharpness (in Acum).

Seminars

  • Webinar 28/5/25: An Introduction to NERIC: The People, Projects and Practical Considerations
  • Webinar 14/5/25: Soundscapy: Open Source Software in Soundscape
  • Webinar 7/5/25: Modal analysis of signal processing systems: applications for room acoustics

Contact Us

Head of Acoustics Research
Professor David Waddington
d.c.waddington@salford.ac.uk

© 2025 University of Salford

  • Acoustics on YouTube
  • Acoustics on Facebook
  • Acoustics on Instagram
  • Acoustics on LinkedIn