Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assert_approx(x, y, e=1e-12):
x = x.flatten()
y = y.flatten()
assert dsp.norm(x - y) < e * dsp.norm(x)
def find_start(self, buf):
carrier = dsp.exp_iwt(self.omega, self.Nsym)
carrier = np.tile(carrier, self.START_PATTERN_LENGTH)
zeroes = carrier * 0.0
signal = np.concatenate([zeroes, carrier])
signal = (2 ** 0.5) * signal / dsp.norm(signal)
corr = np.abs(np.correlate(buf, signal))
norm_b = np.sqrt(np.correlate(np.abs(buf)**2, np.ones(len(signal))))
coeffs = np.zeros_like(corr)
coeffs[norm_b > 0.0] = corr[norm_b > 0.0] / norm_b[norm_b > 0.0]
index = np.argmax(coeffs)
log.info('Carrier coherence: %.3f%%', coeffs[index] * 100)
offset = index + len(zeroes)
return offset