rp2350 SWIFT
Cornell University ECE4760
Sliding Windowed Infinite Fourier Transform (SWIFT)
Pi Pico RP2350
Page Organization : Contents
The SWIFT algorithm to do a Fourier Transform was so new to me that I needed to build up intuition for how it worked and what it could do. The process invovled writing a description of the math followed by a series of programs.
Math: The first section shows the math, and why using SWIFT instead of a FFT might be useful.
SWIFT is related to the Sliding DFT, but uses an infinite exponential window, and is unconditionally stable.
Verify Understanding: The next section is a rewrite of an earlier FFT speech spectrogram in which the FFT was swapped out and SWIFT swapped in, but using SWIFT parameters which reproduced the FFT results, and using the same graphics, audio input, and audio output. Ths was used as a check that I actually understood the math.
Animate the complex resonator: At that point, I wrote a little graphics program which animated the behavior of five of the SWIFT frequency analysers, which are complex-valued resonators. This helped me visualize how adding a real input to a complex-valued phasor can result in frequency selective behavior.
Setting parameters : Now I was ready to understand how the settable parameters for each resonator affected its frequency, bandwidth, and noise. The algorithm sets two time constants and the center frequency for each resonator frequency bin. The time constants control the duration and shape of the averaging window used to perfrom a weighted sum of the current and past inputs for each frequency bin. The bigger of the two time constants sets the exponential weighting function time. A bigger time constant implies narrower bandwidth, but longer settleing time. The shorter of the two time constants controls the response to a suddenly changing input. The longer time constant will usually be a small multiple, perhaps 1 to 10 times, of the period of the bin frequency. The shorter time constant will typically be a small fraction, say 5% to 20%, of the period of the bin frequency.
Design Filter bank : Since each frequency resonator bin can be configured individually you need to figure out what a useful distribution of analysis frequencies is for your application. For speech, I chose a log-linear array of frequencies, with contant Q, so that the bandwidth of each bin is proportional to its bandwidth. I wrote a program which plots the measured response of an array of frequency bins on a VGA monitor.
Phase vocoder : Finally we can write an application which uses an array of frequency bins to analyse speech into 48 bands, then used the complex spectrum to generate pitch-shifted speech using a simple phase-vocoder. The vocoder runs at 20 KHz sampling rate and supports pitch shift from 0.5 to 2.0 times the original voice frequencies.
SWIFT algorithm .
The SWIFT algorithm is a Fourier transform technique which updates the transform at every input sample time, rather than computing a transform on a block of samples, like the FFT. SWIFT also uses an exponentially weighted window, and hence has an infinitely wide window, unlike the finite window of the FFT. These features have several very handy consequences:
The latency for an updated spectrum is one sample, hence completely real-time.
An exponential window gives more weight to recent data.
You only have to transform the frequences you need.
You do not need to produce a full spectrum, although you can.
Since the window is infinite, frequencies are not at fixed spacing like the FFT.
Place the frequencies on a log scale, linear scale, or randomly
There is a bandwidth parameter for each transform frequency bin you want to compute.
Setting the time-constant higher makes the bandwidth narrower.
Of course, time/bandwidth limits mean that very narrow frequency bins may converge slowly.
Each transform frequency bin, at frequency ω, is computed as a damped, complex resonator, with a real input. The estimate of the frequency bin amplitude at time n is Xn(ω) which is, of course, a complex value. Xn(ω) is computed iteratively from the n-1 time step estimate by slightly decaying the complex amplitude toward zero, advancing the phase by one time step, then adding the real input sample.
Xn(ω) = e(-1/τ) × e(jω) × Xn-1(ω) + xn
The units of ω are radians per sample time,
ω=2*π*F/Fs.
Fs is the sample rate and F is the frequency of the transform bin in Hz.
The decay time constant, τ, has units of number of samples. The time constant determines the bandwidth of the bin. Bigger time constant means narrower bandwidth. Typical values might range from 20 to 100, but could be different for each frequency bin. For speech, τ(ω)=3*Fs/F seems to work well.
Since both
τ and ω are constants, the exponentials can be computed once and stored in a table. The real-time computation reduces to one complex multiply...