16
16
17
17
18
18
__all__ = ['kaiser_beta' , 'kaiser_atten' , 'kaiserord' ,
19
- 'firwin' , 'firwin2' , 'fwind1 ' , 'remez' , 'firls' , 'minimum_phase' ]
19
+ 'firwin' , 'firwin2' , 'firwin_2d ' , 'remez' , 'firls' , 'minimum_phase' ]
20
20
21
21
22
22
# Some notes on function parameters:
@@ -1283,15 +1283,15 @@ def minimum_phase(h: np.ndarray,
1283
1283
return h_minimum [:n_out ]
1284
1284
1285
1285
1286
- def fwind1 (hsize , window , * , fc = None , fs = 2 , circular = False ):
1286
+ def firwin_2d (hsize , window , * , fc = None , fs = 2 , circular = False , pass_zero = True , scale = True ):
1287
1287
"""
1288
1288
2D FIR filter design using the window method.
1289
1289
1290
1290
This function computes the coefficients of a 2D finite impulse response
1291
1291
filter. The filter is separable with linear phase; it will be designed
1292
1292
as a product of two 1D filters with dimensions defined by `hsize`.
1293
1293
Additionally, it can create approximately circularly symmetric 2-D windows.
1294
-
1294
+
1295
1295
Parameters
1296
1296
----------
1297
1297
hsize : tuple or list of length 2
@@ -1302,79 +1302,41 @@ def fwind1(hsize, window, *, fc=None, fs=2, circular=False):
1302
1302
Desired window to use for each 1D filter or a single window type
1303
1303
for creating circularly symmetric 2-D windows. Each element should be
1304
1304
a string or tuple of string and parameter values. See
1305
- ' ~scipy.signal.get_window' for a list of windows and required
1305
+ ` ~scipy.signal.get_window` for a list of windows and required
1306
1306
parameters.
1307
1307
fc : float or 1-D array_like, optional
1308
- Cutoff frequency of filter (expressed in the same units as `fs`).
1309
- Required if `circular` is False.
1308
+ Cutoff frequency of the filter in the same units as `fs`. This defines
1309
+ the frequency at which the filter's gain drops to approximately -6 dB
1310
+ (half power) in a low-pass or high-pass filter. For multi-band filters,
1311
+ `fc` can be an array of cutoff frequencies (i.e., band edges) in the
1312
+ range [0, fs/2], with each band specified in pairs. Required if
1313
+ `circular` is False.
1310
1314
fs : float, optional
1311
1315
The sampling frequency of the signal. Default is 2.
1312
1316
circular : bool, optional
1313
1317
Whether to create a circularly symmetric 2-D window. Default is False.
1318
+ pass_zero : {True, False, 'bandpass', 'lowpass', 'highpass', 'bandstop'}, optional
1319
+ If True, the gain at the frequency 0 (i.e., the "DC gain") is 1.
1320
+ If False, the DC gain is 0. Can also be a string argument for the
1321
+ desired filter type (equivalent to ``btype`` in IIR design functions).
1322
+
1323
+ .. versionadded:: 1.3.0
1324
+ Support for string arguments.
1325
+ scale : bool, optional
1326
+ Set to True to scale the coefficients so that the frequency
1327
+ response is exactly unity at a certain frequency.
1328
+ That frequency is either:
1329
+
1330
+ - 0 (DC) if the first passband starts at 0 (i.e. pass_zero
1331
+ is True)
1332
+ - `fs/2` (the Nyquist frequency) if the first passband ends at
1333
+ `fs/2` (i.e the filter is a single band highpass filter);
1334
+ center of first passband otherwise
1314
1335
1315
1336
Returns
1316
1337
-------
1317
1338
filter_2d : (hsize[0], hsize[1]) ndarray
1318
1339
Coefficients of 2D FIR filter.
1319
-
1320
- Raises
1321
- ------
1322
- ValueError
1323
- If `hsize` and `window` are not 2-element tuples or lists.
1324
- If `cutoff` is None when `circular` is True.
1325
- If `cutoff` is outside the range [0, fs / 2] and `circular` is False.
1326
- If any of the elements in `window` are not recognized.
1327
- RuntimeError
1328
- If `firwin` fails to converge when designing the filter.
1329
-
1330
- See Also
1331
- --------
1332
- scipy.signal.firwin, scipy.signal.get_window
1333
-
1334
- Examples
1335
- --------
1336
- Generate a 5x5 low-pass filter with cutoff frequency 0.1.
1337
-
1338
- >>> import numpy as np
1339
- >>> from scipy.signal import get_window
1340
- >>> from scipy.signal import fwind1
1341
- >>> hsize = (5, 5)
1342
- >>> window = (("kaiser", 5.0), ("kaiser", 5.0))
1343
- >>> fc = 0.1
1344
- >>> filter_2d = fwind1(hsize, window, fc=fc)
1345
- >>> filter_2d
1346
- array([[0.00025366, 0.00401662, 0.00738617, 0.00401662, 0.00025366],
1347
- [0.00401662, 0.06360159, 0.11695714, 0.06360159, 0.00401662],
1348
- [0.00738617, 0.11695714, 0.21507283, 0.11695714, 0.00738617],
1349
- [0.00401662, 0.06360159, 0.11695714, 0.06360159, 0.00401662],
1350
- [0.00025366, 0.00401662, 0.00738617, 0.00401662, 0.00025366]])
1351
-
1352
- Generate a circularly symmetric 5x5 low-pass filter with Hamming window.
1353
-
1354
- >>> filter_2d = fwind1((5, 5), 'hamming', fc=fc, circular=True)
1355
- >>> filter_2d
1356
- array([[-0.00020354, -0.00020354, -0.00020354, -0.00020354, -0.00020354],
1357
- [-0.00020354, 0.01506844, 0.09907658, 0.01506844, -0.00020354],
1358
- [-0.00020354, 0.09907658, -0.00020354, 0.09907658, -0.00020354],
1359
- [-0.00020354, 0.01506844, 0.09907658, 0.01506844, -0.00020354],
1360
- [-0.00020354, -0.00020354, -0.00020354, -0.00020354, -0.00020354]])
1361
-
1362
- Plotting the generated 2D filters (optional).
1363
-
1364
- >>> import matplotlib.pyplot as plt
1365
- >>> hsize, fc = (50, 50), 0.05
1366
- >>> window = (("kaiser", 5.0), ("kaiser", 5.0))
1367
- >>> filter0_2d = fwind1(hsize, window, fc=fc)
1368
- >>> filter1_2d = fwind1((50, 50), 'hamming', fc=fc, circular=True)
1369
- ...
1370
- >>> fg, (ax0, ax1) = plt.subplots(1, 2, tight_layout=True, figsize=(6.5, 3.5))
1371
- >>> ax0.set_title("Product of 2 Windows")
1372
- >>> im0 = ax0.imshow(filter0_2d, cmap='viridis', origin='lower', aspect='equal')
1373
- >>> fg.colorbar(im0, ax=ax0, shrink=0.7)
1374
- >>> ax1.set_title("Circular Window")
1375
- >>> im1 = ax1.imshow(filter1_2d, cmap='plasma', origin='lower', aspect='equal')
1376
- >>> fg.colorbar(im1, ax=ax1, shrink=0.7)
1377
- >>> plt.show()
1378
1340
"""
1379
1341
if len (hsize ) != 2 :
1380
1342
raise ValueError ("hsize must be a 2-element tuple or list" )
0 commit comments