Hi everyone,
So, I actually tested out ChatGPT’s knowledge of Nyquist to help me build a phase-accurate filter which is supposed to ultimately filter the audio, reverse, filter again, and then reverse back to normal again. However, I’m noticing phase issues when I run this plugin, and I want to be able to just fix this up.
Thanks for your help, the plugin code is below.
;nyquist plug-in
;version 3
;type process
;name “Phase-Accurate Filter…”
;;;categories “LV2”
;action “Applying phase-accurate filter…”
;control filter-type “Filter Type” choice “High-pass,Low-pass” 0
;control rolloff “Rolloff (dB/octave)” choice “6,12,24,36,48” 0
;control frequency “Cutoff Frequency (Hz)” real “” 1000 1 20000
(defun apply-filter (sig)
(let* ((funcs (if (= filter-type 0)
'(hp highpass2 highpass4 highpass6 highpass8)
'(lp lowpass2 lowpass4 lowpass6 lowpass8)))
(func (nth rolloff funcs)))
(funcall func sig frequency)))
;; Apply forward filter
(setq forward (apply-filter s))
;; Reverse
(setq reversed (reverse forward))
;; Apply second filter pass (to reverse-time signal)
(setq filtered (apply-filter reversed))
;; Reverse back to original
(reverse filtered)
ChatGPT is not good at programming in Nyquist. It makes many errors and frequently hallucinates.
As you correctly identified, Nyquist’s built-in filters have frequency dependent phase shift. This is because they are IIR Butterworth filters, and frequency dependent phase shift is a characteristic of IIR filters.
To avoid the phase shift issue, you would need to write your own linear-phase filter. Designing this kind of filter is fairly complex and really requires some knowledge of DSP, but fortunately there is an example included with Audacity. The Spectral Delete effect uses linear-phase filters.
You could could copy the filter design from the spectral-delete.ny plug-in.