Page 5 of 7

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Mon Jan 19, 2015 5:58 am
by Paul L
Videogamer555 wrote:Currently, when you select a band (say 100 Hz to 10000 Hz in this example), it uses the logarithmic center, REGARDLESS of which mode you are using for spectrogram. The center frequency is thus 1000 Hz. This should be the selection method ONLY when using the logarithmic spectrogram. When in the linear spectrum mode, it should use the LINEAR center instead, which would be 5050 Hz in this example. You see (100+10000)/2=5050. Sadly, this doesn't work in Audacity. My use of the program is for scientific/technical use, which PRIMARILY uses linear spectrograms for filtering. In this use, the center frequency refers to the midpoint between high_freq and low_freq. That is in general center_freq = (low_freq + high_freq) / 2. Bandpass means keep all frequencies in the range low_freq to high_freq (and reject all other frequencies) and try to keep the pass band as flat as possible, but if there must be one point which is higher than the rest it should be at the center_freq (aka mid_point) which I defined in the previous sentence.
Well, I simply, respectfully disagree with those shoulds. I think you are confusing the two questions of how to visualize sound, and how to define a filtering effect that modifies a sound.

The purpose of spectral selection is just a visual aid in choosing a band that you then apply a filtering effect to, and what the filter does has no dependency on how you happen to display the sound. So I don't understand what "using a spectrogram for filtering" means. A spectrogram is only a view.

If you want to define FFT based filtering effects using the spectrum (I do not say "spectrogram"), again, that's really independent of how you happen to view things: the window size and windowing function in the effect might very reasonably be quite independent of what you happen to use for the different purpose of display settings. Noise removal does this sort of thing in fact, but its window size is a constant unaffected by spectrogram preferences for view.

Therefore I think "center frequency" as displayed by the black line should be a function of the top and the bottom frequencies, independent of the vertical scale, and the more often useful function is geometric mean. If you switch view type, the black line will remain at the same frequency, however that may map to the vertical scale, and that is to my mind the less surprising behavior than the alternative.

If you think the arithmetic mean is sometimes more useful, you must be talking about a different kind of effect -- NOT a different kind of view.

If you can express the sort of filtering you want to do as a function of top and bottom frequencies in Nyquist Lisp code, then do so, with the understanding that the center frequency line that is displayed as a convenience for the more usual filters is not necessarily useful in that case.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Mon Jan 19, 2015 8:25 am
by Robert J. H.
The geometric mean isn't necessarily proper for all cases.
However, it is meaningful when we deal with energy or power.


Here is a text file with the levels after applying the Fir filter I've promised above.
Fir-Filter-Output.txt
(33.07 KiB) Downloaded 50 times
As with a FFT filter, the center could as well be the arithmetic mean--if the slopes are identical for lower and upper boundaries.
The Parameters were:
- Band stop
- Center frequency 5000 Hz
- Band with 6000 Hz
- Ripples 0.003 (compared with unity 1.0)
- Transition width ~100 Hz (For F0 and F1)

Note that the corner frequencies have a level of -6 dB and not -3 dB as with analog prototypes.

The highest attenuation is rather 5000 Hz then 4000 for this filter typ (windowed Fir filter).
You can check it by sorting the numbers in e.g. Excel.

The number of tabs (length of the convolution kernel) is automatically calculated with the formulae by Kaiser.
The length can easily go up to e.g 10000 tabs for a narrow transition like in the following chirp with a bandstop between 400 and 800 Hz:
chirp filtered.mp3
(110.2 KiB) Downloaded 95 times

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Mon Jan 19, 2015 5:47 pm
by Paul L
When I switch between a spectrogram and spectrogram log f view, I expect to see the same data, only differently scaled on the vertical axis. That was true of the colors, and that is true of the new solid and dashed lines. But showing the geometric mean in one view and the arithmetic in another would go against that principle.

It might be useful to see the arithmetic mean frequency. That might be a worthwhile future enhancement. Maybe both centers could be shown at once, or maybe spectrogram preferences could choose to show one or the other.

But again, I would want to see the same data, only differently scaled, when I switch views. If the linear spectrogram showed arithmetic mean, then the logarithmic view would also draw a line at the same frequency, even though in that view, the line is not at the center as measured in pixels.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Mon Jan 19, 2015 8:08 pm
by Gale Andrews
Paul L wrote:It might be useful to see the arithmetic mean frequency. That might be a worthwhile future enhancement. Maybe both centers could be shown at once, or maybe spectrogram preferences could choose to show one or the other.

But again, I would want to see the same data, only differently scaled, when I switch views.
+1 to both those paragraphs, though I'd guess Spectrograms Prefs would show one mean or the other, and default to geometric mean.


Gale

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Mon Jan 19, 2015 8:26 pm
by Robert J. H.
Paul L wrote:When I switch between a spectrogram and spectrogram log f view, I expect to see the same data, only differently scaled on the vertical axis. That was true of the colors, and that is true of the new solid and dashed lines. But showing the geometric mean in one view and the arithmetic in another would go against that principle.

It might be useful to see the arithmetic mean frequency. That might be a worthwhile future enhancement. Maybe both centers could be shown at once, or maybe spectrogram preferences could choose to show one or the other.

But again, I would want to see the same data, only differently scaled, when I switch views. If the linear spectrogram showed arithmetic mean, then the logarithmic view would also draw a line at the same frequency, even though in that view, the line is not at the center as measured in pixels.
I agree.
The current center line splits the rectangle into halves of equal power, that's certainly the most physical approach.
The real arithmetic mean line should at best be faint, e.g. dotted, if displayed too.

The important lines are the upper and lower boundaries.
We should ensure that the Spectral Edit Filters act around this points (-3 dB or -6 dB for digital or critical damped prototypes).
As I said before, the high and low shelves seem to affect a wider range than expected.

There's the possibility to restrict the filters to work strictly within the bounds displayed and some formulae are available to move the corner points inwards. I have to check them out.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Tue Jan 20, 2015 12:31 am
by steve
Robert J. H. wrote:As I said before, the high and low shelves seem to affect a wider range than expected.
As per the Nyquist Eq-highshelf and Eq-lowshelf commands (http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index451) the defined frequency point is the half gain point and (unlike high pass and low pass filters) is not the -3 dB point. In other words the filter frequency is defines as the mid point of the transition slope.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Tue Jan 20, 2015 6:26 am
by Robert J. H.
steve wrote:
Robert J. H. wrote:As I said before, the high and low shelves seem to affect a wider range than expected.
As per the Nyquist Eq-highshelf and Eq-lowshelf commands (http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index451) the defined frequency point is the half gain point and (unlike high pass and low pass filters) is not the -3 dB point. In other words the filter frequency is defines as the mid point of the transition slope.
I'm aware of the -6 dB point.
In a peaking eq, the main goal is to reverse a e.g. -20 dB cut with a 20 dB boost to get the original back.
But the point is that I get -9 dB at 2000 Hz.
Paul's mid-shelf function is:

Code: Select all

(defun mid-shelf (sig lf hf gain)
  "Combines high shelf and low shelf filters"
  (let* ((invg (- gain)))
    (scale (db-to-linear gain)
           (eq-highshelf (eq-lowshelf sig lf invg)
                         hf invg))))
I just wonder if this is the correct way of implementing this.
The manual says:
Depending on how the track is displayed and what spectral selection has been made, this effect will do one of the following:
(snip)
• When the spectral selection begins at 0 Hz this effect applies a low frequency shelving filter with a rolloff of 6 dB/octave and with the half-gain frequency defined by the upper boundary of the spectral selection. The gain control sets the amount of low-frequency boost or cut. This is similar to adjusting the bass control on a stereo.
• When the spectral selection ends at the Nyquist frequency of the track this effect applies a high frequency shelving filter with a rolloff of 6 dB/octave and with the half-gain frequency defined by the lower frequency of the spectral selection. The gain control sets the amount of high-frequency boost or cut. This is similar to adjusting the treble control on a stereo.
• When the spectral selection has a center frequency and an upper and lower boundary, this effect performs as both low- and high-frequency shelving filters. In this case the half-gain frequency of the low-frequency shelving filter is defined by the lower boundary of the spectral selection and the half-gain frequency of the high-frequency shelving filter is defined by the upper boundary of the spectral selection. The rolloff for both filters is 6 dB/octave. The gain control sets the amount of boost or cut applied between the lower and upper frequencies.
The correct replacement for the "mid-shelf" filter is EQ-band (which is already used for the parametric Spectral Edit). At least, slope and corner frequencies should be analysed and corrected if necessary.

On the other hand, if we take the first sentence:
• When the spectral selection has a center frequency and an upper and lower boundary, this effect performs as both low- and high-frequency shelving filters.
This would imply that all outside the selection would be cut or boosted.
This would make sense since the inner side is already covered with the parametric eq (which has a better behaviour anyway, from a cut of perspective that is).

BTW Is 6 dB roll-off correct? The filter order is already 2, the minimum for such "active" types.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Tue Jan 20, 2015 8:47 pm
by Robert J. H.
steve wrote:
Robert J. H. wrote:As I said before, the high and low shelves seem to affect a wider range than expected.
As per the Nyquist Eq-highshelf and Eq-lowshelf commands (http://www.cs.cmu.edu/~rbd/doc/nyquist/ ... l#index451) the defined frequency point is the half gain point and (unlike high pass and low pass filters) is not the -3 dB point. In other words the filter frequency is defines as the mid point of the transition slope.
Sorry, my fault, I've interpreted the half-gain point wrong.
Meant is of course the gain entered by the user.
For a 24 dB cut, the low and high frequency points will be 12 dB lower than they were previously.

As for the roll-off, It is neither 6 dB nor 12 dB nor any fixed value.
It depends on the actual gain.
For example, a 72 dB cut gives those averages:

Code: Select all

2 octaves	12.08
4 octaves	12.02
6 octaves	11.17
8 octaves	8.97
Note that those 8 octaves are the whole transition width.
The only thing that we can say with certainty is that the slope is greatest around the corner frequencies.
The 6 dB roll-off should therefore be removed unless we provide a reference/sample gain setting.
Note also: There's no guaranty that the center frequency is cut or boosted by the set gain value, namely if the gain is rather high and the bandwidth is too narrow (which is practically always the case).

In conclusion, I find this effect superfluous and not suited for a spectral selection due to its unpredictable outcome.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Tue Jan 20, 2015 10:15 pm
by steve
Robert J. H. wrote:BTW Is 6 dB roll-off correct?
No, that was an error. The slope of the shelf filters is (approx) 12 dB per octave over the linear part of the transition slope.
Robert J. H. wrote:As for the roll-off, It is neither 6 dB nor 12 dB nor any fixed value.
It depends on the actual gain.
It may help to think of it as a hill.
You are walking along a level road, then you encounter a hill. The hill may go up to a higher level (positive gain), or down to a lower level (negative gain). The road is level at both the top and bottom of the hill.
If you walk from the bottom of the hill (where the road is flat) and start to ascend the hill, the road gradually starts to slope upward. As you continue to ascend, the slope becomes a constant 12 dB per octave. As you approach the top of the hill, the slope gradually becomes less steep and eventually levels out as you reach the top.

If it is a small hill, the "constant slope" section will be short, in fact there may not be much of a constant slope section at all.
If it is a large hill, the constant slope section will be much longer.

Regardless of how high the hill is, the slope when you are half way up the hill is 12 dB per octave for a second order shelf filter with a Q of 1.0.

Bringing it right back to our filter; the greater the gain (positive or negative), the greater the width of the transition (the longer the hill is), but the slope at the mid-point remains the same.

Re: Suggestion (Bandpass Filter and Custom FFT Filter)

Posted: Tue Jan 20, 2015 11:44 pm
by Robert J. H.
steve wrote:
Robert J. H. wrote:BTW Is 6 dB roll-off correct?
No, that was an error. The slope of the shelf filters is (approx) 12 dB per octave over the linear part of the transition slope.
Robert J. H. wrote:As for the roll-off, It is neither 6 dB nor 12 dB nor any fixed value.
It depends on the actual gain.
It may help to think of it as a hill.
You are walking along a level road, then you encounter a hill. The hill may go up to a higher level (positive gain), or down to a lower level (negative gain). The road is level at both the top and bottom of the hill.
If you walk from the bottom of the hill (where the road is flat) and start to ascend the hill, the road gradually starts to slope upward. As you continue to ascend, the slope becomes a constant 12 dB per octave. As you approach the top of the hill, the slope gradually becomes less steep and eventually levels out as you reach the top.

If it is a small hill, the "constant slope" section will be short, in fact there may not be much of a constant slope section at all.
If it is a large hill, the constant slope section will be much longer.

Regardless of how high the hill is, the slope when you are half way up the hill is 12 dB per octave for a second order shelf filter with a Q of 1.0.

Bringing it right back to our filter; the greater the gain (positive or negative), the greater the width of the transition (the longer the hill is), but the slope at the mid-point remains the same.
This instant slope is the maximum and only achievable for big gain corrections.
Those are the instant slope values for a cut 0 to -48 dB. They are extrapolated from a 2 cents frequency difference around 1000 Hz.
As you can see, we do never reach 12 dB instant slope within the shelf effect limits (-/+24 db).
It is therefore not advisable to mention any roll-off in the manual.

Code: Select all

0	-0.000310632
-1	-0.70118
-2	-1.39588
-3	-2.0859
-4	-2.7609
-5	-3.41867
-6	-4.05475
-7	-4.66312
-8	-5.24713
-9	-5.80783
-10	-6.33757
-11	-6.83832
-12	-7.30301
-13	-7.73935
-14	-8.14473
-15	-8.51906
-16	-8.86233
-17	-9.18496
-18	-9.47794
-19	-9.74418
-20	-9.98757
-21	-10.2079
-22	-10.405
-23	-10.5901
-24	-10.7576
-25	-10.8992
-26	-11.0358
-27	-11.1566
-28	-11.27
-29	-11.3717
-30	-11.4508
-31	-11.5251
-32	-11.6024
-33	-11.6692
-34	-11.7218
-35	-11.7693
-36	-11.8159
-37	-11.8506
-38	-11.8907
-39	-11.9245
-40	-11.9461
-41	-11.9733
-42	-11.9991
-43	-12.0092
-44	-12.0291
-45	-12.0386
-46	-12.0549
-47	-12.0645
-48	-12.0753