5 Digital audio system

In digital audio systems, an analog-to-digital converter (ADC) is used to convert the analog electrical waveform representing the sound into a digital signal that can be recorded, edited, or copied using a computer, audio player or other digital tools. The reverse process (digital-to-analog conversion) occurs and the digital signal is converted into analog waveform before it is sent to the audio power amplifier when a consumer wants to listen to the recorded sound.


In MATLAB an audio signal can be read using the audioread command. For example, if the name of an audio file is ‘a.wav’ and it’s recorded with sampling frequency of , you can read and save it in an array called audioSound using the following command:


By checking the size of audioSound, you can see if the audio signal is stereo or mono. In case of being stereo, you can separate the two channels and save each as the left and right channel individually.

You can use audiowrite command to save an audio array into a file. For example, to save the audio signal audioArray into a file called ‘b.wav’, the following command does the job:


The soundsc(audioArray,fs) command plays the sound so the user can listen to the audio.


The following objectives will be covered as you go through the experiment procedure.

  • Read, play and write audio files in Matlab
  • Determine if an audio file is mono or stereo
  • Plot an audio file array
  • Determine the sampling frequency, bandwidth and duration of audio files
  • Plot the frequency spectrum of an audio file


  1. Download Several test audio files. Read each of them using audioread command.

a) What is the sampling frequency of the audio file?

b) How long is the duration of the sound?

c) What is the size of the audio file array?

d) Is it stereo or mono? Why?

e) Is it music or a voice?

2. For stereo audio files, separate the two channels.

3. Choose one of the audio arrays and plot it over time using plot(audioArray,t) command. You should be able to see the amplitude of the voice as it changes over time. Hint: For this case you can define  as:



Explain how the above code works.

4. Choose a voice and a music audio signal and plot their spectrum using the following command:

plot(psd(spectrum.periodogram, audioArray,’Fs’,fs,’NFFT’,length(audioArray)));  

a) What is the maximum frequency of your voice signal?

b) What is the maximum frequency of the music signal?

c) Can you differentiate the voice signal from music signal using its spectrum

5. Select and read a voice audio signal and plot its spectrum.

a) What is the bandwidth of the voice signal?

b) What is the lowest sampling frequency that can be used to sample the voice?

c) What happens if the sampling frequency is below the lowest possible one?

6. Select and read an audio file into an array. Amplify all the array elements by 2 and record it in another file called ‘Amplified file’. Plot the amplitude of the amplified audio within the new file over time.

7. Listen to the new amplified file generated in Step 6 as well as the original file. Do you notice any changes? What are these changes?

8. Write a code that adds echo to the audio file. To do so, consider that besides your audio array and its sampling frequency, you should have two other parameters as delay and echo_amp. The delay represents the delay of the echo in seconds. It means, the echo starts after delay seconds have passed from the start of the audio signal. The parameter echo-amp specifies the amplification of the echo which normally should be relatively a small value, since the echo is typically not as loud as the original signal.

9. Complete your code by down sampling your signal. You can take out every other samples from your audio array and record or play it with the same sample frequency. This way you compress your original audio file. Also, you can just change the sampling frequency to achieve the same result. Plot the compressed audio array and listen to the file. Explain what has happened.

10. Your original audio array has been recorded by sampling frequency fs . What happens if you plot or play the original signal with sampling frequency fs/2? Explain the results.

11. Try to play one of the original files backwards. You can use flipud(audioArray) command to flip your array or write a code to do so. Explain your result and plot the amplitude of the backward audio over time.

12. Do you think compressing or extending the file, will change its spectrum? Plot the spectrum of the compressed or extended file in step 10 and 11. Explain the results.


Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Physical System Modelling Using MATLAB by F. John Dian, R. Vahidnia is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book