-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b178f5
commit ba8d459
Showing
4 changed files
with
197 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"exponentials", | ||
"feedforward", | ||
"figsize", | ||
"freqs", | ||
"frombuffer", | ||
"fspl", | ||
"hann", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Any | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
import scipy.signal | ||
|
||
|
||
def get_frequency_vector( | ||
freqs: int | float | npt.ArrayLike = 1024, | ||
sample_rate: float = 1.0, | ||
whole: bool = True, | ||
decades: int | None = None, | ||
) -> npt.NDArray[np.float_]: | ||
if isinstance(freqs, int): | ||
# freqs represents the number of frequency points | ||
if whole: | ||
max_f = sample_rate | ||
else: | ||
max_f = sample_rate / 2 | ||
|
||
if decades is None: | ||
f = np.linspace(0, max_f, freqs, endpoint=False) | ||
elif isinstance(decades, int): | ||
f = np.logspace(np.log10(max_f) - decades, np.log10(max_f), freqs, endpoint=False) | ||
else: | ||
raise TypeError(f"Argument 'decades' must be an integer, not {type(decades).__name__}.") | ||
else: | ||
# freqs represents the single frequency or multiple frequencies | ||
f = np.asarray(freqs, dtype=float) | ||
f = np.atleast_1d(f) | ||
if not f.ndim <= 1: | ||
raise ValueError(f"Argument 'freqs' must be 0-D or 1-D, not {f.ndim}-D.") | ||
|
||
return f | ||
|
||
|
||
def frequency_response( | ||
b: npt.ArrayLike, | ||
a: npt.ArrayLike, | ||
freqs: int | float | npt.ArrayLike = 1024, | ||
sample_rate: float = 1.0, | ||
whole: bool = True, | ||
decades: int | None = None, | ||
) -> Any: | ||
f = get_frequency_vector(freqs, sample_rate, whole, decades) | ||
f, H = scipy.signal.freqz(b, a, worN=f, fs=sample_rate) | ||
return f, H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters