3
3
4
4
5
5
class FFTConvolveBase :
6
- """Base class for FFT convolve."""
6
+ """Abstract class for FFT convolve."""
7
7
8
8
def __init__ (self , filter , length ) -> None :
9
9
"""
10
+ Base class for creating a convolver that uses the same filter.
11
+
10
12
Parameters
11
13
----------
12
- filter : np .ndarray
14
+ filter : :py:class:`~numpy .ndarray`
13
15
Filter to convolve with. Must be real.
14
16
length : int
15
17
Length of the signal to convolve with.
@@ -22,22 +24,38 @@ def __init__(self, filter, length) -> None:
22
24
self .filter_frequency_response = self ._compute_filter_frequency_response ()
23
25
24
26
@abstractmethod
25
- def _compute_filter_frequency_response (self , filter ) -> np .ndarray :
27
+ def _compute_filter_frequency_response (self ) -> np .ndarray :
28
+ """
29
+ Compute the filter frequency response.
30
+
31
+ Parameters
32
+ ----------
33
+ filter : :py:class:`~numpy.ndarray`
34
+ Filter to compute the frequency response for.
35
+
36
+ Returns
37
+ -------
38
+ filter_frequency_response : :py:class:`~numpy.ndarray`
39
+ Filter frequency response.
40
+ """
26
41
raise NotImplementedError
27
42
28
43
@abstractmethod
29
44
def __call__ (self , signal ) -> np .ndarray :
45
+ """Apply the filter to the signal, in the frequency domain."""
30
46
pass
31
47
32
48
33
49
class RFFTConvolve (FFTConvolveBase ):
34
50
"""Real FFT convolve."""
35
51
36
52
def __init__ (self , filter , length ) -> None :
37
- """
53
+ r"""
54
+ Create convolver that uses a real-valued filter.
55
+
38
56
Parameters
39
57
----------
40
- filter : np .ndarray
58
+ filter : :py:class:`~numpy .ndarray`
41
59
Filter to convolve with. Must be real.
42
60
length : int
43
61
Length of the signal to convolve with.
@@ -48,19 +66,21 @@ def __init__(self, filter, length) -> None:
48
66
super (RFFTConvolve , self ).__init__ (filter , length )
49
67
50
68
def _compute_filter_frequency_response (self ):
51
- """Compute the filter frequency response."""
69
+ r """Compute the filter frequency response."""
52
70
return np .fft .rfft (self .filter , n = self .pad_length )
53
71
54
72
def __call__ (self , signal ) -> np .ndarray :
55
- """
73
+ r"""
74
+ Apply the real-valued filter to the signal, in the frequency domain.
75
+
56
76
Parameters
57
77
----------
58
- signal : np .ndarray
78
+ signal : :py:class:`~numpy .ndarray`
59
79
Signal to convolve with. Must be real.
60
80
61
81
Returns
62
82
-------
63
- result : np .ndarray
83
+ result : :py:class:`~numpy .ndarray`
64
84
Convolved signal.
65
85
"""
66
86
signal_frequency_response = np .fft .rfft (signal , n = self .pad_length )
@@ -73,6 +93,16 @@ class FFTConvolve(FFTConvolveBase):
73
93
"""General FFT convolve."""
74
94
75
95
def __init__ (self , filter , length ) -> None :
96
+ """
97
+ Create convolver that uses a fixed filter.
98
+
99
+ Parameters
100
+ ----------
101
+ filter : :py:class:`~numpy.ndarray`
102
+ Filter to convolve with. Must be real.
103
+ length : int
104
+ Length of the signal to convolve with.
105
+ """
76
106
super (FFTConvolve , self ).__init__ (filter , length )
77
107
78
108
def _compute_filter_frequency_response (self ):
@@ -81,14 +111,16 @@ def _compute_filter_frequency_response(self):
81
111
82
112
def __call__ (self , signal ) -> np .ndarray :
83
113
"""
114
+ Apply the filter to the signal, in the frequency domain.
115
+
84
116
Parameters
85
117
----------
86
- signal : np .ndarray
118
+ signal : :py:class:`~numpy .ndarray`
87
119
Signal to convolve with.
88
120
89
121
Returns
90
122
-------
91
- result : np .ndarray
123
+ result : :py:class:`~numpy .ndarray`
92
124
Convolved signal.
93
125
"""
94
126
signal_frequency_response = np .fft .fft (signal , n = self .pad_length )
0 commit comments