# What methods can be used for lossless audio compression?

15 vues (au cours des 30 derniers jours)
Sisi Misi le 11 Sep 2021
Commenté : Walter Roberson le 11 Sep 2021
Hi everyone
What methods can be used for lossless audio compression?
I've read that RLW, LZW, Arithmetic encoding, Huffman coding, Shannon Fano coding are the algorithm used in the lossless method
But where can we find the matlab code for the algorithm ?
thank you
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (2)

Akira Agata le 11 Sep 2021
I believe the most simplest way to save data as a lossless audio file using MATLAB is audiowrite.
This function can save data as WAVE (.wav) or FLAC (.flac) file, both are typical lossless audio format.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Walter Roberson le 11 Sep 2021
Any deterministic function that does one-to-one and on-to mappings, and makes at least one input shorter to represent on output by at least one bit, is a lossless compression algorithm.
The one-to-one and on-to means that a given input always becomes the same output and that no two different inputs become the same output.
There are an endless number of lossless compression algorithms.
The trick for lossless compression algorithms is finding one that compresses well on a "useful" set of data. A great algorithm for jackhammer noise might not be good for speech or classical music. It would be reasonable to expect that if you had ultrasound recordings of bats then you might want a different algorithm than for that
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Walter Roberson le 11 Sep 2021
Example of a valid lossless compression algorithm:
if regexp(LineToCompress, '#+T1D')
output = '#' + LineToCompress'
elseif strcmp(LineToCompress, 'You take one down, and pass it around!')
output = '#T1D'
else
output = LineToCompress
end
and that would act to transform
99 bottles of beer on the wall!
99 bottles of beer!
You take one down, and pass it around!
98 bottles of beer on the wall!
98 bottles of beer on the wall!
98 bottles of beer!
You take one down, and pass it around!
97 bottles of beer on the wall!
97 bottles of beer on the wall!
97 bottles of beer!
#T1D
96 bottles of beer on the wall!
into
99 bottles of beer on the wall!
99 bottles of beer!
#T1D
98 bottles of beer on the wall!
98 bottles of beer on the wall!
98 bottles of beer!
#T1D
97 bottles of beer on the wall!
97 bottles of beer on the wall!
97 bottles of beer!
##T1D
96 bottles of beer on the wall!
Notice that the third stanza got longer, the input #T1D expanding to ##T1D . But the first two stanzas each got shorter, so there is overall compression.
You could do exactly the same kind of thing with audio. You could recognize an exact copy of the sound corresponding to the sung "You take one down, and pass it around!", and provided that the inputs had exactly the same sound (copied), you could replace it with a sung "T1D!". Such a simple algorithm by itself would be useless in real life, as people are not going to sing the phrase exactly the same way at exactly the right sample times, not in real life.
However, the principle holds: you can recognize something about sound and encode it. For example there could plausibly be a situation in which a piece of equipment emitted a sine wave at 378 Hz that holds steady at a volume for a few seconds at a time before changing. The algorithm could detect stretches of 378 Hz and constant volume, and subtract that out and insert some bits saying "volume 58 duration 482 samples" and the rest of the stream could be encoding any minor differences from that. Would this be generally useful? NO -- but as long as it can exactly reproduce any sound, and it makes at least one situation shorter, it counts as lossless audio compression.
... And that should make it more clear that there is an endless number of lossless audio compression algorithms.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Audio and Video Data dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by