Last active
August 29, 2015 14:21
-
-
Save jfsantos/ea96fe4ea3b1778cecee to your computer and use it in GitHub Desktop.
Compressing the spectrum magnitude
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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