Skip to content

Instantly share code, notes, and snippets.

@jfsantos
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsantos/ea96fe4ea3b1778cecee to your computer and use it in GitHub Desktop.
Save jfsantos/ea96fe4ea3b1778cecee to your computer and use it in GitHub Desktop.
Compressing the spectrum magnitude
import numpy as np
x = np.random.rand(513)
# Converting to the frequency domain
X = np.fft.rfft(x)
# Taking the log of the magnitude and converting back to rectangular
def P2R(magnitude, phase):
return magnitude * np.exp(1j*phase)
def R2P(x):
return np.abs(x), np.angle(x)
mag, phase = R2P(X)
mag_norm = np.log10(mag)
Xnorm = P2R(mag_norm, phase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment