Peak-n-hold on FFT for IQ data
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 scipy.io | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from numpy.fft import fft, fftshift | |
path = '/home/oli/baseband_144288239Hz_17-59-43_08-12-2022.wav' | |
sr, d = scipy.io.wavfile.read(path) | |
d = d[...,0] + 1j * d[...,1] # convert to complex array | |
sta, stop = 30, 60 # time of sweep beginning and end in .wav file | |
fftsize = 1024 | |
cfreq = 144288.239 # center frequency in kHz | |
fspan = sr/1000 # span in kHz = sample rate/1000 | |
xlabel = np.linspace(cfreq-fspan/2, cfreq+fspan/2, fftsize) # label for each bin | |
win = np.hamming(fftsize) # hamming window for filtering fft result | |
maxes = np.zeros(fftsize)-999 # array for recording maximum value of each fft bucket | |
for s in range(sta*sr, stop*sr, fftsize): | |
data = win*d[s:s+fftsize] # cut out chunk of data | |
yf = np.abs(fftshift(fft(data))) # take fft, reorder the output, get modulus | |
s_mag = yf * 2 / np.sum(win) | |
s_dbfs = 20 * np.log10(s_mag/32768) # normalize and convert to log scale | |
maxes = np.maximum(maxes, s_dbfs) # record peak values | |
plt.plot(xlabel, maxes) # plot | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment