Which part of the Bookkeeping vector do I select in order to reconstruct the signal using 3rd, 4th and 5th level coefficients with waverec?

1 visualización (últimos 30 días)
I have a signal that I have decomposed using wavedec, which outputs the wavelet coefficients, C and the bookkeeping vector, L. I want to reconstruct the signal using the 3rd, 4th, and 5th level coefficients. Which part of the Bookkeeping vector should be selected in order to reconstruct the signal using waverec?

Respuestas (1)

Abhimenyu
Abhimenyu el 4 de Abr. de 2024
Hi Eashan,
From the information shared, I inferred that you are trying to reconstruct the signal using the 3rd, 4th, and 5th level "wavelet coefficients". The "bookkeeping vector", L provides the lengths of the various levels of decomposition stored in the wavelet coefficients", C. The structure of C is such that it begins with the approximation coefficients at the final level of decomposition, followed by the detail coefficients for each level in descending order.
Given a decomposition up to level N, the structure of C and L is as follows:
  • C = [A_N, D_N, D_{N-1}, ..., D_1]
  • L = [length(A_N), length(D_N), length(D_{N-1}), ..., length(D_1), original_signal_length]
To reconstruct the signal using just the 3rd, 4th, and 5th level coefficients, the "wavelet coefficients", C can be modified to include only the coefficients needed to reconstruct by setting others to zero. The specific parts of the "bookkeeping vector" are not required.
Assuming 5-level decomposition, here is an example MATLAB R2024A code that can reconstruct the signal using the 3rd, 4th, and 5th level coefficients:
  • Creating an example signal for reference:
% Create a sample signal
t = linspace(0, 1, 512); % Time vector
signal = sin(2 * pi * 5 * t) + 0.5 * sin(2 * pi * 10 * t); % Sample signal
  • Decomposition using the MATLAB "wavedec" function and 'db1' wavelet:
% Wavelet decomposition
wname = 'db1'; % Daubechies wavelet with 1 vanishing moment
[coeffs, L] = wavedec(signal, 5, wname);
  • Zeroing out the coefficients that are not required for reconstruction. Here 1st and 2nd level coefficients are reduced to zero:
% Calculate the cumulative sum of lengths in L to find indices
cumL = cumsum(L);
% Zero out detail coefficients for levels 1 and 2 in coeffs
% For level 1
coeffs(cumL(end-2)+1:cumL(end-1)) = 0;
% For level 2
coeffs(cumL(end-3)+1:cumL(end-2)) = 0;
  • Reconstruct the signal using MATLAB "waverec" function:
% Reconstruct the signal using the modified coeffs and original L
reconstructed_signal = waverec(coeffs, L, wname);
  • Plotting the results:
% Plot the original and reconstructed signal
figure;
plot(t, signal, 'b', 'DisplayName', 'Original Signal');
hold on;
plot(t, reconstructed_signal, 'r--', 'DisplayName', 'Reconstructed Signal');
legend show;
xlabel('Time');
ylabel('Amplitude');
title('Signal Reconstruction Using Levels 3, 4, and 5');
grid on;
To understand more about the MATLAB's "wavedec", "cumsum", "waverec" functions, please follow the below mentioned MATLAB R2024A documentation links respectively:
Regards,
Abhimenyu

Community Treasure Hunt

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

Start Hunting!

Translated by