diff --git a/applications/lofar2/model/pfb_os/dsp.py b/applications/lofar2/model/pfb_os/dsp.py index 5869c9c36b8af0e4352c7454f7e34a09c09e7b69..4e328ac0a5123890d05a4c17e3e705725591b52f 100644 --- a/applications/lofar2/model/pfb_os/dsp.py +++ b/applications/lofar2/model/pfb_os/dsp.py @@ -498,9 +498,7 @@ class PolyPhaseFirFilterStructure: # [ 1, 5, 9], # [ 0, 4, 8]]), Nphases = 4 rows (axis=0) # Ntaps = 3 columns (axis=1) - self.polyCoefs = self.poly_coeffs() - if commutator == 'down': - self.polyCoefs = np.flip(self.polyCoefs, axis=0) + self.polyCoefs = self.poly_coeffs(commutator) # oldest sample[0] # newest sample [15] @@ -514,25 +512,28 @@ class PolyPhaseFirFilterStructure: # [11, 7, 3]]) self.polyDelays = np.zeros((Nphases, self.Ntaps)) - def poly_coeffs(self): + def poly_coeffs(self, commutator): """Polyphase structure for FIR filter coefficients coefs in Nphases Input: . coefs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] + . commutator: 'up' or 'down' Return: - . polyCoefs = [[ 0, 4, 8], # p = 0 - [ 1, 5, 9], # p = 1 - [ 2, 6, 10], # p = 2 - [ 3, 7, 11]]) # p = 3, Nphases = 4 rows (axis=0) - Ntaps = 3 columns (axis=1) + . commutator: 'up', see title Figure in [HARRIS 6], Figure 10.22 and + 10.23 in [LYONS] seem to have commutator arrows in wrong direction. + polyCoefs = [[ 0, 4, 8], # p = 0, H0(z) + [ 1, 5, 9], # p = 1, H1(z) + [ 2, 6, 10], # p = 2, H2(z) + [ 3, 7, 11]]) # p = 3, H3(z), + Nphases = 4 rows (axis=0) + Ntaps = 3 columns (axis=1) If Ncoefs < Ntaps * Nphases, then pad polyCoefs with zeros. """ - Ncoefs = self.Ncoefs - Nphases = self.Nphases - Ntaps = self.Ntaps - polyCoefs = np.zeros(Nphases * Ntaps) - polyCoefs[0:Ncoefs] = self.coefs - polyCoefs = polyCoefs.reshape(Ntaps, Nphases).T + polyCoefs = np.zeros(self.Nphases * self.Ntaps) + polyCoefs[0 : self.Ncoefs] = self.coefs + polyCoefs = polyCoefs.reshape(self.Ntaps, self.Nphases).T + if commutator == 'down': + polyCoefs = np.flip(polyCoefs, axis=0) return polyCoefs def filter_block(self, inData): @@ -546,7 +547,6 @@ class PolyPhaseFirFilterStructure: oldest data and outData[Nphases-1] is newest data, so time n increments, like with inData """ - Ntaps = self.Ntaps # Shift delay memory by one block self.polyDelays = np.roll(self.polyDelays, 1, axis=1) # Shift in inData block at column 0 @@ -633,7 +633,6 @@ def upsample(x, Nup, coefs, verify=False): # interpolate y[n * I + 3] = lfilter(h[3, 7,11], [1], x) # p = 3 """ Nx = len(x) - Ncoefs = len(coefs) a = [1.0] # Polyphase implementation to avoid multiply by zero values @@ -755,7 +754,6 @@ def downsample(x, Ndown, coefs, verify=False): # decimate Nxp = (Ndown - 1 + len(x)) // Ndown # Used number of samples from x Nx = 1 + Ndown * (Nxp - 1) - Ncoefs = len(coefs) a = [1.0] # Polyphase implementation to avoid calculating values that are removed @@ -849,7 +847,6 @@ def resample(x, Nup, Ndown, coefs, verify=False): # interpolate and decimate by """ Nx = len(x) Nv = Nup * Nx - Ncoefs = len(coefs) a = [1.0] Nyp = (Nv + Ndown - 1) // Ndown # Number of samples from v, per poly phase in polyY Ny = 1 + Ndown * (Nyp - 1) # Used number of samples from v