0

I am using Matlab and I have a sparse vector (only having about 10% of nonzero values but otherwise quite arbitrary).

I want to compress it (smallest size). I also want to know the compression ratio I obtained.

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
Abhishek
  • 81
  • 8
  • Isn't the whole point of compression is to reconstruct the signal at the receiver's end ? I mean blindly omitting the zeros will compress the signal but how will you be able to reconstruct it later if required ? – roni Feb 13 '15 at 08:55
  • @roni I have a signal and I want to compress it ,for that what I should I do ,I would like to know is there any inbuilt compression algorithm is there in matlab or not ,..or how to compress it ??? – Abhishek Feb 13 '15 at 15:56
  • Any particular algorithm in mind? Any requirements on the algorithm (speed, efficiency)? Can you give an example of your sparse vector? Please add the information from the comment ot the question. – NoDataDumpNoContribution Feb 18 '15 at 14:32
  • @Trilarion ,I have done wavelet transform(bior) on an ecg siganl and done thresholding on it ,now there there are only 77 non zeros out of 779 data points ..this sparse vector only I need to compress and send .. – Abhishek Feb 20 '15 at 00:23
  • I reformulated your question according to your comments and hope it can be reopened. I think it is a really worthwile topic although it seems you did not do much research before. – NoDataDumpNoContribution Feb 20 '15 at 10:17
  • Do you have integer numbers or floating point, should it be lossless compress or a bit of loss acceptable? – NoDataDumpNoContribution Feb 20 '15 at 10:18
  • @Trilarion..thanks ,I have done DWT and threshold the coefficients to make it sparse ,now I have only 10% of non zero coefficients , my doubt is that when finding compression ratio whether only non zero coefficient bytes are counted or not ,if so then what about position information of zeros..? – Abhishek Feb 23 '15 at 03:04

1 Answers1

1

You can get the size of any variable in MATLAB using the whos function. It returns a struct containing the name, size, class, number of bytes and some other values of a variable. To get information on a variable A, you call

info = whos('A');

So you could e.g. do the following:

% Create matrices
A = [0 1 0 0; 1 0 0 0; 0 0 1 0; 0 0 0 1]
S = sparse(A)

before = whos('A')
after = whos('S')

comprRatio = before.bytes / after.bytes

which in this small examples returns

comprRatio = 
    1.2308

as the matrix A is 128 bytes and the sparse matrix S is 104 bytes.

If you do any other compression (I did not completely get what sort of compression you are trying to achieve), you can do exactly the same thing with whos.

hbaderts
  • 14,136
  • 4
  • 41
  • 48
  • I have a signal and I want to compress it ,for that what I should I do ,I would like to know is there any inbuilt compression algorithm is there in matlab or not ,..or how to compress it ??? – Abhishek Feb 13 '15 at 15:57
  • I thank for your answer but I wasnt looking for it ,I have a signal (which is sparse)and just I want to compress it.. – Abhishek Feb 13 '15 at 16:16
  • use can use DCT transform, wavelets, haar transform . Haar transform is pretty easy to do. You can code it yourself. – roni Feb 13 '15 at 19:34