Skip to content
GitLab
Explore
Sign in
Register
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
b891be9c
Commit
b891be9c
authored
8 months ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Use sys.exit( ERROR message )
parent
d4035ab5
No related branches found
No related tags found
1 merge request
!419
Resolve RTSD-265
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
applications/lofar2/model/rtdsp/firfilter.py
+15
-22
15 additions, 22 deletions
applications/lofar2/model/rtdsp/firfilter.py
applications/lofar2/model/rtdsp/multirate.py
+4
-6
4 additions, 6 deletions
applications/lofar2/model/rtdsp/multirate.py
with
19 additions
and
28 deletions
applications/lofar2/model/rtdsp/firfilter.py
+
15
−
22
View file @
b891be9c
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
# [2] https://github.com/chipmuenk/dsp/blob/main/notebooks/02_LTF/LTF-IIR-allgemein.ipynb
# [2] https://github.com/chipmuenk/dsp/blob/main/notebooks/02_LTF/LTF-IIR-allgemein.ipynb
import
numpy
as
np
import
numpy
as
np
from
sys
import
exit
from
scipy
import
signal
from
scipy
import
signal
from
.utilities
import
c_rtol
,
c_atol
,
ceil_div
,
ceil_pow2
,
is_even
,
is_symmetrical
from
.utilities
import
c_rtol
,
c_atol
,
ceil_div
,
ceil_pow2
,
is_even
,
is_symmetrical
from
.fourier
import
fourier_interpolate
,
dtft
,
estimate_gain_at_frequency
from
.fourier
import
fourier_interpolate
,
dtft
,
estimate_gain_at_frequency
...
@@ -332,7 +333,6 @@ def design_fir_low_pass_filter_adjust(method,
...
@@ -332,7 +333,6 @@ def design_fir_low_pass_filter_adjust(method,
freqResolution
=
0.1
*
fs
/
Ndtft
freqResolution
=
0.1
*
fs
/
Ndtft
FP
=
fpass
FP
=
fpass
FS
=
fstop
FS
=
fstop
result
=
False
while
True
:
while
True
:
# Calculate iteration
# Calculate iteration
nofIterations
+=
1
nofIterations
+=
1
...
@@ -342,14 +342,11 @@ def design_fir_low_pass_filter_adjust(method,
...
@@ -342,14 +342,11 @@ def design_fir_low_pass_filter_adjust(method,
fIndex
,
fValue
,
fGain
=
estimate_gain_at_frequency
(
f
,
HF
,
fcutoff
)
fIndex
,
fValue
,
fGain
=
estimate_gain_at_frequency
(
f
,
HF
,
fcutoff
)
# print('DEBUG: FP, FS, fIndex, fValue, fGain = %s' % str((FP, FS, fIndex, fValue, fGain)))
# print('DEBUG: FP, FS, fIndex, fValue, fGain = %s' % str((FP, FS, fIndex, fValue, fGain)))
if
np
.
abs
(
fGain
-
cutoffGain
)
<
gainResolution
:
if
np
.
abs
(
fGain
-
cutoffGain
)
<
gainResolution
:
result
=
True
break
break
if
fStep
<
freqResolution
:
if
fStep
<
freqResolution
:
result
=
True
break
break
if
nofIterations
>
nofIterationsMax
:
if
nofIterations
>
nofIterationsMax
:
print
(
'
ERROR: Too many iterations.
'
)
exit
(
'
ERROR: Too many iterations (%d > %d).
'
%
(
nofIterations
,
nofIterationsMax
))
break
# Prepare next iteration
# Prepare next iteration
if
adjustBand
==
0
:
if
adjustBand
==
0
:
if
fGain
<
cutoffGain
:
if
fGain
<
cutoffGain
:
...
@@ -380,8 +377,6 @@ def design_fir_low_pass_filter_adjust(method,
...
@@ -380,8 +377,6 @@ def design_fir_low_pass_filter_adjust(method,
FS
-=
fStep
FS
-=
fStep
# print('DEBUG: FS too low, decrease fStep: FS, fStep = %s' % str((FS, fStep)))
# print('DEBUG: FS too low, decrease fStep: FS, fStep = %s' % str((FS, fStep)))
# Return result
if
result
:
if
verbosity
:
if
verbosity
:
# Repeat design_fir_low_pass_filter() for logging
# Repeat design_fir_low_pass_filter() for logging
h
=
design_fir_low_pass_filter
(
method
,
Ncoefs
,
FP
,
FS
,
rippleWeights
=
rippleWeights
,
h
=
design_fir_low_pass_filter
(
method
,
Ncoefs
,
FP
,
FS
,
rippleWeights
=
rippleWeights
,
...
@@ -394,8 +389,6 @@ def design_fir_low_pass_filter_adjust(method,
...
@@ -394,8 +389,6 @@ def design_fir_low_pass_filter_adjust(method,
print
(
'
. fGain = %f
'
%
fGain
)
print
(
'
. fGain = %f
'
%
fGain
)
print
(
'
. fGain**2 = %f
'
%
(
fGain
**
2
))
print
(
'
. fGain**2 = %f
'
%
(
fGain
**
2
))
print
(
''
)
print
(
''
)
else
:
print
(
'
ERROR: Return iteration %d.
'
%
nofIterations
)
return
h
return
h
...
@@ -494,5 +487,5 @@ def filterbank_impulse_response(hprototype, Npoints):
...
@@ -494,5 +487,5 @@ def filterbank_impulse_response(hprototype, Npoints):
hbank
+=
hprototype
*
np
.
exp
(
-
1.0j
*
2
*
np
.
pi
/
Npoints
*
k
*
np
.
arange
(
Lprototype
))
hbank
+=
hprototype
*
np
.
exp
(
-
1.0j
*
2
*
np
.
pi
/
Npoints
*
k
*
np
.
arange
(
Lprototype
))
# hbank.imag is zero
# hbank.imag is zero
if
not
np
.
allclose
(
hbank
.
imag
,
np
.
zeros
(
Lprototype
),
rtol
=
c_rtol
,
atol
=
c_atol
*
Npoints
):
if
not
np
.
allclose
(
hbank
.
imag
,
np
.
zeros
(
Lprototype
),
rtol
=
c_rtol
,
atol
=
c_atol
*
Npoints
):
prin
t
(
'
ERROR: hbank.imag != 0 (max(abs) = %e)
'
%
np
.
max
(
np
.
abs
(
hbank
.
imag
)))
exi
t
(
'
ERROR: hbank.imag != 0 (max(abs) = %e)
'
%
np
.
max
(
np
.
abs
(
hbank
.
imag
)))
return
hbank
.
real
return
hbank
.
real
This diff is collapsed.
Click to expand it.
applications/lofar2/model/rtdsp/multirate.py
+
4
−
6
View file @
b891be9c
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
# . CROCHIERE
# . CROCHIERE
import
numpy
as
np
import
numpy
as
np
from
sys
import
exit
from
scipy
import
signal
from
scipy
import
signal
from
.utilities
import
c_rtol
,
c_atol
,
ceil_div
from
.utilities
import
c_rtol
,
c_atol
,
ceil_div
...
@@ -425,8 +426,7 @@ def upsample(x, Nup, coefs, verify=False, verbosity=1): # interpolate
...
@@ -425,8 +426,7 @@ def upsample(x, Nup, coefs, verify=False, verbosity=1): # interpolate
if
np
.
allclose
(
y
,
yVerify
,
rtol
=
c_rtol
,
atol
=
c_atol
):
if
np
.
allclose
(
y
,
yVerify
,
rtol
=
c_rtol
,
atol
=
c_atol
):
print
(
'
. PASSED: correct upsample result
'
)
print
(
'
. PASSED: correct upsample result
'
)
else
:
else
:
print
(
'
. ERROR: wrong upsample result
'
)
exit
(
'
ERROR: wrong upsample result
'
)
return
False
if
verbosity
:
if
verbosity
:
print
(
'
> Log upsample():
'
)
print
(
'
> Log upsample():
'
)
print
(
'
. Nup =
'
,
str
(
Nup
))
print
(
'
. Nup =
'
,
str
(
Nup
))
...
@@ -489,8 +489,7 @@ def downsample(x, Ndown, coefs, verify=False, verbosity=1): # decimate
...
@@ -489,8 +489,7 @@ def downsample(x, Ndown, coefs, verify=False, verbosity=1): # decimate
if
np
.
allclose
(
y
,
yVerify
,
rtol
=
c_rtol
,
atol
=
c_atol
):
if
np
.
allclose
(
y
,
yVerify
,
rtol
=
c_rtol
,
atol
=
c_atol
):
print
(
'
. PASSED: correct downsample result
'
)
print
(
'
. PASSED: correct downsample result
'
)
else
:
else
:
print
(
'
. ERROR: wrong downsample result
'
)
exit
(
'
ERROR: wrong downsample result
'
)
return
False
if
verbosity
:
if
verbosity
:
print
(
'
> Log downsample():
'
)
print
(
'
> Log downsample():
'
)
print
(
'
. len(x) =
'
,
str
(
len
(
x
)))
print
(
'
. len(x) =
'
,
str
(
len
(
x
)))
...
@@ -596,8 +595,7 @@ def resample(x, Nup, Ndown, coefs, verify=False, verbosity=1): # interpolate an
...
@@ -596,8 +595,7 @@ def resample(x, Nup, Ndown, coefs, verify=False, verbosity=1): # interpolate an
if
np
.
allclose
(
y
,
yVerify
,
rtol
=
c_rtol
,
atol
=
c_atol
):
if
np
.
allclose
(
y
,
yVerify
,
rtol
=
c_rtol
,
atol
=
c_atol
):
print
(
'
. PASSED: correct resample result
'
)
print
(
'
. PASSED: correct resample result
'
)
else
:
else
:
print
(
'
. ERROR: wrong resample result
'
)
exit
(
'
ERROR: wrong resample result
'
)
return
False
if
verbosity
:
if
verbosity
:
print
(
'
> Log resample():
'
)
print
(
'
> Log resample():
'
)
print
(
'
. len(x) =
'
,
str
(
len
(
x
)))
print
(
'
. len(x) =
'
,
str
(
len
(
x
)))
...
...
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