Should I use flat-top windows?

Look at this chart, and look at the description of flat-top windows higher up.

I have also found this freely available paper, with its Appendix D defining many such functions.

Could these have application for my click finding and repairing tools?

It looks like a lot of leakage for low bin numbers, and very little “scallop loss,” and then a steep drop and very little leakage for large numbers. This could be just what I need.

If I want to detect clicks and then fix them with a filter built with eq-band, then scanning the sound with such a windowing function may be best to determine the gain in a band with the least contamination with information from other bands.

I am not using snd-fft, but rather, for each test frequency I convolve the sound with a period of the cosine. That is like doing fft with a rectangular window as long as that period and a skip of 1 but only calculating one coefficient. That means I have leakage as for the rectangular window, with the bin size equal to the frequency, and so with the first zero an octave above my frequency, right?

Perhaps instead I should take a window containing several periods and multiply by a flat top windowing function, then convolve with that. Choose the right number of periods, and I can get a better controlled flat-top leakage for a band of my choosing.

Choose just a few equal sized bands in the logarithmic frequency scale, wide enough to cover the range of interesting frequencies and catch the clicks, and just many enough to separate low bumps and high crackles from the desirable speech frequencies, and (what might be the same thing) also many enough to make the equalization curve applied to the clicky region sufficiently discriminating to pass what it should pass.

I am thinking now this is the way to improve quality of results for calculation time.

That sounds like a reasonable theory.
The way that I would probably approach it would be to split the windowing code out into a standalone function, making it easy to change the window type. You can then compare the results of using different windows.

Or should I abandon the use of convolutions and instead make a band-stop by composing eq-lowshelf and eq-highshelf?

I meant *band-pass

Bandcut filters created by combining high and low shelf filters are simple to implement. Are they steep enough for your needs? (if the slope is > 1 the passband response gets a noticeable peak in its frequency response).

I was just playing with eq-highshelf with negative gain and watching what it does to the frequency of white noise. I see what happens with high slopes. The response isn’t a simple slope, it’s a wobble up, then far down, then up again to the level specified.

The convolution, though, is not very slow to compute, and the spectrum of transformed noise looks just like the central lobe in the Wikipedia illustration! The lobe is steep and the other lobes are invisible. The before and after spectrogram looks like what you expect: unchanged in the middle, zero top and bottom, short transitions.

Here is a demonstration. The paper I linked to has various other combinations of coefficients in Appendix D.

The greater n-periods, the narrower and steeper the band.

(defun cosine-periods (srate freq n-periods)
  (snd-osc (first *sine-table*) (second *sine-table*)
	       srate freq 0.0 (/ n-periods freq) 90.0))

(defun flat-top-window
  (srate dur)
  ;; reference
  (let ((coefficients '(1.0 -1.93 1.29 -0.388 0.028))
	(freq (/ dur)))
    (do ((result (snd-const (car coefficients) 0.0 srate dur)
		 (sum result
		      (prod (car remaining)
			    (cosine-periods srate (* ii freq) ii))))
	 (ii 1 (1+ ii))
	 (remaining (cdr coefficients) (cdr remaining)))
	((not remaining) result))))

(defun compute-convolution-window (srate frequency n-periods)
  (let ((windowing-function
	 (flat-top-window srate (/ n-periods frequency))))
    ;; the coefficient is such that convolving the window with
    ;; a sinusoid of the same frequency would leave amplitude unchanged.
    (prod (* (if (oddp n-periods) -2.0 2.0) frequency (/ (* n-periods srate)))
	  (cosine-periods srate frequency n-periods))))

(convolve s (compute-convolution-window 44100.0 5000.0 10))

That’s really clever. Sadly my mathematical knowledge does not extend to such things, though I can see in practical terms how it is working, and it’s :ugeek:

I have not yet got decisively better results with these windows but I will keep trying. To make them useful I may need to convolve with a bigger window containing more than one period of the cosine of the test frequency so that the lobe is narrowed. That slows the computation so I might trade off against fewer test frequencies. For that matter broadening the window could be tried even for the rectangular window.

The goal is best detection and repair for the computation time. That might take a lot of experiment with many parameters. But meanwhile my original approach is still very good and perhaps worth sharing before I find the best fine tunings.

I have also found an unrelated simple change that stops the excessive cutting of stop consonants, which are bursts of noise you want to hear for a sense of articulate spech; and still cuts out the crackles in the vowels and the rattles in the sibilants. This change does not make fewer labels but it passes a lesser gain cut value to the repair procedure.

You seem better acquainted with the stuff than I am yet, I’ve just learned enough to be dangerous cobbling the right pieces together, and sometimes I think I am dabbling ignorantly with :smiling_imp: