Skip to content
Snippets Groups Projects
Commit b891be9c authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Use sys.exit( ERROR message )

parent d4035ab5
No related branches found
No related tags found
1 merge request!419Resolve RTSD-265
...@@ -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):
print('ERROR: hbank.imag != 0 (max(abs) = %e)' % np.max(np.abs(hbank.imag))) exit('ERROR: hbank.imag != 0 (max(abs) = %e)' % np.max(np.abs(hbank.imag)))
return hbank.real return hbank.real
...@@ -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)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment