Skip to content

Bring back linear scale for visualizer (or an option for it) #453

Open

Description

@whooie

The use of log scaling may make the visualizer output conform better to human perception, but it tends to remove some of the most interesting things you can get from a looking at a short-time Fourier transform.

The key reason for this is that the FT here is displayed using terminal characters, which has the effect of binning everything together into discrete cells that are spaced linearly across a window. Since log scales compress numbers of large magnitudes together and here you can't change the size of your terminal characters, this greatly reduces your ability to resolve differences between loud and/or high-frequency components of your music. Normally this isn't a problem when you just look at a regular plot because your pixels are pretty much always small compared to the scale of the plot, but here the "pixels" are comparatively huge.

Additionally, a key mathematical feature of the FT is the natural trade-off between time resolution and frequency resolution. Essentially, the FT demands that in order to obtain good resolution (that is, the ability to determine which frequencies are present and at what amplitude/intensity in a given signal) at low frequencies, you need to give it a data recorded over a long period of time. At high frequencies, the trade-off is reversed: good resolution demands a lot of data that can be recorded over a shorter period of time. Music files are time-binned on the order of a few tens of kHz to take care of the high-frequency end, but when we take the short-time FT here, we're forced to lose out on the low-frequency trade-off.

So when you plot a short-time FT on a log-log scale and then try to display it on a terminal window, everything on the low-frequency end, where the resolution coming from the FT is already poor, gets stretched out over your screen, while everything on the high-frequency end, where the STFT can offer most of its resolution, gets squished into only a few columns in a terminal.

This is particularly frustrating when looking at sounds like -- for example -- those coming from stringed/brass instruments or even synthesized signals, where the major Fourier components occur not over the span of musical octaves, but over discrete (linearly spaced) frequency intervals. On a linear frequency scale, you could see these harmonics clear as day, but on a log scale they all end up getting squished together.

I'll add that log scaling on the y-axis is also unfavorable for mostly the same reasons. In addition to the problems that arise when dealing with the projection onto terminal cells, an important detractor is the fact that most music is not very quiet, which means that most of the time, the vertical log scale only further decreases visual contrast between any interesting features that may arise in your STFT.

To demonstrate the problems with the log-log scaling visually, I'll take the STFT of the first 25 Fourier components of a 440 Hz square wave. Here is the original signal:

signal

This is a 1/30-second slice sampled at 44100 Hz. This represents a best-case scenario for what the STFT in ncmpcpp may produce using visualizer_fps = 30 for maximal low-end resolution.

Here is the STFT of this slice, plotted using both scales:

stft_linear

stft_log

On the linear scale, each of the components is separated visually by an equal horizontal distance, which shows clearly the relationship between them. The height of each peak also shows intuitively the correct relationship between the amplitudes of each component, with the leftmost being clearly marked as the fundamental frequency of the signal.

On the log scale, however, it's clear that all of the peaks get squished to the right, which decreases your ability to differentiate between neighbors and is exacerbated in the limit of large pixels. Also, the height of each peak compared to the background (its contrast) is decreased, meaning that when other signals at other fundamental frequencies are added in, it will be very difficult to identify these features. It's also clear from the broadening of the lower-frequency peaks that the relatively poor STFT resolution at low frequencies is also exacerbated by the log scale.

[EDIT: One other thing I'll add regarding the contrast between the peaks on the vertical log scale is that since this is an artificially created signal, we know that the STFT should find exactly zero amplitude at all frequencies other than those where it has already found peaks. To this end, the log scale on the vertical axis does another disservice to the information being conveyed by showing that the background behind the peaks is not as close to the bottom of the plot as it is when plotted on the linear scale.]

I understand why some people would prefer the log-log scale, but please understand that sometimes the point of applying some kind of analysis (such as the STFT) is to produce a result that expressly does not conform to the human experience, in order to reveal information that we may not have otherwise detected. The switch to log-log scaling in the visualizer has come with extremely severe detriments to its ability to be a useful feature, and I sincerely hope that you will consider switching back to the linear scale, or at least provide a configuration option that allows users to do so for themselves.

Activity

  1. arybczak commented on Feb 24, 2021

    @arybczak
    Collaborator

    It can be brought back as an option (e.g. visualizer_spectrum_log_scale), sure. PRs welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions