SDA13 Filters

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Signal & Data Analysis in Neuroscience

2024
Filters & Windows

Izhar Bar-Gad
Room: 408 Phone: 7141 Email: [email protected]

Outline – Frequency Domain

 Introduction
 Fourier Transform
 Sampling Theory

 Systems

 Filters

 Windows

 Spectral Analysis

Filter in signal analysis

 Filters are used to eliminate unwanted


frequencies from an input signal or to select a
desired frequency range among many others.

 Filters form a sub-group of the systems.

 There are analog and digital filters. We will


focus on the digital filters.

1
3
Filters

|X(ω)|
Original frequency domain
ω

|X(ω)|

 Low Pass Filter (LPF)


ω
|X(ω)|
 High Pass Filter (HPF)
ω
|X(ω)|
 Band Pass Filter (BPF)
ω
|X(ω)|
 Band Stop Filter (BSF)
ω

Input – Filter – Output

 Given the input X(ω) and desired output


Y(ω), how can we describe H(ω) ?

 Moreover, how can we transfer it to the


time domain and get a representation of
the three components?

Ideal Filtering

Since Y(ω)=X(ω)∙H(ω)

H(ω) X(ω)
|H(ω)| |X(ω)|

ω ω

Y(ω)
|Y(ω)|

2 Remember : No frequency domain systems exist !!

6
Ideals problem : F(rect)=sinc

Ideal frequency response  sinc in the time domain !

The sinc function

sin(𝑥)
 The classical “unnormalized” definition 𝑠𝑖𝑛𝑐 𝑥 =
𝑥
sin(𝜋𝑥)
 Signal analysis “normalized” definition 𝑠𝑖𝑛𝑐 𝑥 =
𝜋𝑥

sinc problem

 The sinc function is infinite, forever oscillating


around zero.

 Inserting Irrelevant samples into the filtered signal

 Since both F(rect)=sinc & F(sinc)=rect


this problem is relevant for rectangular windows in
both time and frequency domains

3
9
Filter Design - Amplitude

(Example of a python design tool is the “pyfda” package)

10

Truncated sinc filter

11

Filter families

 There are many filter families possessing


different characteristics
 In this example a 10 pole Chebyshev &
Butterworth low-pass filters

4
12
Number of poles

 Butterworth filter of order 1  5

13

Special case: Notch Filter

 Special case of band-stop filter.


 Remove a narrow band from the signal
 Usually used for network noise (50,60 hz)
 BEWARE:
 Drastically distorts phase, esp. when analog
 Even if not, cancels most of the energy in the narrow
band instead of just the noise part of it

14

Filter example I
Original extracellular signal

Extracellular recording, containing the summation of


different processes. Some relevant (neural origin)
and some irrelevant (non neural origin).
0.015

0.01

0.005
Voltage (mV)

-0.005

-0.01

5 -0.015
0 100 200 300 400 500
Time (ms)
600 700 800 900 1000

15
Filter example II
Following notch filter (~1800Hz)

External (non biological noise) may have a very


narrow band. Both local field potential (LFP) and
action potentials (spikes) are apparent.

0.01

0.005

Voltage (mV)
-0.005

-0.01

-0.015
0 100 200 300 400 500 600 700 800 900 1000
Time (ms)

16

Filter example III


Following high pass (~300Hz)

Removal of the high frequency components


removes the local field potential, leaving the spiking
activity.
-3
x 10
5

0
Voltage (mV)

-5

-10
0 100 200 300 400 500 600 700 800 900 1000
Time (ms)

17

Filter Design - Phase

LTI system: H ( )  A( )ei ( )

Therefore, in order to achieve constant delay


(that all frequencies will be delayed by the
same phase) we would like to have a linear
phase response.
[or at least at the relevant frequency range]
6
18
Semi-Log plot

H(ω) 50

Magnitude (dB)
0

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

5000

Phase (degrees)
0

-5000

-10000

-15000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

matlab: freqz

19

Phase distortion
Extracellular recording

(Yael & Bar-Gad., 2017)

20

Phase distortion
Linear vs. Non-linear phase

7
21
Filters
Avoiding sampling problems

when X(ω)  X[k] looks like this,


You have an aliasing problem…
Anti-Aliasing filter
What is there to do?
X(ω)
And if we can not increase ωs ?

X(ω)
cut

X[k]

22

Online vs. Offline Filtering

 Online filtering –
 Live streaming (usually analog) data
 Delay limit
 Limited computational resources

 Offline filtering –
 Sampled, stored, digital data
 No time limit
 Less limited computational resources

23

Analog Filters

RC Circuit = the simplest LPF

8
24
Filters in Neuroscience

 Cell Membrane as LPF


 Slice Bath as LPF

25

2D Fourier transform

 Continuous 2D transform

 Discrete 2D transform

(http://fourier.eng.hmc.edu/e101/lectures/Image_Processing/Image_Processing.html)

26

2D Fourier transform

9
27
Spatial filtering

 Spatial featufiltersres may be applied on


2D (or even 3D) images.
(https://medium.com/@hicraigchen/digital-image-processing-using-fourier-transform-in-python-bcb49424fd82)

Original Low pass High pass

(from OpenCV github)

28

Spatial filtering

Ideal Butterworth
filter filter

l Low pass

High pass

(from OpenCV github)

29

Outline – Frequency Domain

 Introduction
 Fourier Transform

 Sampling Theory

 Systems

 Filters

 Windows

 Spectral Analysis

10
30
sinc: time & frequency duality

Time Domain Frequency Domain

31

Finite sinc

32

Ideal Filter Example

2 2
signal  sin( t )  sin(10 * t)
1000 1000
2

1 . 5

0 . 5

- 0 . 5

- 1

- 1 . 5

- 2
0 5 0 0 1 0 0 0 1 5 0 0 2 0 0 0 2 5 0 0 3 0 0 0 3 5 0 0 4 0 0 0 4 5 0 0 5 0 0 0

Convolution with a rectangular window


result = conv(ones(1,120), signal)
1 5 0

1 0 0

5 0

- 5 0

11 - 1

- 1
0

5
0

0
0 5 0 0 1 0 0 0 1 5 0 0 2 0 0 0 2 5 0 0 3 0 0 0 3 5 0 0 4 0 0 0 4 5 0 0 5 0 0 0

33
Windows

34

Windows frequency response

frequency time
Triangular window

W[n]=

-M ≤ n ≤ M
Hanning window

Hamming window

35

Leakage windows I

12
36
Leakage windows II

37

Windows and filters

38

DFT Frequencies

 Discrete 2k
j n 2
 Range : 0-2, e N
 k 
N
 Periodic

But…
What about frequencies in between?

13
39
DFT Leakage

Say we had a sinusoid of 2.3 Khz and we still


sampled it at 8000 samples/s :

The output frequency bins = 0Kkz, 1Khz, …, 7Khz


2.3 Khz bin is missing!!

What happens is that this frequency component


shows up (leaks) in all the other frequency bins

Remedy
Windowing Techniques

40

14

You might also like