Skip to content

Commit af64081

Browse files
authored
Add support for bandstop filter type (#1464)
* Add support for bandstop filter type Extended FirFilterParameters to include 'bandstop' as a valid filter type. Updated validation and filter coefficient logic to handle bandstop filters alongside existing types. * Update changelog for bandstop filter support Added a changelog entry for bandstop filter type support and updated the code example to use FirFilterParameters().alter().
1 parent 83c6b46 commit af64081

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Running draft to be removed immediately prior to release. When altering tables,
88
import all foreign key references.
99

1010
```python
11+
from spyglass.common.common_filter import FirFilterParameters
1112
from spyglass.decoding.v1.core import DecodingParameters
1213

14+
FirFilterParameters().alter()
1315
DecodingParameters().alter()
1416
```
1517

@@ -19,6 +21,7 @@ DecodingParameters().alter()
1921
- Add note on fetching changes to setup notebook #1371
2022
- Revise table field docstring heading and `mermaid` diagram generation #1402
2123
- Add pages for custom analysis tables and class inheritance structure #1435
24+
- Add support for bandstop filter type #1464
2225

2326
### Infrastructure
2427

src/spyglass/common/common_filter.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class FirFilterParameters(SpyglassMixin, dj.Manual):
5858
filter_name: varchar(80) # descriptive name of this filter
5959
filter_sampling_rate: int # sampling rate for this filter
6060
---
61-
filter_type: enum("lowpass", "highpass", "bandpass")
61+
filter_type: enum("lowpass", "highpass", "bandpass", "bandstop") # type of filter
6262
filter_low_stop = 0: float # lowest freq for stop band for low filt
6363
filter_low_pass = 0: float # lowest freq for pass band of low filt
6464
filter_high_pass = 0: float # highest freq for pass band for high filt
@@ -103,7 +103,12 @@ def add_filter(
103103
Exception:
104104
Raises an exception if an unexpected filter type is encountered.
105105
"""
106-
VALID_FILTERS = {"lowpass": 2, "highpass": 2, "bandpass": 4}
106+
VALID_FILTERS = {
107+
"lowpass": 2, # low_stop, low_pass
108+
"highpass": 2, # high_stop, high_pass
109+
"bandpass": 4, # low_stop, low_pass, high_pass, high_stop
110+
"bandstop": 4, # low_stop, low_pass, high_pass, high_stop
111+
}
107112
FILTER_ERR = "Error in Filter.add_filter: "
108113
FILTER_N_ERR = FILTER_ERR + "filter {} requires {} band_frequencies."
109114

@@ -112,6 +117,7 @@ def add_filter(
112117
# low pass : [high_pass high_stop]
113118
# high pass: [low stop low pass]
114119
# band pass: [low_stop low_pass high_pass high_stop].
120+
# band stop: [low_stop low_pass high_pass high_stop].
115121
if filter_type not in VALID_FILTERS:
116122
logger.error(
117123
FILTER_ERR
@@ -164,14 +170,24 @@ def add_filter(
164170
"filter_low_stop": band_edges[0],
165171
"filter_low_pass": band_edges[1],
166172
}
167-
else:
173+
elif filter_type == "bandpass":
168174
desired = [0, 1, 1, 0]
169175
pass_stop_dict = {
170176
"filter_low_stop": band_edges[0],
171177
"filter_low_pass": band_edges[1],
172178
"filter_high_pass": band_edges[2],
173179
"filter_high_stop": band_edges[3],
174180
}
181+
elif filter_type == "bandstop":
182+
desired = [1, 0, 0, 1]
183+
pass_stop_dict = {
184+
"filter_low_stop": band_edges[0],
185+
"filter_low_pass": band_edges[1],
186+
"filter_high_pass": band_edges[2],
187+
"filter_high_stop": band_edges[3],
188+
}
189+
else:
190+
raise ValueError(f"Unhandled filter_type: {filter_type}")
175191

176192
# create 1d array for coefficients
177193
filterdict.update(

0 commit comments

Comments
 (0)