def oversamplingFilter(n, M, p=2): ''' Produce the nxn oversampling filter that is needed to exactly filter dyadic DRT etc. This version returns values as multiplicative inverses (mod M) for use with the NTT ''' gcd_table = np.zeros(n) gcdInv_table = np.zeros(n) gcd_table[0] = n + int(n) / p gcdInv_table[0] = nt.minverse(gcd_table[0], M) gcd_table[1] = 1 gcdInv_table[1] = nt.minverse(gcd_table[1], M) for j in range(2, n): u, v, gcd_table[j] = nt.extended_gcd(int(j), int(n)) gcdInv_table[j] = nt.minverse(gcd_table[j], M) filter = nt.zeros((n, n)) for j in range(0, n): for k in range(0, n): if gcd_table[j] < gcd_table[k]: filter[j, k] = nt.integer(gcdInv_table[j]) else: filter[j, k] = nt.integer(gcdInv_table[k]) return filter
def oversampling_1D(n, p=2, norm=False): ''' The 1D oversampling. All values are GCDs. Use the filter versions to remove the oversampling. ''' gcd_table = np.zeros(n) gcd_table[0] = n + int(n) / p gcd_table[1] = 1 for j in range(2, n): u, v, gcd_table[j] = nt.extended_gcd(int(j), int(n)) return gcd_table
def oversampling(n, p=2): ''' Produce the nxn oversampling filter that is needed to exactly filter dyadic DRT etc. ''' gcd_table = np.zeros(n) gcd_table[0] = n + n / p gcd_table[1] = 1 for j in range(2, n): u, v, gcd_table[j] = nt.extended_gcd(int(j), int(n)) filter = np.zeros((n, n)) for j in range(0, n): for k in range(0, n): if gcd_table[j] < gcd_table[k]: filter[j, k] = gcd_table[j] else: filter[j, k] = gcd_table[k] return filter
def oversampling_1D_filter(n, p=2, norm=False): ''' The 1D filter for removing oversampling. All values are multiplicative inverses. To apply this filter multiply with 1D FFT slice ''' normValue = 1 if norm: normValue = n gcd_table = np.zeros(n) gcdInv_table = np.zeros(n) gcd_table[0] = n + int(n) / p gcdInv_table[0] = 1.0 / gcd_table[0] gcd_table[1] = 1 gcdInv_table[1] = 1.0 / gcd_table[1] for j in range(2, n): u, v, gcd_table[j] = nt.extended_gcd(int(j), int(n)) gcdInv_table[j] = 1.0 / (gcd_table[j] * normValue) return gcdInv_table