How do i implement DWT algorithm on audio?

3 views (last 30 days)
Boby Ahmad
Boby Ahmad on 13 Aug 2017
Answered: Hornett on 20 Aug 2024
DWT algo for embedding watermarks
i try to get CA,CD coeffisien with DWT
here is the code
[ca,cd]=dwt('audio.wav','haar');
but it get error,
*??? Error using ==> dwt
Too many output arguments.*
I have tried to use wavelet toolbox, but the result is also error
before i try with DWT, i have done try with LWT
lss = liftwave('haar','int2int');
[y, Fs] = wavread('audio.wav');
inc=2^4;
y2 = y*inc;
[R,k]=size(y2);
sample = round(y2(1:R,1));
[CA,CD]=lwt(double(sample(:)),lss);
someone can help me to write down the correct syntax / code to get CA,CD with DWT??
and what is the different using lwt and dwt??
thank you, sorry for bad english

Answers (1)

Hornett
Hornett on 20 Aug 2024
To address your issue with the Discrete Wavelet Transform (DWT) and Lifted Wavelet Transform (LWT) in MATLAB, let's clarify a few things and provide a working example.Understanding DWT and LWT
  1. DWT (Discrete Wavelet Transform): This is a traditional method to decompose a signal into approximation (CA) and detail (CD) coefficients using wavelets. It is often used for signal processing tasks, including watermarking.
  2. LWT (Lifted Wavelet Transform): This is an implementation of wavelet transforms that is more efficient in terms of computation and can handle integer data directly, which is useful for lossless transformations.
Correcting Your CodeUsing DWT
The error you're encountering with DWT is likely due to the incorrect number of outputs. The dwt function in MATLAB typically returns two outputs: the approximation coefficients and the detail coefficients for one level of decomposition. However, if you want to process an audio file, you need to read the file correctly and ensure your data is in the right format.
Here's how you can perform DWT on an audio signal:
% Read the audio file
[y, Fs] = audioread('audio.wav'); % Use 'audioread' instead of 'wavread'
% Select a single channel if stereo
y = y(:,1);
% Perform DWT
[CA, CD] = dwt(y, 'haar');
Using LWT
For LWT, your syntax looks mostly correct, but here is a refined version:
matlab
Copy code
% Read the audio file
[y, Fs] = audioread('audio.wav'); % Use 'audioread' instead of 'wavread'
% Select a single channel if stereo
y = y(:,1);
% Define liftwave
lss = liftwave('haar', 'int2int');
% Perform LWT
[y2, Fs] = audioread('audio.wav');
inc = 2^4;
y2 = y * inc;
sample = round(y2);
[CA, CD] = lwt(double(sample(:)), lss);
Key Differences Between DWT and LWT
  • Efficiency: LWT is generally more computationally efficient than DWT because it is based on a lifting scheme that reduces the number of operations.
  • Data Type: LWT can handle integer data directly, which makes it suitable for applications requiring lossless transformations.
  • Flexibility: LWT allows for custom wavelet designs, which can be advantageous for specific applications.
Additional Tips
  • Ensure you have the Wavelet Toolbox installed in MATLAB to use these functions.
  • Always check your data dimensions when performing operations on audio signals, especially if they are stereo (two channels).
  • Use audioread instead of wavread as the latter is deprecated in newer versions of MATLAB.
By following these guidelines, you should be able to perform DWT and LWT on your audio data successfully.

Categories

Find more on Discrete Multiresolution Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!