Clear Filters
Clear Filters

How to implement sparse decoding after signal decompression

5 views (last 30 days)
Hi all,
I am trying to do the compression and subsequent decompression of polysomnographic signals based on the Lempel-Ziv-Welch (LZW) algorithm. The pre-call step of the LZW algorithm is sparse encoding which I have implemented as follows and it seems to work. However, I don't know how to implement the sparse decoding after the subsequent decompression to compare it with the original signal.
%----------------------------COMPRESS--------------------------------
[...]
%Construct a dictionary consisting of the Daubechies' extremal-phase wavelet least-asymmetric
%wavelet with 4 vanishing moments at levels 1 and 4, the discrete cosine transform-II basis,
%and the sine basis.
dictionary= {{'db4',2},'dct','sin',{'sym4',1},{'sym4',4}};
[mpdict,nbvect]= wmpdictionary(length(originalSignal),'lstcpt',dictionary);
%SPARSE ENCODING
dictionarySparse= mpdict; %1) The dictionary created that contains the entry is saved
dictionaryFull= full(dictionarySparse); %2) The full dictionary is obtained. The sparse
% dictionary is changed to the full one
alpha= randi ([0,10000],1152,1);%3) A random vector of the same size as the
% dictionary matrix necessary to make the
% dictionary more manageable is created
dicVector = dictionaryFull*alpha; %4) The dictionary is multiplied by the previous vector and a
% vector of the size of the dictionary (256 values) is obtained
[...]
%----------------------------DECOMPRESS--------------------------------
%Call LZW algorithm function to decompress.
[lzwOutputd, lzwTabled] = lzw2norm(lzwOutput);
lzwOutputdTime=0:1:length(lzwOutputd)-1;
%To RESTORE COEFFICIENTS a change from uint8 to double to return to
%having the same data type as when beginning is made. They are then
%normalized by dividing by their norm.
S2 = im2double (lzwOutputd); %S2 = cast (lzwOutputd,'double');
CRestaurados = S2/norm(S2);
CR_final = CRestaurados';
%SPARSE DECODING: Obtain the dictionary containing the restored signal:
%an array of 256x1152 values. Do the inverse step to sparse encoding.
%--?--
%Reconstructed signal
%The 256 values of the signal obtained in the previous step and the time
%vector are stored within the same vector and file
reconstructedEOG = originalSignal_salida;
tempReconsEOG = lzwOutputdTime';
reconstructedEOG = [tempReconsEOG reconstructedEOG];
This is the flowchart that I follow in my implementation according to the literature
If anyone can guide me I would be very grateful.
Kind regards,

Accepted Answer

Piyush
Piyush on 12 Oct 2023
I can understand that you are trying to implement compression and decompression of polysomnographic
signals based on the Lempel-Ziv-Welch (LZW) algorithm. While attempting to write the code for the algorithm you are unable to implement the sparse decoding, which is the pre-call step of the LZW algorithm.
Sparse decoding is a process used in certain compression or signal processing techniques to recover or reconstruct a sparse representation of the original signal or data. Sparse decoding aims to reconstruct the original signal from a compressed or sparse representation, typically achieved by using a dictionary or basis functions. To implement the sparse decoding step of the LZW algorithm after decompression, you can follow these steps:
  1. After decompression, you have the variable CRestaurados, which represents the restored signal coefficients.
  2. To perform sparse decoding, you need to reconstruct the signal using the dictionary that was used in the sparse encoding step.
  3. Initialize an empty array to store the reconstructed signal.
  4. Iterate through the restored signal coefficients:
  5. a. For each coefficient, multiply it by the corresponding column of the dictionary matrix dictionaryFull. This will give you a vector representing a dictionary entry.
5. b. Append the vector to the reconstructed signal array.
6. The reconstructed signal array now contains the sparse decoding of the compressed signal.
The below attached code snippet demonstrates the implementation of sparse coding:
reconstructedSignal = []; % Initialize the reconstructed signal array
for i = 1:size(CR_final, 1)
coefficient = CR_final(i); % Get the current coefficient
% Multiply the coefficient with the corresponding column of the dictionary
dictionaryEntry = dictionaryFull(:, i) * coefficient;
% Append the dictionary entry to the reconstructed signal
reconstructedSignal = [reconstructedSignal; dictionaryEntry];
end
% The reconstructed signal is now available in the 'reconstructedSignal' array
After implementing the sparse decoding step, you can compare the reconstructedSignal with the original signal to assess the accuracy of the decompression. Please note that the code provided assumes that the dimensions of CR_final and dictionaryFull are compatible.
Hope this helps!

More Answers (1)

Alberto López Martínez
Alberto López Martínez on 12 Apr 2024
Thank you very much for your answer. We have finally been able to implement this solution satisfactorily.
Sorry for the delay in thanking you for your help.
All best,
Alberto

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!