Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RTSD
HDL
Commits
925839ff
Commit
925839ff
authored
1 year ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Add iir_biquad_butter_coefficients(), for biquads used in TBB.
parent
315257df
No related branches found
No related tags found
1 merge request
!374
Add plot_iir_filter_analysis() based on LTF-IIR-allgemein.ipynbcode from...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
applications/lofar2/model/pfb_os/dsp.py
+37
-4
37 additions, 4 deletions
applications/lofar2/model/pfb_os/dsp.py
with
37 additions
and
4 deletions
applications/lofar2/model/pfb_os/dsp.py
+
37
−
4
View file @
925839ff
...
@@ -117,7 +117,7 @@ def impulse_at_zero_crossing(x):
...
@@ -117,7 +117,7 @@ def impulse_at_zero_crossing(x):
###############################################################################
###############################################################################
# Filter design
#
FIR
Filter design
###############################################################################
###############################################################################
def
nof_taps_kaiser_window
(
fs
,
fpass
,
fstop
,
atten_db
):
def
nof_taps_kaiser_window
(
fs
,
fpass
,
fstop
,
atten_db
):
...
@@ -157,7 +157,7 @@ def ideal_low_pass_filter(Npoints, Npass, bandEdgeGain=1.0):
...
@@ -157,7 +157,7 @@ def ideal_low_pass_filter(Npoints, Npass, bandEdgeGain=1.0):
# Magnitude frequency reponse
# Magnitude frequency reponse
HF
=
np
.
zeros
([
Npoints
])
HF
=
np
.
zeros
([
Npoints
])
HF
[
0
]
=
bandEdgeGain
HF
[
0
]
=
bandEdgeGain
HF
[
1
:
Npass
-
1
]
=
1
HF
[
1
:
Npass
-
1
]
=
1
HF
[
Npass
-
1
]
=
bandEdgeGain
HF
[
Npass
-
1
]
=
bandEdgeGain
# Zero center HF to make it even
# Zero center HF to make it even
HF
=
np
.
roll
(
HF
,
-
(
Npass
//
2
))
HF
=
np
.
roll
(
HF
,
-
(
Npass
//
2
))
...
@@ -222,6 +222,39 @@ def fourier_interpolate(HFfilter, Ncoefs):
...
@@ -222,6 +222,39 @@ def fourier_interpolate(HFfilter, Ncoefs):
return
hInterpolated
.
real
return
hInterpolated
.
real
###############################################################################
# IIR Filter design
###############################################################################
def
iir_biquad_butter_coefficients
(
f0
,
BW
,
band
=
'
bandstop
'
,
fs
=
1
):
"""
Calculate b0, b1, b2, a0, a1, a2 for biquad IIR filter section.
Bilinear transform of Butterworth filters. From
https://webaudio.github.io/Audio-EQ-Cookbook/Audio-EQ-Cookbook.txt
For single biquad bandpass alternatively use signal.iirpeak()
For single biquad bandstop alternatively use signal.iirnotch()
"""
w0
=
2
*
np
.
pi
*
f0
/
fs
Q
=
f0
/
BW
si
=
np
.
sin
(
w0
)
cs
=
np
.
cos
(
w0
)
alpha
=
np
.
sin
(
w0
)
/
(
2
*
Q
)
a1
=
-
2
*
cs
if
band
==
'
lowpass
'
:
b0
=
1
-
cs
b
=
[
b0
/
2
,
b0
,
b0
/
2
]
elif
band
==
'
highpass
'
:
b0
=
1
+
cs
b
=
[
b0
/
2
,
-
b0
,
b0
/
2
]
elif
band
==
'
bandstop
'
:
b
=
[
1
,
a1
,
1
]
elif
band
==
'
bandpass
'
:
b
=
[
si
/
2
,
0
,
-
si
/
2
]
a
=
[
1
+
alpha
,
a1
,
1
-
alpha
]
return
b
,
a
###############################################################################
###############################################################################
# Hilbert transform filter
# Hilbert transform filter
###############################################################################
###############################################################################
...
@@ -475,7 +508,7 @@ def plot_spectra(f, HF, fs=1.0, fLim=None, dbLim=None):
...
@@ -475,7 +508,7 @@ def plot_spectra(f, HF, fs=1.0, fLim=None, dbLim=None):
plt
.
grid
(
True
)
plt
.
grid
(
True
)
def
plot_power_spectrum
(
f
,
HF
,
fmt
=
'
r
'
,
fs
=
1.0
,
fLim
=
None
,
dbLim
=
None
,
showRoll
=
False
):
def
plot_power_spectrum
(
f
,
HF
,
fmt
=
'
r
'
,
fs
=
1.0
,
fLim
=
None
,
dbLim
=
None
):
"""
Plot power spectrum
"""
Plot power spectrum
Input:
Input:
...
@@ -485,7 +518,7 @@ def plot_power_spectrum(f, HF, fmt='r', fs=1.0, fLim=None, dbLim=None, showRoll=
...
@@ -485,7 +518,7 @@ def plot_power_spectrum(f, HF, fmt='r', fs=1.0, fLim=None, dbLim=None, showRoll=
. fs: sample frequency in Hz, scale f by fs, fs >= 1
. fs: sample frequency in Hz, scale f by fs, fs >= 1
"""
"""
if
fs
>
1
:
if
fs
>
1
:
flabel
=
'
Frequency
[fs / %d]
'
%
fs
flabel
=
'
Frequency
'
else
:
else
:
flabel
=
'
Frequency [fs]
'
flabel
=
'
Frequency [fs]
'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment