# Sample level n-pass filter

An n-pass filter is a filter that reduces certain frequencies.

A sample level filter is a filter that only checks neighboring samples by a small amount.

Sample level low-pass filter: An output sample x are input samples (x-1)×0.25, (x)×0.5 and (x+1)×0.25 added together. There is a checkbox for x-1 and x+1 to overflow (first-1=last, last+1=first).

Sample level high-pass filter: An output sample x are input samples (x-1)×-0.25, (x)×0.5 and (x+1)×-0.25 added together. There is a checkbox for x-1 and x+1 to overflow (first-1=last, last+1=first).

And it is impossible to reproduce with current Audacity, as there isn’t any exact volume input in Normalize (the dB input is limited to 2 decimal places, not even 16-bit precision; please implement more decimal places AND an unencoded volume input).

In fact, it’s possible to generalize these sample-level n-pass filters, producing a family of n-pass filters that work by duplicating, shifting, amplifying and combining.

For example, here is a cosine generalization that is essentially twice the size of the original sample-level low-pass filter: (x-3)×0.03661165, (x-2)×0.125, (x-1)×0.21338835, (x)×0.25, (x+1)×0.21338835, (x+2)×0.125 and (x+3)×0.03661165 added together.

What will happen, if a sinc generalization is used?

If you really want to do this sort of thing, you need to use MatLab, or Octave, or Nyquist.
Of those three, Nyquist is by far the easiest to learn and use, and it is built into Audacity.
The other two are unrelated to Audacity, and have their own support channels.

Looking at your original post, if we ignore the bit about “overflow”, then it is a kind of averaging filter that may be achieved in just a few lines of Nyquist code.
These examples can be run in the Nyquist Prompt effect, and require a fairly recent version of Audacity. They are not full plug-ins, though they could easily be made into full plug-ins, but are to illustrate how you would approach this type of task in Audacity. I don’t use MatLab or Octave, so I can’t help with either of those.

``````;version 4
;control type "Filter type" choice "Low pass,High pass" 0

(setf type (1+ (* type -2)))

(defun filter (sig)
(let ((d (/ len)))
(sum
(mult type 0.25 (extract (* 2 d) 1 sig))
(mult 0.5 (extract d 1 sig))
(mult type 0.25 sig))))

(multichan-expand #'filter *track*)
``````

If all you are interested in is the frequency response of the filter, then it is even easier:

``````;version 4
;control type "Filter type" choice "Low pass,High pass" 0

(if (= type 0)
(lowpass2 *track* (/ *sound-srate* 4) 0.57)
(highpass2 *track* (/ *sound-srate* 4) 0.57))
``````

It gets a little more complicated to add the “overflow” samples, and in most cases it will just create a click at the start and/or end, but it can be done like this:

``````;version 4
;control type "Filter type" choice "Low pass,High pass" 0
;control loop "Loop boundary values" choice "Yes,No" 0

(setf type (1+ (* type -2)))

(defun sample (val)
(snd-const (* type 0.25 val) 0 *sound-srate* (/ *sound-srate*)))

(defun sampleval (sig n)
(if (= loop 0)
(abs-env (sref sig (/ n *sound-srate*)))
0))

(defun filter (sig)
(let ((d (/ len))
(first (sampleval sig 1))
(final (sampleval sig (1- len))))
(if (= loop 0)
(sum
(sample final)
(mult type 0.25 (extract (* 2 d) 1 sig))
(mult 0.5 (extract d 1 sig))
(mult type 0.25 sig)
(at-abs (/ (- len 1) *sound-srate*) (cue (sample first))))
(sum
(mult type 0.25 (extract (* 2 d) 1 sig))
(mult 0.5 (extract d 1 sig))
(mult type 0.25 sig)))))

(multichan-expand #'filter *track*)
``````

The purpose of the integer overflow for these filters is to allow seamless processing on loops.

Normally one would process the audio before making the loop.

If you are starting with a seamless loop and you want to apply effects, then a useful technique is to to repeat the loop 2 times (total of three times, then apply the effects, then make a new loop from the middle 1/3rd. This technique works with most effects, without requiring specially modified effects.