Digital filters, and what they do to time
FIR versus IIR, Butterworth and its cousins, phase distortion, zero-phase filtering, and the ordering mistakes that quietly wreck analyses.
A filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity., Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace., Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first., Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak.. Glossary entry removes frequencies you do not want. Every filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry also does something to the frequencies you keep: it delays them, and usually by different amounts, which smears waveforms and shifts peaks. The whole art of filtering biosignals is choosing which distortion you can afford. Let’s design a few and watch what they do to an event-related potential.
- Butterworth low-pass, order 4, cutoff 30 Hz. Read the peak latency shift in the readout. Now order 8. The edge gets sharper and the shift gets larger.
- Turn on zero-phase. The shift goes to zero. The peak is a little smaller, because the filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry’s smoothing is still there, but it is in the right place.
- Switch to FIRFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. Related: IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry and vary the taps. The phase is a straight line (constant delay), which the plot shows already compensated. Watch the transition get sharper as taps increase.
- Set the test signal to a step and try a high-pass at 1 Hz. That droop after the step is what a high-pass does to a slow potential.
Two families
An FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. Related: IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts., Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak.. Glossary entry computes each output sample as a weighted sum of the last N input samples. Nothing is fed back. Make the weights symmetric and every frequency is delayed by exactly the same amount, (N−1)/2 samples, so waveform shapes are preserved and you can shift the output back by that amount to line it up. The cost is that sharp filtersFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry need many taps: a steep low-pass at 1 Hz on 250 Hz data needs hundreds of weights and a long delay.
Written out, with input , output , weights , and taps:
Symmetric weights () give every frequency the same delay of samples, which is why the shape survives.
An IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. Related: FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape., Butterworth filterButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else., Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak.. Glossary entry feeds its previous outputs back. A handful of coefficients gives a sharp response, which is why every analog filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry and every real-time digital filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry is IIRIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. Related: FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. , Butterworth filterButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry. The cost is that the delay varies with frequency: low frequencies come through later than high ones near the cutoff. That is phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. Related: Zero-phase filteringZero-phase filtering Running a filter forward and then backward through recorded data so the delays cancel; impossible in real time., Group delayGroup delay How long a filter delays the envelope of a signal at each frequency; constant for symmetric FIR filters.. Glossary entry, and in Figure 1 you watched it move an ERPEvent-related potential (ERP) The small, stereotyped voltage waveform the brain produces in response to an event, invisible in a single trial and revealed by averaging many. Related: P300P300 A positive bump about 300 milliseconds after a rare or meaningful stimulus, the basis of the classic BCI speller. , N170N170 A negative deflection about 170 milliseconds after seeing a face, over the back of the head on the right. , Error-related negativity (ERN)Error-related negativity (ERN) A sharp negative wave about 50 to 100 milliseconds after you make a mistake, before you consciously notice. , Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. . Glossary entry peak by tens of milliseconds.
Written out, with feedforward weights and feedback weights :
The terms feed past outputs back into the sum, and that feedback is what makes the delay vary with frequency.
Butterworth and its cousins
Among IIRIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. Related: FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. , Butterworth filterButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry designs, ButterworthButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else. Related: IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts.. Glossary entry has the flattest passband with no ripple, at the cost of a gradual roll-off. Chebyshev rolls off faster but ripples in the passband. Bessel has the most constant delay (the least phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. Related: Zero-phase filteringZero-phase filtering Running a filter forward and then backward through recorded data so the delays cancel; impossible in real time. , Group delayGroup delay How long a filter delays the envelope of a signal at each frequency; constant for symmetric FIR filters. . Glossary entry) and the gentlest roll-off. Elliptic is the sharpest and the worst behaved in phase. For biosignals the default is Butterworth, and the order is usually 2 to 4: higher orders ring after sharp events, which you can see in Figure 1 by setting the test signal to spikesSpike Shorthand for an action potential as seen by an electrode, a brief blip about a millisecond wide. Related: Action potentialAction potential The brief, all-or-nothing voltage spike a neuron fires, about a millisecond long and about 100 millivolts tall across its membrane. , Spike sortingSpike sorting Deciding which spikes on an electrode came from which neuron, by clustering their waveform shapes. , Extracellular recordingExtracellular recording Recording with an electrode near neurons rather than inside one; you see small, fast blips from nearby cells rather than the full membrane swing. . Glossary entry at order 8.
Zero-phase filtering
Run an IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. Related: FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. , Butterworth filterButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry forward through the data, then run it backward through the result. The forward pass delays each frequency by some amount; the backward pass delays it by the same amount in the other direction. The delays cancel exactly and the peak lands where it belongs. This is filtfilt, and it is zero-phase filteringZero-phase filtering Running a filter forward and then backward through recorded data so the delays cancel; impossible in real time. Related: Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak.. Glossary entry. Two consequences. The magnitude response is applied twice, so a 4th-order filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry behaves like an 8th-order one in attenuation. And it needs the future: it is only possible on recorded data, never in a real-time BCIBrain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. Related: DecoderDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. , Closed loopClosed loop A system in which the output feeds back to influence the input, such as a user adjusting their brain activity while watching the cursor it controls. . Glossary entry, which is why decodersDecoder The algorithm that maps neural signals to intended actions, such as a classifier or a Kalman filter. Related: ClassifierClassifier An algorithm that assigns each trial a label, such as left hand or right hand, after being trained on labelled examples. , Kalman filterKalman filter An estimator that blends a prediction from a motion model with a noisy measurement, weighting each by how much it trusts it; the decoder behind most intracortical cursor control. , Brain-computer interface (BCI)Brain-computer interface (BCI) A system that turns measured brain activity into control of something outside the body, from a cursor to a wheelchair to a speech synthesizer. . Glossary entry that work offline sometimes disappoint online.
In frequency terms, with the filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry’s response, forward-backward filtering gives:
The magnitude is squared, so attenuation in decibels doubles; the phase cancels to zero at every frequency.
You need to detect the P300 peak latency in a real-time speller. Which filter?
A symmetric FIRFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. Related: IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry with its delay subtracted, or a low-order causal IIRIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. Related: FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. , Butterworth filterButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry whose latency shift you have measured and accept. Filtfilt is impossible in real time. A causal Butterworth shifts the peak by an amount that depends on order and cutoff, which is fine only if you have measured it. The FIRFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. Related: IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry’s delay is constant and known, so you subtract it and the latency is right, at the cost of a fixed lag of half the filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry length. Real-time systems live with lag; they cannot live with unknown distortion.
Ordering mistakes
FilterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry after epoching. A low-frequency filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry needs seconds of data to settle. On a one-second epochEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry it distorts the edges and can add a slope across the whole thing. FilterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry the continuous data first, always.
High-pass too high. A 1 Hz high-pass on an ERPEvent-related potential (ERP) The small, stereotyped voltage waveform the brain produces in response to an event, invisible in a single trial and revealed by averaging many. Related: P300P300 A positive bump about 300 milliseconds after a rare or meaningful stimulus, the basis of the classic BCI speller. , N170N170 A negative deflection about 170 milliseconds after seeing a face, over the back of the head on the right. , Error-related negativity (ERN)Error-related negativity (ERN) A sharp negative wave about 50 to 100 milliseconds after you make a mistake, before you consciously notice. , Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. . Glossary entry experiment removes the slow components that some ERPsEvent-related potential (ERP) The small, stereotyped voltage waveform the brain produces in response to an event, invisible in a single trial and revealed by averaging many. Related: P300P300 A positive bump about 300 milliseconds after a rare or meaningful stimulus, the basis of the classic BCI speller. , N170N170 A negative deflection about 170 milliseconds after seeing a face, over the back of the head on the right. , Error-related negativity (ERN)Error-related negativity (ERN) A sharp negative wave about 50 to 100 milliseconds after you make a mistake, before you consciously notice. , Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. . Glossary entry (the late positive, the readiness potential) consist of, and it can create fake early components as an artifactArtifact Anything in the recording that did not come from the brain: blinks, muscle, heartbeat, movement, sweat, mains hum, electrode pops. Related: Blink artifactBlink artifact The large, slow deflection an eye blink produces in frontal channels, often ten times the size of the brain signal. , Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. , Artifact subspace reconstruction (ASR)Artifact subspace reconstruction (ASR) An automatic method that detects short high-variance bursts and reconstructs them from clean data; common in real-time pipelines. . Glossary entry of the droop. For ERPsEvent-related potential (ERP) The small, stereotyped voltage waveform the brain produces in response to an event, invisible in a single trial and revealed by averaging many. Related: P300P300 A positive bump about 300 milliseconds after a rare or meaningful stimulus, the basis of the classic BCI speller. , N170N170 A negative deflection about 170 milliseconds after seeing a face, over the back of the head on the right. , Error-related negativity (ERN)Error-related negativity (ERN) A sharp negative wave about 50 to 100 milliseconds after you make a mistake, before you consciously notice. , Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. . Glossary entry, 0.1 Hz; for oscillations, 1 Hz is fine.
NotchNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. Related: FilterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. , Common-mode signalCommon-mode signal A voltage that appears equally on both inputs of a differential amplifier, such as 60 Hz hum picked up by the whole body. . Glossary entry in the wrong place. A notchNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. Related: FilterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. , Common-mode signalCommon-mode signal A voltage that appears equally on both inputs of a differential amplifier, such as 60 Hz hum picked up by the whole body. . Glossary entry after epoching rings across the epochEpoch A fixed-length slice of the recording locked to an event, such as one second starting 200 milliseconds before each stimulus. Related: Trial averagingTrial averaging Adding many time-locked epochs together so the consistent response grows and the random noise shrinks by the square root of the number of trials. , Baseline correctionBaseline correction Subtracting the mean of the pre-stimulus interval from each epoch so trials line up. . Glossary entry. A notchNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. Related: FilterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. , Common-mode signalCommon-mode signal A voltage that appears equally on both inputs of a differential amplifier, such as 60 Hz hum picked up by the whole body. . Glossary entry at all, if the hum could have been fixed at the source, hides a problem.
Downsampling without a low-pass. Decimating 1000 Hz data to 250 Hz by taking every fourth sample aliases everything above 125 Hz into your band. Low-pass first, always; MNEMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. . Glossary entry’s resample does this for you.
Decimating 1000 Hz data to 250 Hz moves the Nyquist limit from 500 Hz to 125 Hz:
Everything above the new must be filtered out before the rate change, never after.
Filtering the average. FilterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry the single trials and then average, or average and then filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry; the result is the same for linear filtersFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry, but filtering the average hides how much each trial was distorted. Do it on the trials so you can see.
Deep dive Reading a frequency response 3 min
The magnitude plot in decibels: 0 dB is unchanged, −3 dB is 70 percent (the conventional cutoff), −20 dB is a tenth, −40 dB is a hundredth. The transition band is the stretch between passband and stopband; a steeper transition needs a higher order or more taps. The phase plot in radians, unwrapped: a straight line is a constant delay (its slope is the delay); a curve is phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. Related: Zero-phase filteringZero-phase filtering Running a filter forward and then backward through recorded data so the delays cancel; impossible in real time. , Group delayGroup delay How long a filter delays the envelope of a signal at each frequency; constant for symmetric FIR filters. . Glossary entry. Group delayGroup delay How long a filter delays the envelope of a signal at each frequency; constant for symmetric FIR filters. Related: Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak.. Glossary entry is the negative slope of the phase and is the delay each frequency’s envelope experiences.
Decibels compress ratios with a logarithm, for amplitudes:
So becomes dB, becomes dB, and becomes dB. Group delayGroup delay How long a filter delays the envelope of a signal at each frequency; constant for symmetric FIR filters. Related: Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry is the matching time-domain measure:
Here is the unwrapped phase in radians; is the delay each frequency’s envelope experiences, constant for a straight-line phase and varying wherever the phase curves.
Deep dive Designing an FIR filter 3 min
The windowed-sinc method: the ideal low-pass has an impulse response shaped like sin(x)/x, which is infinitely long. Truncate it to N taps and multiply by a smooth window (Hamming, Blackman) to tame the ripples the truncation causes. More taps gives a sharper transition; a wider window gives less ripple but a wider transition. MNEMNE-Python The standard open-source Python library for EEG and MEG analysis: filtering, epoching, ICA, topographies, source localization. Related: Independent component analysis (ICA)Independent component analysis (ICA) A method that unmixes multichannel data into statistically independent sources, so blinks and heartbeat can be identified and removed. . Glossary entry’s default filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry is exactly this, with the length chosen from the transition width. The interactive’s FIRFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. Related: IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry is a Hamming-windowed sinc.
Deep dive Biquads and why real-time filters are cascades of them 3 min
Any IIR filterIIR filter A filter that feeds its output back into itself; cheap and sharp, but it delays different frequencies by different amounts. Related: FIR filterFIR filter A filter that outputs a weighted sum of recent inputs only; symmetric ones delay every frequency equally, which preserves waveform shape. , Butterworth filterButterworth filter The IIR filter with the flattest possible passband, the default choice when you do not have a reason to choose something else. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry can be broken into second-order sections, “biquads,” each with five coefficients. Cascading them is numerically far better behaved than one high-order filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry, especially on a microcontroller in fixed point. The output=‘sos’ option in SciPy and the filterFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry chain in the site’s simulator are both biquad cascades. If you write firmwareFirmware The program running on the microcontroller, which configures the chip, reads samples on time, and ships them to the computer. Related: SPISPI A simple four-wire bus for talking to chips like the ADS1299 from a microcontroller. . Glossary entry that filtersFilter An operation that passes some frequencies and attenuates others; every filter also delays or distorts the timing of what it passes. Related: High-pass filterHigh-pass filter Removes slow drifts and DC offsets, passing everything above a cutoff; set it too high and you erase slow brain activity. , Low-pass filterLow-pass filter Removes fast content above a cutoff; the anti-alias filter is one, and so is the smoothing you apply to a noisy trace. , Notch filterNotch filter A very narrow filter that removes one frequency, usually 60 Hz mains hum; it also rings and distorts nearby content, so fix the hum at the source first. , Phase distortionPhase distortion Different frequencies being delayed by different amounts, which smears and shifts waveforms such as an ERP peak. . Glossary entry, write a biquad.
Explain what this page was about to your roommate in three sentences. No jargon they would not know.
We choose between finite impulse response filters that delay all frequencies equally by half their length and infinite impulse response designs like fourth order Butterworth near 30 Hz that sharpen the edge but shift peaks by tens of milliseconds. We run the filter forward then backward on recorded data when we need zero phase, accepting doubled attenuation and no real time use. We filter long continuous data before cutting epochs, keep high pass near 0.1 Hz for slow responses, and low pass before any downsampling so content above the new half rate cannot alias.
Yours does not have to match. Check that the three ideas are there.