diff --git a/applications/lofar2/model/rtdsp/firfilter.py b/applications/lofar2/model/rtdsp/firfilter.py index b7bab7bb4545cc3f58dd84fc6c9b6a927c80c8bb..843d306bf3cf7b49ef35d8d93c22016558816ee3 100644 --- a/applications/lofar2/model/rtdsp/firfilter.py +++ b/applications/lofar2/model/rtdsp/firfilter.py @@ -28,6 +28,7 @@ # [2] https://github.com/chipmuenk/dsp/blob/main/notebooks/02_LTF/LTF-IIR-allgemein.ipynb import numpy as np +from sys import exit from scipy import signal 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 @@ -332,7 +333,6 @@ def design_fir_low_pass_filter_adjust(method, freqResolution = 0.1 * fs / Ndtft FP = fpass FS = fstop - result = False while True: # Calculate iteration nofIterations += 1 @@ -342,14 +342,11 @@ def design_fir_low_pass_filter_adjust(method, fIndex, fValue, fGain = estimate_gain_at_frequency(f, HF, fcutoff) # print('DEBUG: FP, FS, fIndex, fValue, fGain = %s' % str((FP, FS, fIndex, fValue, fGain))) if np.abs(fGain - cutoffGain) < gainResolution: - result = True break if fStep < freqResolution: - result = True break if nofIterations > nofIterationsMax: - print('ERROR: Too many iterations.') - break + exit('ERROR: Too many iterations (%d > %d).' % (nofIterations, nofIterationsMax)) # Prepare next iteration if adjustBand == 0: if fGain < cutoffGain: @@ -380,22 +377,18 @@ def design_fir_low_pass_filter_adjust(method, FS -= fStep # print('DEBUG: FS too low, decrease fStep: FS, fStep = %s' % str((FS, fStep))) - # Return result - if result: - if verbosity: - # Repeat design_fir_low_pass_filter() for logging - h = design_fir_low_pass_filter(method, Ncoefs, FP, FS, rippleWeights=rippleWeights, - kaiserBeta=kaiserBeta, fs=fs, verbosity=verbosity) - print('> design_fir_low_pass_filter_adjust():') - print('. nofIterations = %d' % nofIterations) - print('. FP / fpass = %f' % (FP / fpass)) - print('. FS / fstop = %f' % (FS / fstop)) - print('. fcutoff = %f' % fcutoff) - print('. fGain = %f' % fGain) - print('. fGain**2 = %f' % (fGain**2)) - print('') - else: - print('ERROR: Return iteration %d.' % nofIterations) + if verbosity: + # Repeat design_fir_low_pass_filter() for logging + h = design_fir_low_pass_filter(method, Ncoefs, FP, FS, rippleWeights=rippleWeights, + kaiserBeta=kaiserBeta, fs=fs, verbosity=verbosity) + print('> design_fir_low_pass_filter_adjust():') + print('. nofIterations = %d' % nofIterations) + print('. FP / fpass = %f' % (FP / fpass)) + print('. FS / fstop = %f' % (FS / fstop)) + print('. fcutoff = %f' % fcutoff) + print('. fGain = %f' % fGain) + print('. fGain**2 = %f' % (fGain**2)) + print('') return h @@ -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.imag is zero 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 diff --git a/applications/lofar2/model/rtdsp/multirate.py b/applications/lofar2/model/rtdsp/multirate.py index 7fd2e54b4939697690fe30e6df44a113cc4d0e44..908dff640294a7290d6c7684a629d7eeee4af7d1 100644 --- a/applications/lofar2/model/rtdsp/multirate.py +++ b/applications/lofar2/model/rtdsp/multirate.py @@ -36,6 +36,7 @@ # . CROCHIERE import numpy as np +from sys import exit from scipy import signal from .utilities import c_rtol, c_atol, ceil_div @@ -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): print(' . PASSED: correct upsample result') else: - print(' . ERROR: wrong upsample result') - return False + exit('ERROR: wrong upsample result') if verbosity: print('> Log upsample():') print(' . Nup =', str(Nup)) @@ -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): print(' . PASSED: correct downsample result') else: - print(' . ERROR: wrong downsample result') - return False + exit('ERROR: wrong downsample result') if verbosity: print('> Log downsample():') print(' . len(x) =', str(len(x))) @@ -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): print(' . PASSED: correct resample result') else: - print(' . ERROR: wrong resample result') - return False + exit('ERROR: wrong resample result') if verbosity: print('> Log resample():') print(' . len(x) =', str(len(x)))