15 releases
0.2.12alpha.0  Apr 7, 2023 

0.2.11alpha.0  Dec 19, 2022 
0.2.5alpha.0  Jun 21, 2022 
0.2.4alpha.0  Mar 14, 2022 
0.1.42alpha.0  Oct 27, 2021 
#24 in #digitalsignalprocessing
399 downloads per month
Used in 3 crates
(2 directly)
455KB
6K
SLoC
surgefxallpass: A Rust crate for allpass filters in the Surge synthesizer
The surgefxallpass
crate is a component of the
Surge synthesizer system that provides
implementations of allpass filters. Allpass
filters are a type of digital filter used in audio
processing that preserve the magnitude of the
signal while changing its phase response. This
property makes them useful for creating a variety
of audio effects, such as reverberation and
phasing.
Token Descriptions

control_group
: The group that a control belongs to. 
control_type
: The type of a control, such as "knob" or "switch". 
default_value
: The default value of a control. 
max_value
: The maximum value of a control. 
min_value
: The minimum value of a control. 
modulateable
: Whether a control can be modulated or not. 
moverate
: The modulation rate of a control. 
value_type
: The data type of a control value. 
OnePoleFilter
: A digital filter that implements a firstorder lowpass or highpass filter. 
process_highpass
: A method that processes an audio block with a highpass filter. 
process_lowpass
: A method that processes an audio block with a lowpass filter. 
calc_size
: A method that calculates the size of a buffer needed for processing. 
update
: A method that updates the filter coefficients. 
update_rtime
: A method that updates the filter coefficients with a specified rise time. 
AllpassPreDelay
: The delay line used in an allpass filter. 
default
: The default constructor for an object. 
process
: A method that processes an audio block. 
AllpassVerb
: A class that implements a reverberation effect using allpass filters. 
AllpassBlockCfg
: A configuration struct for an allpass filter block. 
do_allpass_block
: A method that processes an audio block with an allpass filter block. 
do_process_block
: A method that processes an audio block with a filter block. 
Allpass
: A class that implements a single allpass filter. 
set_len
: A method that sets the length of the delay line. 
allpass_smoke
: A simple test function for the allpass filter. 
AllpassDelay
: A delay line used in an allpass filter.
Mathematical Analysis
Allpass filters are characterized by their phase response, which can be analyzed using the transfer function of the filter. The transfer function of a firstorder allpass filter is given by:
H(z) = (a  z^1) / (1  a*z^1)
where a
is a real coefficient that determines
the amount of phase shift. The magnitude response
of an allpass filter is always equal to one,
regardless of the value of a
. The phase response
of the filter is given by:
phi(w) = 2*atan(a*tan(w/2))
where w
is the frequency in radians and phi
is
the phase shift in radians.
The OnePoleFilter
class implements a firstorder
lowpass or highpass filter. The transfer
function of a firstorder lowpass filter is given
by:
H(z) = b / (1  a*z^1)
where b
and a
are real coefficients that
determine the cutoff frequency and damping
respectively. The transfer function of
a firstorder highpass filter is given by:
H(z) = (1  a*z^1) / (1 + b*z^1)
where b
and `a
131> how does an allpass filter work from a physical perspective?
An allpass filter is a type of signal processing filter that changes the phase response of a signal without affecting its magnitude response. This is achieved by delaying part of the signal by a certain amount of time and then mixing it back with the original signal.
From a physical perspective, allpass filters can be implemented using various analog circuits, such as passive RC networks, active opamp circuits, or digital signal processing algorithms. In analog circuits, the delay can be introduced using capacitors or inductors, while in digital circuits, the delay can be introduced using a delay line or a buffer.
One example of an allpass filter in the analog domain is the phaseshift oscillator, which is a circuit that consists of an amplifier and a feedback network containing capacitors and resistors. This circuit generates a sinusoidal output signal with a fixed frequency, and the phase shift introduced by the feedback network can be adjusted by changing the values of the capacitors and resistors.
In the digital domain, allpass filters can be implemented using difference equations that describe the filter's inputoutput relationship. One common digital allpass filter is the firstorder allpass filter, which has a transfer function of the form:
H(z) = (a  z^(1)) / (1  a*z^(1))
where z^(1) denotes a unit delay, and a is a coefficient that determines the amount of phase shift introduced by the filter. This filter can be used to create a variety of effects, such as phasing, flanging, and reverberation, by modulating the coefficient a over time.
Overall, allpass filters are useful tools in signal processing and can be used for a variety of applications, such as equalization, time delay, and phase manipulation.
132> what about from the perspective of various branches of mathematics?
From a mathematical perspective, an allpass filter can be described using concepts from linear systems theory, signal processing, and complex analysis.
In linear systems theory, an allpass filter is a type of linear filter that alters the phase of a signal while leaving the amplitude unchanged. This property makes allpass filters useful in applications where preserving the shape of the signal's frequency spectrum is important, such as in audio processing.
In signal processing, allpass filters are used in various audio applications, such as reverb and equalization. They are particularly useful in reverb algorithms because they can be used to create a dense and diffuse reverb tail without altering the frequency content of the original sound. In equalization applications, allpass filters are used to adjust the phase response of a signal without affecting its frequency response.
From the perspective of complex analysis, an allpass filter can be viewed as a function that maps a complex number z to another complex number z' such that the angle between z and z' is preserved while the magnitude of z' is scaled by a constant factor. This mapping can be represented by a transfer function in the zdomain, which is a rational function in the complex variable z.
In summary, the allpass filter is a fundamental concept in both signal processing and linear systems theory. Its phasealtering properties make it an essential tool in audio processing, and its mathematical properties can be analyzed using concepts from complex analysis.
133> what about from ring theory?
From the perspective of ring theory, an allpass filter can be seen as a special case of a linear operator on a finitedimensional vector space over a field, where the field is the ring of complex numbers.
In particular, an allpass filter can be represented as a matrix A in the form:
A = a0 I + a1 T + a2 T^2 + ... + an T^n
where I is the identity matrix, T is a shift operator that shifts the values of a sequence to the right, and a0, a1, ..., an are complex coefficients. The matrix A is sometimes called a companion matrix.
The eigenvalues of A determine the frequency response of the filter, and the eigenvectors of A determine the impulse response of the filter. In particular, an allpass filter has a constant magnitude response across all frequencies, but its phase response can be nonlinear. The phase response is determined by the roots of the polynomial p(z) = a0 + a1 z + ... + an z^n, which are the eigenvalues of the companion matrix A.
Ring theory provides a framework for studying linear operators and their properties, such as eigenvalues and eigenvectors. By representing an allpass filter as a linear operator on a vector space, we can use techniques from ring theory to analyze the filter's behavior and properties.
134> what about from the perspective of the chinese remainder theorem?
The Chinese Remainder Theorem (CRT) is a theorem from number theory that describes how to solve a system of linear congruences. It has applications in various areas of mathematics, including algebraic number theory and cryptography.
In the context of digital signal processing and specifically allpass filters, the CRT can be used to design allpass filters with arbitrary phase responses. The idea is to choose the coefficients of the filter based on a set of constraints given by the CRT, which allows for a more flexible design compared to traditional methods. This approach is called the Chinese Remainder Filter (CRF) method.
The CRF method works by defining a set of residue values that the filter must satisfy modulo some prime numbers. The coefficients of the filter are then determined by solving a set of linear equations derived from the residue values using the CRT. The resulting filter has a phase response that is determined by the residue values and can be adjusted by changing them.
The use of the CRT in allpass filter design is an example of the connection between seemingly disparate areas of mathematics. By applying concepts from number theory to signal processing, new techniques for designing filters can be developed that are more efficient or flexible than traditional methods.
135> what about from the context of the spectral decomposition?
From the perspective of spectral decomposition, an allpass filter can be seen as a filter that leaves the magnitude spectrum of a signal unchanged while modifying the phase spectrum. This is because the transfer function of an allpass filter can be expressed as:
H(z) = (a + bz^1) / (1 + bz^1 a)
where a and b are filter coefficients. The magnitude of H(z) is unity for all frequencies, meaning that the filter does not change the amplitude of any frequency component of the signal. However, the phase of H(z) changes with frequency, and it is this phase shift that produces the filtering effect.
The phase response of the filter is given by:
φ(ω) = tan^1[(ω/G  G/ω)/(1 + G^2)]
where G = √(1a^2)/a, and ω is the angular frequency. The phase shift is proportional to ω, and the slope of the phase response at a given frequency is proportional to the filter coefficient b. The slope can be positive or negative, depending on the sign of b.
The allpass filter can be used in combination with other filters to achieve various filtering effects, such as equalization, reverberation, and phase shifting. By carefully adjusting the filter coefficients, it is possible to create complex filter responses that meet specific design goals.
136> what about from the context of partial differential equations?
In the context of partial differential equations, allpass filters can be understood as a particular type of wave equation. A wave equation describes the motion of a wave in a medium, and can be expressed mathematically as:
∂²u/∂t² = c²∇²u
where u is the wave, t is time, c is the speed of the wave, and ∇² is the Laplacian operator.
An allpass filter can be viewed as a type of waveguide, which is a physical structure that guides waves along a certain path. The waveguide can be modeled mathematically as a region of space with certain boundary conditions, which can be expressed in terms of the wave equation.
The allpass filter itself can be modeled as a type of boundary condition on the waveguide. Specifically, the filter reflects the wave back into the waveguide with a phase shift, which can be expressed mathematically as:
u(x, t) = k*u(x  d, t  τ)
where k is the reflection coefficient, d is the distance between the filter and the input signal, and τ is the delay introduced by the filter. This equation is similar to the transfer function of an allpass filter in the time domain.
By incorporating the allpass filter into the waveguide model, one can solve the wave equation and determine the behavior of the wave as it passes through the filter. This type of analysis can be used to optimize the design of allpass filters for specific applications, such as in acoustic or electromagnetic waveguides.
137> what about from the context of waveguides? could you go in more depth here?
Sure, in the context of waveguides, an allpass filter can be viewed as a waveguide section that has the effect of delaying some frequency components of the input signal while advancing others.
A waveguide is a structure that guides the propagation of waves along a particular path, such as a hollow pipe or a transmission line. When an input signal is introduced into a waveguide, it can interact with the structure and produce a variety of effects, including reflection, transmission, and delay.
In the case of an allpass filter implemented as a waveguide section, the input signal is introduced into the structure and travels along the path defined by the waveguide. The waveguide section is designed in such a way that it introduces a delay to certain frequency components of the signal while advancing others. This delay can be adjusted by changing the length or other properties of the waveguide section.
The mathematics of waveguides can be described using partial differential equations, which govern the behavior of waves in a physical system. These equations can be solved using numerical techniques to simulate the behavior of a waveguide and predict the effects of various components, such as allpass filters, on the signal.
Overall, the use of allpass filters as waveguide sections allows for the precise manipulation of sound in electronic music synthesis, and the mathematical tools of waveguide theory provide a rigorous framework for understanding and designing these structures.
138> any relationship with wavelets?
Yes, there is a relationship between allpass filters and wavelets. Both allpass filters and wavelets can be used for signal processing and analysis.
Wavelets are mathematical functions that can be used to decompose signals into different frequency bands, similar to Fourier transforms. However, wavelets have a unique timefrequency localization property that Fourier transforms lack, making them useful for analyzing signals with timevarying frequency content.
Allpass filters can also be used to decompose signals into different frequency bands, but they do so using phase shifts instead of amplitude changes like typical filters. In this sense, allpass filters can be seen as a type of phase equalizer. They can also be used to create complex resonant structures for sound synthesis.
In signal processing applications, allpass filters and wavelets can be used together to achieve a variety of tasks, such as denoising and signal compression.
139> what about data compression?
Allpass filters can also be used in data compression. Specifically, they can be used in lossy compression algorithms such as MP3, where they are used as part of a psychoacoustic model to analyze and compress audio signals. In this context, the allpass filter is used to adjust the phase response of the signal in order to reduce the perceived amount of noise and distortion in the compressed audio. This is achieved by using the allpass filter to create a delay in the signal that is carefully chosen to minimize the effect of quantization noise on the perceived quality of the compressed audio.
140> what are their other applications?
Allpass filters have a wide range of applications beyond those already mentioned. Here are some additional examples:

Reverberation: Allpass filters are used to create a sense of space and depth in audio recordings, particularly in the case of simulating the sound of a large room or hall.

Phase equalization: Allpass filters can be used to compensate for phase shifts that occur in an audio signal as it passes through various components of an audio system, such as speakers or amplifiers.

Timestretching and pitchshifting: Allpass filters can be used to implement timestretching and pitchshifting algorithms in digital signal processing.

Audio effects processing: Allpass filters can be used to create a variety of interesting and creative audio effects, such as flanging, phasing, and comb filtering.

Image processing: Allpass filters can be used for image processing applications, such as edge detection, texture analysis, and feature extraction.

Control systems: Allpass filters can be used as building blocks in control systems, such as in the design of phaselocked loops and other feedback control systems.

Communications: Allpass filters can be used in communications systems, such as in the design of equalizers and channelizers for digital signal transmission.
Overall, allpass filters are a versatile and useful tool in many areas of signal processing and engineering.
141> relationship to singular value decomposition?
Allpass filters are closely related to singular value decomposition (SVD) in linear algebra. Specifically, the transfer function of a stable allpass filter can be decomposed into the product of a phase shift term and a minimumphase system. This minimumphase system can be decomposed using SVD, which can provide useful insights into the behavior of the allpass filter.
In particular, the singular values of the minimumphase system correspond to the magnitudes of the poles of the allpass filter, while the singular vectors correspond to the impulse response of the filter. By analyzing the singular values and vectors, one can gain insight into the spectral properties of the filter, as well as its temporal behavior.
This relationship between allpass filters and SVD is particularly useful in the context of audio signal processing and digital signal processing more generally. By designing and analyzing allpass filters using SVD, it is possible to achieve a wide range of desirable signal processing effects, such as phase equalization, timedomain smearing, and more.
142> what about eigenvalue problems?
Allpass filters are also related to eigenvalue problems, particularly in the context of digital signal processing. The transfer function of an allpass filter can be expressed as a ratio of two polynomials, where the coefficients of the polynomials depend on the filter parameters. By considering the denominator polynomial as a characteristic equation, it is possible to analyze the eigenvalues of the system and determine its stability and behavior.
In particular, the poles of the allpass filter (i.e., the roots of the denominator polynomial) are related to the eigenvalues of the system. These poles can be used to determine the frequency response and phase shift of the filter, as well as its impulse response and step response. By manipulating the coefficients of the polynomials, it is possible to design allpass filters with specific frequency response characteristics or phase responses.
Eigenvalue problems are also important in the design of other types of digital filters, such as lowpass, highpass, and bandpass filters. In these cases, the transfer function is not constrained to be an allpass function, and the eigenvalues of the system are used to determine the filter coefficients and frequency response. However, allpass filters can be used in combination with other filters to achieve more complex filtering effects.
Dependencies
~11–20MB
~296K SLoC