The officially official Devuan Forum!

You are not logged in.

#1 2024-07-17 21:28:36

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Resampling and the Gibbs phenomenon with Audacity

The Gibbs phenomenon was observed by experimental physicists and was believed to be due to imperfections in the measuring apparatus, but it is in fact a mathematical result. It is one cause of ringing artifacts in signal processing. It is named after Josiah Willard Gibbs.
_https://en.wikipedia.org/wiki/Gibbs_phenomenon

Square wave
_https://en.wikipedia.org/wiki/Square_wave

Analogue signal is continuous, and digital signal is discrete.
The simplest example of discrete signals is, perhaps, square waves.
Because of "jump discontinuity", square waves don't like resampling.
It doesn't matter  which resampler was used, the result is always a sort of Gibbs phenomenon.

Gibbs phenomenon
Functional approximation of square wave using 25 harmonics
_https://en.wikipedia.org/wiki/File:Gibbs_phenomenon_50.svg
_https://en.wikipedia.org/wiki/Gibbs_phenomenon

Square waves can be easily created with Audacity.

sudo apt install audacity

1. Open Audacity.

2. Go to Edit > Preferences > Quality

3. Set the project defaults:
Default Sample Rate: 384000 Hz
Default Sample Format: 32-bit float
Sample Rate Converter: Best Quality (Slowest)
And click "OK".

On the bottom left corner of Audacity's main window, you will see Project Rate (Hz) menu. It should be "384000". If not, click on it and select "384000".

Go to Generate > Tone
Waveform: Square
Frequency (Hz): 440
Amplitude: 0.8
Duration: 000,040,000 samples

Click "Generate", and you will see a nice square wave.
On the left side of the audio track, you should see:
Mono, 384000Hz
32-bit float

Now, we can downsample the square wave to 48kHz 16bit (default).
It seems that, in Audacity, the standard Linux resampler (libsamplerate) was already replaced with SoX resampler. Therefore, the result might be a nice Gibbs phenomenon, and not a kind of strange artefact.

Downsampling:

1. Change the sample rate of the project to 48000 Hz (on the bottom left corner of Audacity's main window).

2. Go to File > Export > Export as WAV
Click "Save", then click "OK".
It will be downsampled to 48kHz 16bit (default) and exported as wave.

Check it with "file" command:

$ file 16bit_48kHz.wav
16bit_48kHz.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 48000 Hz 

Now, you can open this wave with Audacity and see a sort of Gibbs phenomenon.
You can zoom into it:
Go to View > Zoom > "Zoom in"

Since the public has already complained that all this is "not even remotely scientific", it makes sense, perhaps, to make it more scientific with math.

sudo apt install maxima gnuplot 

Let us take a very simple mathematical function

tanh(20*sin(x)) 

If you plot it with Maxima

$ maxima
(%i1) plot2d([tanh(20*sin(x))], [x,-10*%pi,10*%pi], [y,-1.1,1.1], [plot_format, gnuplot])$ 

you will see a square wave with "jump discontinuities".
If you zoom into it

$ maxima
(%i2) plot2d([tanh(20*sin(x))], [x,-1.2*%pi,1.2*%pi], [y,-1.1,1.1], [plot_format, gnuplot])$ 

you will see a continuous function.
It depends on the resolution (that is, sample rate).

If the original wave is 32bit Float 384kHz DXD, and it is a sort of music recording, it is not likely to have very big "jump discontinuities", and, therefore, the Gibbs phenomenon may not produce audible sound distortions with downsampling. It depends, of course, on the quality of resampler as well.

EDIT: To avoid confusion, it might be necessary to provide a sort of mathematical explanation.

Because of "jump discontinuities", Fourier series cannot converge uniformly
_https://en.wikipedia.org/wiki/Convergence_of_Fourier_series
It should be obvious that a series of continuous functions cannot converge uniformly to a function with "jump discontinuities".  This is the reason why any sort of interpolation (and any sort of resamplers) fails. That is why you get the Gibbs phenomenon, and, that is why the square wave is not a sum of harmonics (in terms of physics).
_https://en.wikipedia.org/wiki/Harmonic

Digital to audio conversion (DAC) means that a digital signal (that is, a discrete signal of finite sample rate) is converted to analog signal (that is, a continuous signal of infinite sample rate). It might be obvious, therefore, that, when you are playing a square wave through your DAC, you get the same Gibbs phenomenon.
Notice that "the Gibbs phenomenon was observed by experimental physicists and was believed to be due to imperfections in the measuring apparatus, but it is in fact a mathematical result."
_https://en.wikipedia.org/wiki/Gibbs_phenomenon

This also means sound distortions, when you are playing a digital music crap of CD format through your DAC.

If you do not believe that your DAC is playing crap, you can create a square wave of 48kHz 16bit format with Audacity, upsample it to 384kHz 32bit Float DXD format, zoom into it, and you will see the same Gibbs phenomenon.

It doesn't matter whether resampling of a square wave is performed in software or in hardware. The result is always a sort of Gibbs phenomenon. You cannot fool the nature, as it was discovered by experimental physicists and explained by mathematicians.

In short, square waves are used to visualize the effect of "jump discontinuities". It helps to understand why and how resampling produces sound distortions. Since "jump discontinuities" are a natural feature of low resolution formats, such as 48kHz 16bit, it does not make much sense to measure sound quality of this particular sort of digital crap in "blind tests".

NOTE: If it is not obvious that the square wave is not a sum of harmonics, you may try a very simple "imaginary experiment".
Since harmonics, or sinusoidal waves, are continuous functions, you may try to imagine a continuous function.
The sum of two continuous functions is a continuous function. This can be taken for granted.
3 = 2 + 1
4 = 3 + 1
...
100 = 99 + 1
Thus the sum of 100 continuous functions is also a continuous function.
However, the square wave is not a continuous function. It has "jump discontinuities".
What is more, the square wave is not even approximately equal to a sum of harmonics. That is why you get the Gibbs phenomenon, when you are trying to approximate it with a sum of harmonics.

Last edited by igorzwx (2024-07-26 20:44:02)

Offline

#2 2024-07-18 18:33:10

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

Recorded over 50 years ago. It's much more enjoyable to listen to than rectangles. Without any bells and whistles.
https://www.youtube.com/watch?v=dthgRdTf0Ds

Last edited by aluma (2024-07-18 18:41:23)

Offline

#3 2024-07-18 19:19:54

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

aluma wrote:

Recorded over 50 years ago... Without any bells and whistles.

℗ 1967 - It was, perhaps, analogue recording. Without any sort of pulseaudio and without Gibbs.

The World We Knew (Over And Over) · Frank Sinatra
The World We Knew
℗ 1967 Frank Sinatra Enterprises, LLC

Discover the Hi-Res Masters: Frank Sinatra playlist containing all the essential tracks in Hi-Res 24-bit for an unequalled sound quality (FLAC 24-Bit / 192kHz)

It may sound better, perhaps.

Do you think that youtube sound quality (through pulseaudio) is good enough?

Last edited by igorzwx (2024-07-18 22:03:09)

Offline

#4 2024-07-19 02:33:23

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

Have you ever heard this recording played from a gramophone record?
(Have you ever listened to vinyl?)

It's time to save you, your long-term struggle against pulseaudio is making itself felt. The contemplation of rectangles has now been added to writing out directions to the doctor. smile

What our posts have in common is that they have nothing to do with this forum itself, the forum of the Devuan distribution, and your links and advice on proprietary formats and paid resamples in no way correspond to Freedom Hacks, as I understand it.

P.S. I might add, your questions and my answers don't make much sense.

We need a point of reference, no matter how much I “sang Caruso,” if you haven’t heard Hi-End sound with a modified CD, with a sampling frequency of only 44.1 kHz, when “Valkyries really fly” and the performer can be “touched” in space, when you hear all 16 bits and the atmosphere of the hall, you simply have nothing to compare with. A regular computer, even at 384 kHz, is very far from this level.

You can play with Audiocity and copy links to commercial startups, but they have no practical meaning.

Last edited by aluma (2024-07-19 04:21:29)

Offline

#5 2024-07-19 09:18:49

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

You did not answer my question. May I ask it again?

Do you think that youtube sound quality (through pulseaudio) is good enough?

Offline

#6 2024-07-19 10:54:20

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

It suits me quite well.

Offline

#7 2024-07-19 13:31:53

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

Thanks for answering. It seems that your are satisfied with sound quality.

However, the topic is about "resampling and the Gibbs phenomenon".
If you want to discuss something else, you may start a new topic.

Offline

#8 2024-07-20 04:24:15

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

If you want to discuss something else, you may start a new topic.

If the original wave is 32bit Float 384kHz DXD, and it is a sort of music recording, it is not likely to have very big "jump discontinuities", and, therefore, the Gibbs phenomenon may not produce audible sound distortions with downsampling. It depends, of course, on the quality of resampler as well.

How can you be left unattended?
You'll step on every mistake! smile

First, let's try to get at least some practical result from your idea and move from fortune-telling to facts.
To do this, you need to select the sampling frequencies available to your sound card. Then you can simply play them back and hear the difference. And you can make this accessible to everyone if you select 48 kHz and change it twice, to, for example, 192 and back to 48. Any card has 48 kHz and everyone can hear the differences.

And secondly, if you put in your own words all the mathematics that is crammed into the wiki article, then everything is simple. A rectangular pulse is the sum of an infinite number of sinusoids with all possible frequencies. But the upper frequency of the card is limited by its bandwidth (usually a little more than 20 kHz), so we get not a rectangle, but a trapezoid (we have a front with a non-zero duration) and a “comb”.

By the way, the number of harmonics will be determined by the selected pulse frequency and bandwidth; for 1 kHz and 20 kHz the upper one will be the 20th.
Therefore, the real signal at the output of the card will be different from the “virtual” one that the computer will show in gnuplot.

Last edited by aluma (2024-07-20 05:01:54)

Offline

#9 2024-07-20 08:51:28

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

It is off-topic again.

The topic is about "resampling and the Gibbs phenomenon with Audacity".

It is about how resamplers work, it is about math.
It is not about playing square waves though a sound card.

In a word, "384kHz" of DXD is sample rate. It is not frequency.

Resampling is performed in software.
And you are trying to explain how hardware works.
It is very interesting, but it is off-topic.

NOTE: In mathematics, square waves are used to visualize the effect of "jump discontinuities", and you can find them in many text books on Fourier series.

Offline

#10 2024-07-20 10:34:57

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

the Gibbs phenomenon may not produce audible sound distortions with downsampling.

Instead of assumptions and fortune-telling, take it and listen. Not necessarily at a sampling frequency of 384 KHz; if there is an effect, it will be noticeable at any one. You can do this with any signal; with a rectangle it’s easier to hear.

Offline

#11 2024-07-20 11:05:41

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

You can play square waves through your DAC, if you want.
But it has nothing to do with the topic.

Offline

#12 2024-07-20 12:55:10

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

For God's sake, I don't want to disturb you at all.
Through Audigy2 I do not hear any difference when playing wav files of 192 and 48 kHz  (square wave generated by Audacity) . Obviously, the hardware (bandwidth) neutralizes the differences and there is no escape from this.

Last edited by aluma (2024-07-20 13:09:17)

Offline

#13 2024-07-20 13:19:59

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

This is closely related topic. But it is still another topic, and we may better discuss it separately (in a new "topic").

The topic is about quality of resampling. It is about quality of digital sound, or, perhaps, more exactly, "digital sound file".
What you want to discuss is the quality of "digital to audio" conversion (DAC).
The final result depends on both, and on the sound system (quality of drivers etc.).

Last edited by igorzwx (2024-07-20 16:02:19)

Offline

#14 2024-07-20 15:33:28

stargate-sg1-cheyenne-mtn
Member
Registered: 2023-11-27
Posts: 190  

Re: Resampling and the Gibbs phenomenon with Audacity

https://en.wikipedia.org/wiki/Audiophile

Last edited by stargate-sg1-cheyenne-mtn (2024-07-24 07:42:13)


Be Excellent to each other and Party On!
https://www.youtube.com/watch?v=rph_1DODXDU
https://en.wikipedia.org/wiki/Bill_%26_Ted%27s_Excellent_Adventure
Do unto others as you would have them do instantaneously back to you!

Offline

#15 2024-07-20 16:31:36

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

OK, if you want to make an audio test, you may try something like this.

Take a free sample of 32bit Float DXD
_https://positive-feedback.com/reviews/music-reviews/what-we-hear-with-dxd-32-bit-files/
and downsample it with the fftrate resampler to different audio formats.
For example:
1. DXD to 192kHz 32bit (or 24bit)
2. DXD to 48kHz 16bit

Install Audacious and the fftrate ALSA plugin.
To prevent resampling, configure fftrate to 192kHz.
In Audacious, select ALSA output and set "Bit depth".
Then, you can play 192kHz wave.

Then, you can reconfigure fftrate for 48kHz 16bit format, and play 48kHz 16bit wave.

audacious 2>&1 *.wav 

Last edited by igorzwx (2024-07-20 18:37:50)

Offline

#16 2024-07-21 05:22:11

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

No not like this.

The generally accepted approach in such cases is for the user to state the premises, check it himself and report his impressions.
Check your assumptions yourself and don’t hesitate to let us know about your result.

If you don't have the appropriate hardware, just compare the sound of two 48 kHz files, one original, the other resampled from a file with a different sampling rate.

And inviting others to check their toys is bad manners, I think so.

Offline

#17 2024-07-21 08:03:38

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

If the goal is to improve sound quality on your notebook, my method may work.

What is important is to prevent resampling and format conversion.
Otherwise, you may not know, what you are actually testing.

Offline

#18 2024-07-21 08:14:32

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

Have you tried it yourself?
You won't improve anything and you won't hear any difference from resampling your favorite Petrov.
Empty chatter.

Offline

#19 2024-07-21 10:02:46

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

Yes, I am using my method, and it works.
If the goal is to improve sound quality on your computer, you can simply remove pulseaudio and/or pipewire, install Petrov's fftrate plugin, and configure it for 32bit 192kHz (Intel HDA), or other HiRes format, if it is supported by your sound card. For USB headsets, you may try 16bit 48kHz.

Offline

#20 2024-07-21 11:20:29

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

Just words without any objective data, measurements, etc.
And about “pulseaudio and/or pipewire” - this is nonsense. Their necessity is determined by specific conditions, sound card, BIOS, etc.

Offline

#21 2024-07-21 11:34:21

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

Of course, it is very bad manners to remove pulseaudio or pipewire.
The good manners is to use pulseaudio, pipewire, or any other crap, because of loyalty to authorities.

Offline

#22 2024-07-21 11:54:58

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

What does bad manners have to do with it?
Look through the forum, I asked for advice about sound in Firefox. With pure alsa, the sound was everywhere, except for the browser, which “did not see” the sound system. Either pipewire or jack was required.
I have 5 different computers at home with the same Linux and DE and the sound settings are different for everyone.

Offline

#23 2024-07-21 12:50:04

igorzwx
Member
Registered: 2024-05-06
Posts: 105  

Re: Resampling and the Gibbs phenomenon with Audacity

On Devuan Daedalus 5.0, sound works in Firefox out of the box, after the removal of pulseaudio
_https://dev1galaxy.org/viewtopic.php?pid=49837#p49837

The problem might be that you want to use your Audigy2, and it is not the default device.
The simplest solution to such problems is to run

arateconf

and select Audigy2 as "default device".
The manual is here:

ALSA without PulseAudio and PipeWire
_https://dev1galaxy.org/viewtopic.php?id=6644

If you start a new topic, and I will try to help.

NOTE: It is not necessary to remove PulseAudio. You can remove it later, when ALSA is configured and sound works with

apulse firefox 

Some useful commands for testing ALSA, you may find here:
_https://dev1galaxy.org/viewtopic.php?pid=50114#p50114
_https://wiki.archlinux.org/title/Advanced_Linux_Sound_Architecture

Last edited by igorzwx (2024-07-21 13:34:40)

Offline

#24 2024-07-21 16:12:26

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: Resampling and the Gibbs phenomenon with Audacity

If you start a new topic, and I will try to help.

Thank you very much, no help needed.

https://dev1galaxy.org/viewtopic.php?id=6118

Offline

#25 2024-07-21 16:16:36

chris2be8
Member
Registered: 2018-08-11
Posts: 306  

Re: Resampling and the Gibbs phenomenon with Audacity

Could some moderator please move this thread to Off-topic ? It has nothing to do with Devuan.

Offline

Board footer