# harmonic algorithm for extending compressed bandwidth of audio file

I just found this site and feel at home :)

I've been playin around with python and some compression ideas and was wondering if there's anything like what I am trying to figure out...

I've noticed that mp4's uploaded to instagram go from ~0 to 13100Hz and on Youtube from ~0 to ~14000Hz... which is OK, but what if there was an algorithm to extend or at least soften this highcut, by taking the amplitudes of the frequencies within the respective bandwidths and applying a harmonic function, (possibly with averaging/weights), to add in implied values to the currently non-existant values (i.e. the and additional bandwidth from 14,000 to 20,000Hz would be harmonically synthesized and still have realistic values.) It could be a plug-in or something.

Anyways, I'm going to check out the board some, and hope to hear some smart replies! thanks!

• there is something called an aural exciter that's sorta meant to do something like this. it sorta splits the audio into low and high bands, and the high band goes through some simple non-linearity (maybe a square function and a cube function) to generate frequency components what previously were absent, then it's added back to the low band. – robert bristow-johnson Sep 4 '18 at 1:57
• Hi Evan! Welcome to your home then, but unfortunately audio is not throughly covered here and I don't know if it could change in the future... Anyway nothing shall stop you from asking your questions though. – Fat32 Sep 4 '18 at 2:07
• oh, forgot to mention. welcome to comp.dsp. – robert bristow-johnson Sep 4 '18 at 2:08
• oops, i meant the DSP stackexchange. – robert bristow-johnson Sep 4 '18 at 2:08

1. high-pass filter your input signal (keep the unmolested input around for later). the cutoff frequency should be adjustable. i would think a 2nd-order HPF with a Q approx= 0.707 (Butterworth) would be good enough.
2. square that HPF output,
3. add (maybe with an adjustable gain coefficient) that squared HPF back to the original input and output that audio sample.

see if that brightens up your day.

• Cool thanks! Wow you guys were some intense debaters back in the day! I've played around with Aphex exciters for audio production, hadn't thought of it in this scenario. What I did not know was about the odd-valued harmonics - which seems to be more of a problem with analog bridge rectifiers. What your saying looks good. Just to clarify I'm not replacing or mixing with filtered values - I am synthesizing harmonics to create values which were lost during compression or do not belong to the file or signal. thanks again! – evan Sep 4 '18 at 3:13

In addition to Robert's more practical answer, I would like to put just few lines on the (indefinetely long and debated) theoretical aspects of auido bandwidth extension.

Since the first days of digital audio compression, people are looking for ways to improve the decoded audio quality. The mass effect came with mp3s and mp4s as you noticed as well. Those codecs throw away the upper parts of the audio spectrum to reduce the compressed bandwidth. Its justification is solidly stated that most people (on the average; a key concept in perceptual lossy codecs) cannot hear the difference. Which is sufficiently verified by tests according to their claims.

So according to this view point, the loss of the audio quality in these codecs do not result from the thrown away spectrum but of the higly nonlinear modifications performed in the remaining audible band. This is especially dependent on the bitrate selected to encode the audio.

Needless to indicate, however, an uncompressed PCM waveform at sufficient bandwidth carries the highest audio quality (say among digital copies) whatever.

Therefore, algorithms still exist claiming to recover the missing spectrum. But is that really possible? All of these algorithms are clever. They add new spectrum that will feel pleasant. Just like old analog equipment adding pleasant distortions.

Furthermore, some more serious of them try to extend the bandwidth consistently with the existing spectrum. This demands a more mathematical treatment though, harmonic extensions, dependencies, and even physical constraints are considered; instrument modeling could be an ultimate tool in extending the harmony for example.

But eventually, one must recognize that, especially at mediocre compression levels the existing auido is highly modified and most of the subtle virtues are lost, and only regenerated to be similar in feeling to the original for the average listener. All of those algorithms, as a consequence, rely on this available compressed approximation to reconstruct the missing band, which may create an even a harder problem than the original at some instances.

Can you even reconstruct the audible band perfectly ?

• Agreed, the richness is lost especially if it's dependent on a physical instrument (one day machine learning could recognize/apply a model). Although the 6-7000Hz difference is only half an octave, I believe these frequencies do have affect. To reconstruct first put a rolling hp filter so amplitude values arent too heavy. Then for each frequency bin 0 to 14000Hz apply a harmonic function, storing only values above 14000Hz. Probably hardcode a few conditions to smooth out the new values. The harmonic function could be logarithmic for music, or omit odd harmonics if needed. Thanks for the reply! – evan Sep 4 '18 at 4:00
• Just forget the compression codec mpX and assume you have uncompressed PCM audio in 20-20kHz range. Now, filter it by a LPF cutoff 14kHz whose attenuation is 80dB at stop band. Threshold the stop band so that it's zero. Now if you can reconstruct the missing band from 14kHz-20kHz, then you can begin working on mpX encoded audio. Honestly, anyone who wants to get involved in such a work should have a fair knowledge about the internal mechanism of mp3 encoders. Because a solution that claims to recover what is being lost can hardly be proposed without knowing how it was lost in the first place. – Fat32 Sep 4 '18 at 12:41

Has been tried many times with varying degrees of success (or lack thereof).

These days most streaming services are fairly good: Spotify streams Ogg Vorbis at 302 kb/s. Apple Music streams HE-AAC at 256 kb/s. These are typically good up to about 16k or so.

Any stuff that's up there tends to not be harmonic, but it's typically wide band; created by transient events: attacks, percussion, cymbals, key clicks, etc. I'd think the best you can do is to get the average spectral shape right: extrapolating from the highest octave you have plus some spectral shaping filter.

Whether that's better or worse than doing nothing makes for an interesting listening experiment.