"Ringing"?

A "new fashioned" televisor, using an Arduino to drive the motor and display.

Moderators: Dave Moll, Andrew Davie, Steve Anderson

"Ringing"?

Postby Andrew Davie » Mon May 29, 2017 6:17 pm

Here's someting that's been bugging me for a while - brought back to mind by discussion of "ringing" in this post.

What I seem to see on my televisor's picture near the black frame division at bottom of every frame is a sort of "ripple" or "ringing" of white horizontal lines which appear to get less visible and closer together as one goes up the frame. I suspect this is a byproduct of the resampling that I have done on the original image converting from (say) 48kHz down to 19200 Hz. Is it the case that when downsampling, one gets time-shifted artefacts in audio data that becomes visible as artefacting in a picture? I could do a picture to show, but hopefully I have described well enough. And if this IS the reason, is it because of the resampling algorithm, or is it an innate problem when downsampling?

Edit: I did a picture....

ring2.png
ring2.png (84.16 KiB) Viewed 13796 times


The red lines show the horizontal location of a few "white" lines at the bottom of a frame - data converted via audacity 48kHz original to a 19200Hz final.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: "Ringing"?

Postby gary » Tue May 30, 2017 8:45 pm

It's Gibb's phenomenon Andrew without going into great detail it is the oscillations or ringing that occur in a band limited signal at a discontinuity such as the edge of a square wave when a Fourier series is taken (usually when brick wall filtering as is required for a 19200 hz signal with a 9600 hz bandwidth). It is a result of there being a finite number of sine waves available when the signal requires an infinite number of sine waves (as does a square wave).

The only solution is to remove the discontinuity - which in this case appears to be the sync pulse - by smoothing (reducing the higher frequencies with a less sharp filter response).

This example indicates that prior to resampling (and hence filtering) it would be a good idea to remove the sync pulses which are effectively square waves. If needed they can be added back after the processing.

It is interesting to note that as the apertures of a Nipkow disk represent a low pass filter you would expect the same phenomenon to be exhibited there if a black bar or similar is displayed. There is evidence that it does occur on Nipkow disk based camera but I have yet to notice it on a monitor - I have always put that down to the fact that a scan line on a Nipkow disk represents an infinite sequence of overlapped samples.

PS: Please excuse my poor punctuation. My comma key is not working and I have done my best to work around that.
gary
 

Re: "Ringing"?

Postby Andrew Davie » Mon Jun 05, 2017 1:16 am

Thanks for the explanation. This is bothering me. If I consider the WAV file as a series of pixels, and do an image-processing resample on those pixels, then I will not get any artefacting like this, surely? It seems that the "Gibb's artefacts" are because of the assumption that we have a sound file and pixels are represented by an (infinite) sum of sine waves. That I understand. But I could, for example, write a simple program to resample 120 pixel scanlines (48KHz) to 48 pixel scanlines (19.2KHz). Then I wouldn't have any issues with "square wave discontinuities" because in fact each pixel is not a sum of sine waves, or an approximation - it's an exact value from 0-255. A resampled pixel is representing the averaged brightness of whatever span of pixels were being processed. There would be no "ripple", I think? Each pixel would be the average of the spanning 2.5 pixels (120/48). I can't see how a sharp discontinuity like the framing division would introduce sine-wave based artefacts in other pixels. A black band would simply dim the pixels adjacent. This, if processing as an image.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: "Ringing"?

Postby Klaas Robers » Tue Jun 06, 2017 10:28 pm

The point is indeed that Audacity sees the files of samples as sound. By down sampling from e.g 48 kHz to 16 kHz all spectrum (tones) from 8 kHz to 24 kHz that are present in the 48 kHz wave file, have to be removed BEFORE you can do the down sampling. Otherwise the might give unexpected and false notes in the spectrum below 8 kHz.

This low pass filter with a cut off frequency of 8 kHz is doing nothing for tones of 0 to 8 kHz and should suppress all tones above 8 kHz. Such a sharp filter inhearently introduces ringing on steep edges in the signal. We can't HEAR that ringing, as to our ears this is a natural process.

The way that you suggest, by averaging will not suppress frequencies above 8 kHz, do the process on a file of one pixel black, one pixel white, etc. This 24 kHz still gives modulation in the down sampled file. This effect is called "Aliassing".
User avatar
Klaas Robers
"Gomez!", "Oh Morticia."
 
Posts: 1656
Joined: Wed Jan 24, 2007 8:42 pm
Location: Valkenswaard, the Netherlands

Re: "Ringing"?

Postby Andrew Davie » Tue Jun 06, 2017 10:39 pm

Klaas Robers wrote:The point is indeed that Audacity sees the files of samples as sound. By down sampling from e.g 48 kHz to 16 kHz all spectrum (tones) from 8 kHz to 24 kHz that are present in the 48 kHz wave file, have to be removed BEFORE you can do the down sampling. Otherwise the might give unexpected and false notes in the spectrum below 8 kHz.

This low pass filter with a cut off frequency of 8 kHz is doing nothing for tones of 0 to 8 kHz and should suppress all tones above 8 kHz. Such a sharp filter inhearently introduces ringing on steep edges in the signal. We can't HEAR that ringing, as to our ears this is a natural process.

The way that you suggest, by averaging will not suppress frequencies above 8 kHz, do the process on a file of one pixel black, one pixel white, etc. This 24 kHz still gives modulation in the down sampled file. This effect is called "Aliassing".



Thanks Klaas. I understand your explanation. However, one point - aliasing will only affect adjacent pixels - that is, the effect of a sharp discontinuity like the black band between frames will only affect the pixels over which it is averaged - there will not be effects on pixels "downstream", so to speak. The processing by Audacity introduces ringing I now understand as a part of the filter sharpness, but this won't be present in an image-processing result which will indeed show aliasing, but not extended beyond the pixels directly affected.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: "Ringing"?

Postby Klaas Robers » Tue Jun 06, 2017 11:19 pm

That is true, but averaging, as you suggest, is almost the worst way of filtering. There is no "best" filter. A sharp filter cuts off all high frequencies, but introduces ringing. A filter that gives no ringing only attenuates the frequencies higher than the chosen cut-off and attenuates also frequencies below the cut-off.

For audio ringing is not a problem, so sharp filters can be used and are used, especially in the digital audio world.

For video filters of the "Butterworth" approach give a useable compromise between filtering and ringing.

Filter design is a science on its own. Only a few persons know about that.
User avatar
Klaas Robers
"Gomez!", "Oh Morticia."
 
Posts: 1656
Joined: Wed Jan 24, 2007 8:42 pm
Location: Valkenswaard, the Netherlands

Re: "Ringing"?

Postby ppppenguin » Wed Jun 07, 2017 1:50 am

As Klaas has said, there's no "best" filter. If you're subsampling a signal then you need to reduce the badnwidth of the original. If you use a sharp cutoff filter each output sample will have contributions from many samples both before and after that sample. If the input signal contains frequencies that are in band for the input but out of band for the output you'll get ringing. If you use a gentler filter (such as Butterworth) you'll get less ringing. If you use a Bessel or Gaussian you'll get none at all but high frequency components will be attenuated. At this level choosing the correct filtering can be as much an art as a science. The science tells you what will happen to the signal. Your eyes or ears will tell you what it feels like.

If the original is already aliased (for example a 1 pixel transition from white to black) it's even worse.

In practice a lot of TV systems have inherent vertical alisasing due to the scan lines and all have temporal aliasing. Think of the wagon wheels going backwards in westerns. All you can do is arrive at a compromise that is both technically and visually acceptable. This is why top quality standards conversion is so difficult. Interlace only makes it harder because vertical and temporal information can occupy the same parts of the 2 dimensional YT spectrum. Hence it's not always possible to untangle vertical detail from movement.

One simple case where there's no fully satisfactory answer is converting full bandwidth RGB to YCbCr (YUV) where the chroma components have reduced bandwidth as is the case in almost all TV systems. A sharp cutoff filter gives ringing, a gentler filter loses fine detail. In other words you can't win. You just have to choose the best compromise.
Jeffrey Borinsky www.borinsky.co.uk
User avatar
ppppenguin
Research Scientist
 
Posts: 44
Joined: Fri Nov 04, 2016 5:30 am

Re: "Ringing"?

Postby gary » Wed Jun 07, 2017 8:06 pm

Andrew Davie wrote:Thanks for the explanation. This is bothering me. If I consider the WAV file as a series of pixels, and do an image-processing resample on those pixels, then I will not get any artefacting like this, surely? It seems that the "Gibb's artefacts" are because of the assumption that we have a sound file and pixels are represented by an (infinite) sum of sine waves. That I understand. But I could, for example, write a simple program to resample 120 pixel scanlines (48KHz) to 48 pixel scanlines (19.2KHz). Then I wouldn't have any issues with "square wave discontinuities" because in fact each pixel is not a sum of sine waves, or an approximation - it's an exact value from 0-255. A resampled pixel is representing the averaged brightness of whatever span of pixels were being processed. There would be no "ripple", I think? Each pixel would be the average of the spanning 2.5 pixels (120/48). I can't see how a sharp discontinuity like the framing division would introduce sine-wave based artefacts in other pixels. A black band would simply dim the pixels adjacent. This, if processing as an image.


No, it doesn't matter what the data is, sound, video, population statistics, telemetry, it is all the same, if the data can be represented as a function, it can be represented by sums simpler trigonometric functions - this is called Fourier Analysis and is fundamental to any type of signal processing.

Fourier Analysis was initially developed to help study heat transfer.

But that is a diversion which I have only addressed to show that it doesn't make any difference as to what the signal is ringing will always be present at a discontinuity, that, wherever the slope of the change is infinite.

There are two ways to digitally filter a signal, in the time domain, and in the frequency domain. Filtering has the advantage that what is a complex convolution operation in the time domain is a simple multiplication in the frequency domain, but, effectively they are doing the same thing (it is, if you like, something like using logarithms to make a multiplication a simple add).

When you are averaging, what you are doing what is a fairly simple convolution that has a relatively poor frequency response but quite a good time domain response for certain applications like noise reduction (smoothing).

Andrew Davie wrote:because in fact each pixel is not a sum of sine waves, or an approximation - it's an exact value from 0-255.


Erm, yes and no, it is an exact value but it is the value of a superposition of sine waves - those sine waves are all the frequencies present in the signal, each with it's own amplitude, when you sum them all up at that particular time, you get that exact pixel value.

You actually know this without realising it, all those sine waves together represent the "spectrum" of the signal. When you see the "bars" in a spectrum they represent the amplitude of the sine wave at that particular frequency.

Of course the spectrum is a continuous space (an infinite number of sine waves) but so are the amplitudes (pixels) but by Nyquist's theorem you only need f/2 of them - same thing in the spectrum (frequency domain).

It is actually fair to put an NBTV signal through a brickwall filter as you have done with Audacity because if you took the the original signal and presented it to an NBTV bandlimited transmission system (which is a lowpass filter) you would get the same effect (assuming the bandlimiting is perfect).

It is really not fair to compare digital image processing with a TV signal as an image is two dimensional and a TV signal is one dimensional, however that is not to say you can't do image processing before you send the one dimensional signal such that the discontinuities are removed before hand - but people like Chris Long would (justifiably) complain because you are removing the higher frequencies in that band limited signal - this represents what is known as aperture distortion.

The real culprit in this, as I have indicated before, is the 19200 sample rate - by Nyquist that guarantees either a brickwall filter with ringing, or a "smoothing filter" with aperture distortion.

Here are two reasonable wikipedia articles on the subject:

https://en.wikipedia.org/wiki/Ringing_artifacts
https://en.wikipedia.org/wiki/Spatial_anti-aliasing

It has only recently become aware to me that the forced compromise between ringing and frequency response is an example of the uncertainty principle in action.
gary
 

Re: "Ringing"?

Postby ppppenguin » Wed Jun 07, 2017 8:57 pm

Gary raises several interesting points.

Taking the last one first, I really don't think that sampling theory can be equated with Heisenberg's uncertainty principle. Sampling theory, Fourier, Nyquist etc all emerge naturally from the maths while the uncertainty principle is related to measurement and the presence of an observer. Leads us into difficult metaphysics very quickly.

No, it doesn't matter what the data is, sound, video, population statistics, telemetry, it is all the same, if the data can be represented as a function, it can be represented by sums simpler trigonometric functions - this is called Fourier Analysis and is fundamental to any type of signal processing.


I think there are some functions that don't work properly with Fourier analysis. My maths isn't good enough to demonstrate this but I think that artificial sequences such as infinitely sharp transitions from white to black can fool the system. And give horrible ringing if you try to filter them other than gently.

Quantising (number of bits) is a completely separate argument to sampling. Fourier analysis doesn't involve quantising. If you don't have enough bits then you'll get additional errors above any caused by aliasing but that's not a problem in any well designed system. By proper application of dither any quantising errors can be turned into noise, thus avoiding the posterisation and banding effects you sometimes see. If you don't have enough bits in a filter calculation you can sometimes get overflow or underflow which will cause unexpected additional errors. The output of a filter can always be rounded to any desired number of bits. If done correctly this gives the usual tradeoff between number of bits and noise.

As an aside I once experimented with 1 bit video. Looked evil on monochrome pictures but PAL colour subcarrier was an effective dither signal so coloured parts of the picture looked much better.
Jeffrey Borinsky www.borinsky.co.uk
User avatar
ppppenguin
Research Scientist
 
Posts: 44
Joined: Fri Nov 04, 2016 5:30 am

Re: "Ringing"?

Postby gary » Wed Jun 07, 2017 10:53 pm

ppppenguin wrote:Gary raises several interesting points.

Taking the last one first, I really don't think that sampling theory can be equated with Heisenberg's uncertainty principle. Sampling theory, Fourier, Nyquist etc all emerge naturally from the maths while the uncertainty principle is related to measurement and the presence of an observer. Leads us into difficult metaphysics very quickly.


Er no,
"Historically, the uncertainty principle has been confused with a somewhat similar effect in physics, called the observer effect, which notes that measurements of certain systems cannot be made without affecting the systems, that is, without changing something in a system. Heisenberg offered such an observer effect at the quantum level as a physical "explanation" of quantum uncertainty. It has since become clear, however, that the uncertainty principle is inherent in the properties of all wave-like systems."

In relation to filter design:

"As stated in the uncertainty principle, the product of the width of the frequency function and the width of the impulse response cannot be smaller than a specific constant. This implies that if a specific frequency function is requested, corresponding to a specific frequency width, the minimum width of the filter in the signal domain is set. Vice versa, if the maximum width of the response is given, this determines the smallest possible width in the frequency. This is a typical example of contradictory requirements where the filter design process may try to find a useful compromise."

The Uncertainty Principle is a mathematical concept:

uncertainty.JPG
uncertainty.JPG (12.08 KiB) Viewed 13732 times


Never mind, that was not taught at Uni when I went either.

No, it doesn't matter what the data is, sound, video, population statistics, telemetry, it is all the same, if the data can be represented as a function, it can be represented by sums simpler trigonometric functions - this is called Fourier Analysis and is fundamental to any type of signal processing.


ppppenguin wrote:I think there are some functions that don't work properly with Fourier analysis. My maths isn't good enough to demonstrate this but I think that artificial sequences such as infinitely sharp transitions from white to black can fool the system. And give horrible ringing if you try to filter them other than gently.


Well the data or signal must be periodic, but any set of data can be windowed to appear periodic. Whether that is appropriate or not depends on what you are trying to achieve.
I am struggling to come up with anything that can't be the subject of Fourier Analysis but the number of possibilities is infinite. As far as I am aware the topic is mathematically controversial. Suffice it to say, as an electrical engineer I have yet to come up with anything in my domain that cannot be analysed.

But yes, what you say is perfectly correct, and is indeed, the source of the Gibb's Phenomenon I remarked upon earlier. That transition from "white to black" is the "discontinuity" I refer to - because, as a signal it requires an infinitely steep slope, or zero rise time to instantaneously go from minimum to maximum.

I didn't mention this before as I thought it obvious but maybe it isn't, but the ringing that Andrew has demonstrated above depends very much on the picture content - if the picture he shows above had low greyscale values above the sync pulse the ringing would not be as severe at that point.

ppppenguin wrote:Quantising (number of bits) is a completely separate argument to sampling.

I am not sure why you are bringing that up, I certainly didn't (at least intentionally) - If you are referring to the 0-255 values that Andrew brought up then consider those as a mapping of 0 to 1.0.

ppppenguin wrote: Fourier analysis doesn't involve quantising. If you don't have enough bits then you'll get additional errors above any caused by aliasing but that's not a problem in any well designed system. By proper application of dither any quantising errors can be turned into noise, thus avoiding the posterisation and banding effects you sometimes see. If you don't have enough bits in a filter calculation you can sometimes get overflow or underflow which will cause unexpected additional errors. The output of a filter can always be rounded to any desired number of bits. If done correctly this gives the usual tradeoff between number of bits and noise.


Indeed, there are many aspects of signal processing that need to be taken into account, but we are talking about ringing here so I am not exactly sure of your point unless it was to add another source of error. (LOL I meant "draw attention to another source of error").

ppppenguin wrote:As an aside I once experimented with 1 bit video. Looked evil on monochrome pictures but PAL colour subcarrier was an effective dither signal so coloured parts of the picture looked much better.


Dithering a 1 bit signal is something I need to get my head around. LOL
gary
 

Re: "Ringing"?

Postby Andrew Davie » Wed Jun 07, 2017 11:54 pm

Really interesting discussion and I'm glad I asked the question. For me, a perfect picture may not be the best picture. For example, the first version of "Porridge" that Gary sent me was "ideal" I think but I did not like the visuals at all. I find the sharp discontinuities in pixels very off-putting and much prefer an "averaged" image. However, be that as it may, my televisor is operational once again - the new wiring is all OK, and I'm now able to upload to the Arduino once again. So I took the opportunity to make a better video for analysis/discussion of the effect - although I think we may be all done with that....? I've learned a lot - thanks to all.

This video (from a 1930s film "Magic Rays of Light") perfectly shows the typical singer close-up that we've seen in some of Don McLean's restorations of actual video from the 1930s, particuarly the Woman Singing singing and Betty Bolton. If you look closely at the bottom of frame, just above the black horizontal frame divider, you will see some good clear examples of the ringing we have been discussing. Interesting, though, my default "Doctor Who" video has no sign of this. The two were created through totally different processes/software. The Doctor Who shows it's possible to get really good looking video without the ringing.


youtu.be/szQV-aixNZM
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: "Ringing"?

Postby gary » Thu Jun 08, 2017 12:24 am

Andrew, do you mind sharing the audio file of your "really good looking" Dr Who video please?
gary
 

Re: "Ringing"?

Postby Andrew Davie » Thu Jun 08, 2017 1:20 am

gary wrote:Andrew, do you mind sharing the audio file of your "really good looking" Dr Who video please?


Not at all! Be warned - 100MiBi download! Doctor Who audio file
You might need to right-click "save as" if your browser tries to actually play it :)

Oh yes, don't forget it's in my NBTV8 format!
That's 8-bit video and audio, with video unsigned 8-bit, NO synch pulses. 19200 Hz. Audio signed 8-bit.
12.5fps, 48 pixels high, 32 scanlines. Video left channel, I seem to recall.
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: "Ringing"?

Postby Andrew Davie » Thu Jun 08, 2017 1:28 am

Just stumbled on this - compare my televisor (above) with this MUTR playing exactly the same video (from about 2:20 onwards)...


youtu.be/fTSeUjvScUA
User avatar
Andrew Davie
"Gomez!", "Oh Morticia."
 
Posts: 1590
Joined: Wed Jan 24, 2007 4:42 pm
Location: Queensland, Australia

Re: "Ringing"?

Postby gary » Thu Jun 08, 2017 8:10 pm

Andrew Davie wrote:
gary wrote:Andrew, do you mind sharing the audio file of your "really good looking" Dr Who video please?


Not at all! Be warned - 100MiBi download! Doctor Who audio file
You might need to right-click "save as" if your browser tries to actually play it :)

Oh yes, don't forget it's in my NBTV8 format!
That's 8-bit video and audio, with video unsigned 8-bit, NO synch pulses. 19200 Hz. Audio signed 8-bit.
12.5fps, 48 pixels high, 32 scanlines. Video left channel, I seem to recall.


That seems to have both syncs (albeit not negative going but that makes no difference) and the ringing bars:

Image1.jpg
Image1.jpg (3.94 KiB) Viewed 13706 times


Did you give me the right file?

Or maybe it just isn't very obvious when viewed via a disk.
gary
 

Next

Return to Andrew Davie's Arduino Televisor

Who is online

Users browsing this forum: No registered users and 1 guest