Created
February 4, 2019 16:45
-
-
Save mattvenn/cd79555536e64c5434cf3273ec35f587 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import matplotlib.pyplot as plt | |
import glob | |
Fs = 32000000 / 16 # sampling rate | |
Ts = 1.0/Fs # sampling interval | |
def load(filename): | |
y = [] | |
x = [] | |
count = 0 | |
with open(filename) as fh: | |
for val in fh.readlines(): | |
count += 1 | |
x.append(len(x)) | |
y.append(int(val)) | |
# if count == 1000: | |
# break | |
return x, y | |
def plot(): | |
fig = plt.figure() | |
# freq plot | |
ax = fig.add_subplot(1,1,1) | |
ax.grid(True) | |
ax.set_xlabel('Freq (Hz)') | |
ax.set_ylabel('|Y(freq)|') | |
for filename in glob.glob("data-10k*/*csv"): | |
print(filename) | |
x, y = load(filename) | |
ref = 1000 # arbitrary ref | |
N = len(y) | |
win = np.hamming(N) | |
window = y[0:N] * win # Take a slice and multiply by a window | |
sp = np.fft.rfft(window) # Calculate real FFT | |
s_mag = np.abs(sp) * 2 / np.sum(win) # Scale the magnitude of FFT by window and factor of 2, | |
freq = np.arange((N / 2) + 1) / (float(N) / Fs) # Frequency axis | |
ax.plot(freq, s_mag) | |
plt.show() | |
if __name__ == '__main__': | |
plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment