From edcde25bbe92cc3e5b50ceb385b273243b0a5cf3 Mon Sep 17 00:00:00 2001 From: Eric Kooistra <kooistra@astron.nl> Date: Wed, 26 Jun 2024 15:45:55 +0200 Subject: [PATCH] Add verbosity. --- applications/lofar2/model/rtdsp/multirate.py | 52 +++++++++++--------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/applications/lofar2/model/rtdsp/multirate.py b/applications/lofar2/model/rtdsp/multirate.py index 06d1cbbf3d..5909777002 100644 --- a/applications/lofar2/model/rtdsp/multirate.py +++ b/applications/lofar2/model/rtdsp/multirate.py @@ -134,7 +134,7 @@ class PolyPhaseFirFilterStructure: return outData -def upsample(x, Nup, coefs, verify=False): # interpolate +def upsample(x, Nup, coefs, verify=False, verbosity=1): # interpolate """Upsample x by factor I = Nup Input: @@ -143,6 +143,7 @@ def upsample(x, Nup, coefs, verify=False): # interpolate . coefs: FIR filter coefficients for antialiasing LPF . verify: when True then verify that output y is the same when calculated directly or when calculated using the polyphase implementation. + - verbosity: when > 0 print() status, else no print() Return: . y: Upsampled output signal y[m] @@ -242,15 +243,16 @@ def upsample(x, Nup, coefs, verify=False): # interpolate else: print('ERROR: wrong upsample result') - print('> upsample():') - print('. Nup = ' + str(Nup)) - print('. Nx = ' + str(Nx)) - print('. len(y) = ' + str(len(y))) - print('') + if verbosity: + print('> upsample():') + print('. Nup = ' + str(Nup)) + print('. Nx = ' + str(Nx)) + print('. len(y) = ' + str(len(y))) + print('') return y -def downsample(x, Ndown, coefs, verify=False): # decimate +def downsample(x, Ndown, coefs, verify=False, verbosity=1): # decimate """Downsample x by factor D = Ndown up Input: @@ -259,6 +261,7 @@ def downsample(x, Ndown, coefs, verify=False): # decimate . coefs: FIR filter coefficients for antialiasing LPF . verify: when True then verify that output y is the same when calculated directly or when calculated using the polyphase implementation. + - verbosity: when > 0 print() status, else no print() Return: . y: Downsampled output signal y[m] @@ -368,17 +371,18 @@ def downsample(x, Ndown, coefs, verify=False): # decimate else: print('ERROR: wrong downsample result') - print('> downsample():') - print('. len(x) = ' + str(len(x))) - print('. Ndown = ' + str(Ndown)) - print('. Nx = ' + str(Nx)) - print('. Nxp = ' + str(Nxp)) - print('. len(y) = ' + str(len(y))) # = Nxp - print('') + if verbosity: + print('> downsample():') + print('. len(x) = ' + str(len(x))) + print('. Ndown = ' + str(Ndown)) + print('. Nx = ' + str(Nx)) + print('. Nxp = ' + str(Nxp)) + print('. len(y) = ' + str(len(y))) # = Nxp + print('') return y -def resample(x, Nup, Ndown, coefs, verify=False): # interpolate and decimate by Nup / Ndown +def resample(x, Nup, Ndown, coefs, verify=False, verbosity=1): # interpolate and decimate by Nup / Ndown """Resample x by factor I / D = Nup / Ndown x[n] --> Nup --> v[m] --> LPF --> w[m] --> Ndown --> y[k] @@ -408,6 +412,7 @@ def resample(x, Nup, Ndown, coefs, verify=False): # interpolate and decimate by . coefs: FIR filter coefficients for antialiasing LPF . verify: when True then verify that output y is the same when calculated directly or when calculated using the polyphase implementation. + - verbosity: when > 0 print() status, else no print() Return: . y: Resampled output signal y[m] @@ -458,12 +463,13 @@ def resample(x, Nup, Ndown, coefs, verify=False): # interpolate and decimate by else: print('ERROR: wrong resample result') - print('> resample():') - print('. len(x) = ' + str(len(x))) - print('. Nx = ' + str(Nx)) - print('. len(v) = ' + str(len(v))) - print('. Ny = ' + str(Ny)) - print('. Nyp = ' + str(Nyp)) - print('. len(y) = ' + str(len(y))) - print('') + if verbosity: + print('> resample():') + print('. len(x) = ' + str(len(x))) + print('. Nx = ' + str(Nx)) + print('. len(v) = ' + str(len(v))) + print('. Ny = ' + str(Ny)) + print('. Nyp = ' + str(Nyp)) + print('. len(y) = ' + str(len(y))) + print('') return y -- GitLab