The digital state variable filter

The digital state variable filter was described in Hal Chamberlin’s Musical Applications of Microprocessors. Derived by straight-forward replacement of components from the analog state variable fiter with digital counterparts, the digital state variable is a popular synthesizer filter, as was its analog counterpart.

The state variable filter has several advantages over biquads as a synthesizer filter. Lowpass, highpass, bandpass, and band reject are available simultaneously. Also, frequency and Q control are independent and their values calculated easily.

The frequency control coefficient, f, is defined as

where Fs is the sample rate and Fc is the filter’s corner frequency you want to set. The q coefficient is defined as

where Q normally ranges from 0.5 to inifinity (where the filter oscillates).

Like its analog counterpart, and biquads, the digital state variable has a cutoff slope of 12 dB/octave.

The main drawback of the digital state variable is that it becomes unstable at higher frequencies. It depends on the Q setting, but basically the upper bound of stability is about where f reaches 1, which is at one-sixth of the sample rate (8 kHz at 48 kHz). The only way around this is to oversample. A simple way to double the filter’s sample rate (and thereby double the filter’s frequency range) is to run the filter twice with the same input sample, and discard one output sample.

As a sine oscillator

The state variable makes a great low frequency sine wave oscillator. Just set the Q to infinity, and make sure it has an impulse to get it started. Simply preset the delays (set the “cosine” delay to 1, or other peak value, and the other to 0) and run, and it will oscillate forever without instability, with fixed point or floating point. Even better, it gives you two waves in quadrature—simultaneous sine and cosine.

Simplified to remove unecessary parts, the oscillator looks like this:

For low frequencies, we can reduce the calculation of the f coefficient equation to

Here’s an example in C to show how easy this oscillator is to use; first initialize the oscillator amplitude, amp, to whatever amplitude you want (normally 1.0 for ±1.0 peak-to-peak output):

// initialize oscillator
sinZ = 0.0;
cosZ = amp;

Then, for every new sample, compute the sine and cosine components and use them as needed:

// iterate oscillator
sinZ = sinZ + f * cosZ;
cosZ = cosZ – f * sinZ;

The sine purity is excellent at low frequencies (becoming asymmetrical at high frequencies).

This entry was posted in Digital Audio, Filters, IIR Filters. Bookmark the permalink.

7 Responses to The digital state variable filter

  1. TAL says:

    Great article. Will try it. Like the idea of a filter that does not need complex volume and frequency corrction tables. Always used some type of biquad filters. Keep posting :)

  2. Very nice post, Nigell! Could you please develop the 4th (and possible the 8th) order digital SVF. The following paper presents the development for the analog 4th SVF:

    DENNIS A. BOHN, “A FOURTH-ORDER STATE VARIABLE FILTER FOR LINKWITZ-RILEY ACTIVE CROSSOVER DESIGNS” in AES Convention:74 (October 1983)

    • Nigel Redmon says:

      First, most higher-order filters are made by cascading lower-order filters—this is done to reduce the precision necessary for the higher-order poles. For instance, you can use two of these second-order SVFs in series for a fourth-order filter. The Moog-style digital filters are made from four first-order filters.

      One key consideration in a synthesizer filter is how well it behaves when frequency (and perhaps resonance) are changed quickly; that’s why we don’t use direct form biquads as synthesizer filters. I hope to find time to write an article on an improved SVF suitable for synthesizers for an upcoming post.

  3. Adriano Mitre says:

    Cascading two 2nd order state-variable filters (SVF) is indeed straightforward. The result, however, does not feature the expected 4th order LP/HP/BP/BR simultaneous outputs — rather, only one of the outputs is as expected.

    Without loss of generality, let’s assume that the LP output of the SVF I is connected to the SVF II input. In such case, it is true that one has at the LP output of SVF II the expected 4th order lowpass filter, however the remaining SVF II outputs are LP-XX cascades of little meaning or use. The same applies to the HP, BP, and BR.

    Being mostly focuseded on implementing a time-invariant 4th order crossover using a single 4th order SVF, I look after topology in which the complementary 4th order low and highpass outputs are simultaneously available.

    • Nigel Redmon says:

      OK, I see now that your goal is a crossover and not a lowpass synth filter. I suggest focusing your search on “Linkwitz-Riley” in particular, rather than fourth-order state variable.

  4. Q says:

    Isn’t there a delay in the output back to input line missing?

    • Nigel Redmon says:

      There just needs to be a delay somewhere in the loop, as you can see in the diagram. I’ll try to present a more modern, improved version in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>