You are on page 1of 27

Short-time FFT, Multi-taper

analysis & Filtering in SPM12


Computational Psychiatry Seminar, FS 2015
Daniel Renz, Translational Neuromodeling Unit, ETHZ & UZH
20.03.2015
Overview
• Refresher
• Short-time Fourier transform
• Filter design
• Multitapering
• Filtering of EEG data in SPM12

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 2


Recap: Fourier Transform (FT)
• Our goal: To analyze event related signal changes in the time-frequency domain.
• FT expands a function in terms of sinusoids (or complex exponentials) to fully reveal all
frequency components.
• FT does not have any time resolution.

http://nbviewer.ipython.org/github/calebmadrigal/Fourier
TalkOSCON/blob/master/images/prism.png
Cohen 2014

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 3


Recap: Fourier Transform (FT)

http://upload.wikimedia.org/wikipedia/commons/7/72/Fourier
_transform_time_and_frequency_domains_%28small%29.gif

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 4


Recap: Inner product (dot product)
• Measures covariance / similarity / non-orthogonality between two vectors
(the inner product of orthogonal vectors is zero).
• Can be extended to functions.
• Any two sinusoids of different frequency are orthogonal.
This means that sinusoids can be used as basis functions.
• We can think of Fourier transformation at frequency ω as the
inner product of the signal with a complex-valued oscillation.
• As the basis functions are orthogonal, the Fourier-transform http://mathinsight.org/media/ima
ge/image/dot_product_projection
gives a perfect representation of the frequency spectrum. _unit_vector.png

• How to extend this to have temporal resolution?

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 5


How to get a time-frequency representation
• Model-free non-parametric methods: Short-time Fourier, Wavelet, Hilbert.
• We can view all three methods as convolutions with complex oscillatory kernels [Bruns 2003].

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 6


How to get a time-frequency representation
• Model-free non-parametric methods: Short-time Fourier, Wavelet, Hilbert.
• We can view all three methods as convolutions with complex oscillatory kernels [Bruns 2003].

http://www.merriam-webster.com/dictionary/convolution

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 7


Recap: Convolution
• We can think of convolution as the extension of the inner product
(dot product) to incorporate timelags.
• Compute the inner product of signal with kernel (window) at beginning
of signal, then move across the signal, computing products on the way.
• Outcome: time series of one
signal weighted by another
signal that slides along the
first signal.

repeat

Cohen 2014

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 8


Recap: Convolution

http://www.hpleym.no/atcm99/paper8.html

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 9


Recap: Convolution

http://www.hpleym.no/atcm99/paper8.html

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 10


Short-time Fourier Transform (STFT)
• Segment signal in narrow time segments.
• Taper (apply window on segment) each segment.
• Apply Fourier transform to each segment.

repeat

Cohen 2014

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 11


Short-time Fourier Transform (STFT)
• What shape should the window function have? Boxcar, Gaussian, ...
• How wide should it be?
• Should be narrow enough to consider windowed signal stationary.
• Narrow windows do not offer good localization in the frequency domain.
• Uncertainty principle: There is always a trade-off.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 12


Windows in STFT
• Should not use boxcar function as a window, as this will lead to unwanted artifacts.
• The discontinuities at the ends of the signal are the problem.
Idea: smooth signal to zero at the end points.

http://www.ni.com/white-paper/4844/en/

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 13


Windows in STFT
• Should not use boxcar function as a window, as this will lead to unwanted artifacts.
• Many possible windows, e.g. Hann, Hamming, Gaussian.
• A Gaussian has the same localization in time and frequency domain.
• Often Hann is preferred, because it tapers the data fully to zero.
• Use overlapping segments to compensate for signal loss (often around 90% overlap).

http://www.ni.com/white-paper/4844/en/
Cohen 2014

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 14


Recap: Wavelets
• Complex Morlet wavelet: Complex-valued oscillation multiplied by Gaussian-shaped envelope.
• Variance of Gaussian envelope scales with frequency of oscillation.
• The wavelet is convolved with the signal of interest. This effectively implements a band-pass filter.
• No fundamental difference to STFT with Gaussian window, but more convenient to use if
frequency-dependent temporal resolution is required.

http://upload.wikimedia.org/wikipedia/commons/c/c4/STFT_and_WT.jpg

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 15


Recap: Hilbert analysis
• Window on frequencies only (via band-pass filter).
• Then extend the signal to the complex plane (analytic signal) via Hilbert transform.
• One can show that this, too, is equivalent to convolution of the signal with a complex oscillatory
kernel [Bruns 2003].
• In practice, Hilbert analysis allows for direct control over filter properties as compared to wavelets.
But it‘s also more complicated.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 16


Comparing STFT, Wavelet and Hilbert
• Formally, they are very close (convolutions with complex-valued kernels).
• Practical differences:
• Computation speed, ease-of-use
• Conventional shape of kernel: Gaussian for Wavelets, Hamming for STFT, the equivalent of an
„ideal“ bandpass impulse response for Hilbert.

Bruns 2004: Fourier with Hamming window, Hilbert with ideal bandpass filter (smooth flanks) and complex Morlet wavelet.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 17


Comparing STFT, Wavelet and Hilbert
• The interpretation of power is the same for STFT, filter-Hilbert and wavelet convolution.
• The interpretation of phase changes
• Hilbert / Wavelet methods give instantaneous phase (phase at each time point).
• STFT gives one phase value per time window, referring to the phase of the sinusoid in that
window.

Cohen 2014

STFT phase in window Hilbert / Wavelet phase time series

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 18


Recap: Filtering
• We can think of filtering as a clever kind of averaging performed as a convolution with a filter‘s
impulse reponse function (Thus, STFT can also be viewed as a filtering procedure).
• And this is equivalent to multiplication in the frequency domain.

Slides from J. Heinzle

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 19


Recap: Filtering
• Can use filters to cut out a band of
frequencies or cut out everything but
a band of frequencies.
• But not perfectly: Precise cutoffs in the
time domain (box-car function!) result
in problems in the frequency domain, and
vice versa.

Slides from J. Heinzle


http://www.ni.com/white-paper/4844/en/

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 20


Spectral Leakage
• Steep slopes in time domain cause low main-lob
width (good!) and high side-lobes (bad!) in the
frequency domain.
• Fundamental trade-off between main-lobe width
and side-lobe amplitude.

http://www.ni.com/white-paper/4844/en/

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 21


Multitapering
• Idea: Apply several tapers (window functions) that have slightly different temporal
characteristics and then average the power spectra.
• This increases the SNR, so it’s useful for situations of low SNR ratio, such as higher-
frequency activity or single-trial analysis.

Cohen 2014

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 22


Multitapering: Slepian tapers
• If we use orthogonal tapers, windowed signals provide
independent spectral estimates.
• This reduces estimation bias of power.
• Discrete prolate spheroidal sequence (DPSS, also known
as Slepian sequence) is the orthogonal sequence that
has the optimal main lobe energy concentration
(main lobe energy/ total energy).

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 23


Multitapering
• More tapers means more smoothing.
• How much smoothing is appropriate? Trade-Off between SNR and accuracy.
• In MATLAB, the function dpss will compute a number of tapers, based on the desired spectral
smoothing and the length of the time segment.
• [desired segment length] * [frequency bandwidth of main lobe] = 2* [number of tapers].
• Should only use tapers with energy concentration > 90%.
• Good official tutorial:
http://ch.mathworks.com/help/signal/ref/pmtm.html

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 24


Filter design
• Can optimize two out of three requirements: filter order (lower=better), main lobe width
(narrower=better) and side-lobe amplitude (lower=better).
• Filter order refers to the complexity of the filter.
• In FIR filters, it specifies the number of time points in the signal that are used to compute the filter
output (so higher order = more temporal smoothing).
• In IIR filters, it‘s more complicated, but higher order filters
can quickly get unstable.
• Butterworth filter
• IIR filter that is maximally flat in the
pass-band (no ripples).
• This means that the transition band is
really wide.
http://www.electronics-tutorials.ws/filter/fil57.gif

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 25


Summary
• By Multitapering we mean taking the average of several STFT on the same signal with
orthogonal windows. This improves SNR at the cost of more smoothing.
• STFT, Wavelet and Hilbert can all be thought of as convolving the signal with complex
oscillatory kernels.
• Which one you want to use depends on your requirements
• STFT by default has a fixed resolution across frequencies and enables multitapering
• Wavelets provide higher temporal resolutions for higher frequencies.
• Hilbert is flexible, as it gives complete control over filter design.
• Designing a good filter is difficult and always depends on your specific goals. The butterworth
filter is a good general-purpose choice, as it has a flat pass-band.

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 26


Filtering of EEG data in SPM12

Daniel Renz, Short-time FFT, Multi-tapering & Filtering in SPM12 27

You might also like