Monday, October 14, 2024

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages

Audio Compression Using Wavelets In MATLAB

efy tested sani theoAudio frequencies range from 20Hz to 20kHz but these frequencies are not heard in the same way. Frequencies below 20Hz and above 20kHz are very difficult to hear, while those not much more than 20Hz, or not much less than 20kHz, cannot be heard by most people. We often need to process these audio signals for various applications. MATLAB is one of the best signal analysis and signal processing tools.

Audio compression is a very good example of speech and signal processing. We use the Internet for various purposes including entertainment. Audio is common in all entertainment applications. If an audio file size is large, it takes more space to store.

Audio/video compression frees up space substantially, which can then be utilised for other purposes. This article describes some important audio compression techniques.

- Advertisement -

An audio signal sample is taken and analysed using MATLAB for frequency and amplitude. Haar and Daubenches algorithms are applied on the speech signal and the audio is compressed. Audio sizes before and after compression are compared.

The following parameters are compared by the program: Peak signal-to-noise ratio (PSNR), normalised root-mean-square error (NRMSE) and compression ratios.

- Advertisement -

Haar wavelet algorithm performs the following functions:
1. Selects audio and finds actual signal size
2. Finds amplitude and frequency
3. Creates frame
4. Decomposes the signal spectrum into wavelet
5. Creates psychoacoustic model
6. Inspects the spectrum and finds tones maskers
7. Applies mu-law of compression
8. Finds and corrects offset
9. Rewrites wave
10. Finds the size of compressed signal

Daubenches wavelet transform performs the following functions:
1. Selects audio and finds the actual signal size
2. Finds amplitude and frequency
3. Chooses a block size
4. Changes compression percentages
5. Initialises compressed matrix
6. Does compression using inverse discrete cosine transform (IDCT)
7. Rewrites signal
8. Finds the size of compressed signal

For complete algorithms, refer code implementations.

MATLAB code file AudioCompression.m implements Haar wavelet and AudioCompression2.m file implements Daubenches wavelet. In this example, Windows XP Startup.wav is the sample audio file used for compression.

Comparison of performance metrics such as PSNR, MSE and compression ratio shows that Daubenches algorithm is best suited for lossless compression of speech signals. Advantages of audio compression are less storage space and associated cost, and faster data transfer.

There are several techniques for data compression. You should follow lossless compression technique as lossy audio compression results in data loss.

Image and video can be compressed in a similar way.

Steps to run the program

Run AudioCompresssion.m file. You will get a window as shown in Fig. 1. Select audio file and then press Compress Audio button. You will get output windows as shown in Fig. 5. Compare audio file sizes before and after compression. The compressed audio file is generated as Output1.wav in the same path as the original source file (AudioCompresssion.m).

Program output (Haar wavelet)
Fig. 1: Program output (Haar wavelet)
Original audio signal (size: 414.691kB)
Fig. 2: Original audio signal (size: 414.691kB)
Haar-wavelet-decomposed audio signal (size: 207.367kB)
Fig. 3: Haar-wavelet-decomposed audio signal (size: 207.367kB)
Daubenches-wavelet-decomposed audio signal (size: 192.043kB)
Fig. 4: Daubenches-wavelet-decomposed audio signal (size: 192.043kB)
Graphical user interface for audio compression
Fig. 5: Graphical user interface for audio compression

Now run AudioCompression2.m file. Select audio file and press Compress Audio button. You will get the program output window as shown in Fig. 6. Observe the size of compressed audio. Here, three compressed audio files are generated and saved in the same path as the original source file. These three outputs correspond to different discrete cosine transform (DCT) window sizes of 2, 4 and 8. The percentage change in compressed files may differ depending on the quality of original file and size.

Program output (Daubenches wavelet)
Fig. 6: Program output (Daubenches wavelet)

Download Source Folder


 

29 COMMENTS

  1. The author Lalit Patil replies: It is fully tested and it’s working fine. What may be the reason is you might have low RAM in laptop or MATLAB may be consuming higher % of CPU in laptop so GUI couldn’t load properly. You can try with good configuration of laptop.

  2. After selecting the audio in the GUI the program gives the following error.
    => Error using audioread. Too many arguments.
    =>Error in gui_mainfcn – feval(varargin{:});
    =>Error in gui_mainfcn(gui_State,varargin{:});
    =>Error while evaluating UIControl Callback

  3. Please check the correct code with the original code. This project was tested using Matlab R2014a. Note that there are some compatibility issues in Matlab version, you can also check them in your Matlab environment.

  4. You have not mentioned the exact configuration of your Laptop but if you have 4GB RAM and 10GB HD, you can run MATLAB 2014a. Note that there are advantages having higher RAM and HD memories for running tool like Matlab.

  5. i got input when i pressed compress icon..its shows following error

    Error using wavread (line 70)
    Invalid Wave File. Reason: Cannot open file.

    Error in AudioCompression>pushbutton2_Callback (line 106)
    [x,Fs,bits] = wavread(file_name);

    Error in gui_mainfcn (line 95)
    feval(varargin{:});

    Error in AudioCompression (line 42)
    gui_mainfcn(gui_State, varargin{:});

    Error in
    @(hObject,eventdata)AudioCompression(‘pushbutton2_Callback’,hObject,eventdata,guidata(hObject))

    Error while evaluating uicontrol Callback

  6. sir, i am getting this error
    Too many outputs requested. Most likely cause is missing [] around left hand side that has a comma separated list expansion.

    Error in AudioCompression2>pushbutton2_Callback (line 85)
    SIZE = fileinfo.bytes;

    Error in gui_mainfcn (line 95)
    feval(varargin{:});

    Error in AudioCompression2 (line 42)
    gui_mainfcn(gui_State, varargin{:});

    Error in @(hObject,eventdata)AudioCompression2(‘pushbutton2_Callback’,hObject,eventdata,guidata(hObject))

    Error while evaluating UIControl Callback

    please help me ..

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics