Skip to content
Snippets Groups Projects
Commit 10c9cfe1 authored by Merlo, Jason's avatar Merlo, Jason
Browse files

Updated to add fourier interpolation

parent 60dbce69
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ Maintainer: Jason Merlo (merlojas@msu.edu)
import numpy as np # Storing data
from pyratk.datatypes.ts_data import TimeSeries # storing data
import scipy.constants as spc # speed of light
from scipy import signal # Upsampling
from pyratk.datatypes.geometry import Point # radar location
# from pyratk.datatypes.motion import StateMatrix # track location
from pyqtgraph import QtCore
......@@ -39,6 +40,7 @@ class Radar(object):
# === INITIALIZATION METHODS ==============================================
def __init__(self, data_mgr, index, loc=Point(),
f0=24.150e9, fft_size=2**16, fft_win_size=2**12,
interp_size=25e3,
cluda_thread=None):
super(Radar, self).__init__()
"""
......@@ -65,11 +67,12 @@ class Radar(object):
# Processing parameters
self.fft_size = fft_size
self.window_size = fft_win_size
self.interp_size = int(interp_size)
# Derived processing parameters
self.update_rate = self.data_mgr.sample_rate / self.data_mgr.sample_chunk_size
self.center_bin = np.ceil(self.fft_size / 2)
self.bin_size = self.data_mgr.sample_rate / self.fft_size
self.center_bin = np.ceil(self.interp_size / 2)
self.bin_size = self.data_mgr.sample_rate / self.interp_size
# === State variables ===
# initial array size 4096 samples
......@@ -106,7 +109,7 @@ class Radar(object):
"""Compute frequency based on bin location."""
return (bin - self.center_bin) * float(self.bin_size)
def compute_cfft(self, complex_data, fft_size):
def compute_cfft(self, complex_data, fft_size, interp_size=1000):
"""Compute fft and fft magnitude for plotting."""
# Create hanning window
# hanning = np.hanning(complex_data.shape[0])
......@@ -124,6 +127,8 @@ class Radar(object):
# Display only magnitude
fft_mag = np.linalg.norm([fft_complex.real, fft_complex.imag], axis=0)
fft_mag = signal.resample(fft_mag, interp_size)
return fft_mag
# === CONTROL METHODS =====================================================
......@@ -143,7 +148,7 @@ class Radar(object):
# Calculate complex FFT
# may be zero-padded if fft-size > sample_chunk_size
self.cfft_data = self.compute_cfft(window_slice, self.fft_size)
self.cfft_data = self.compute_cfft(window_slice, self.fft_size, self.interp_size)
# Find maximum frequency
fmax_bin = np.argmax(self.cfft_data)
......
......@@ -9,12 +9,13 @@ Maintainer: Jason Merlo (merlojas@msu.edu)
"""
import pyqtgraph as pg # Used for RadarWidget superclass
import numpy as np # Used for numerical operations
from scipy import signal # Used for upsampling
import time # Used for FPS calculations
class FftWidget(pg.GraphicsLayoutWidget):
def __init__(self, radar, vmax_len=100, show_max_plot=False,
fft_yrange=[-100,100], fft_xrange=[-50000,50000]):
fft_yrange=[-100,100], fft_xrange=[-25e3,25e3]):
super(FftWidget, self).__init__()
# Copy arguments to member variables
......@@ -54,9 +55,6 @@ class FftWidget(pg.GraphicsLayoutWidget):
# fft_xrange = [-50 / self.radar.bin_size, 50 / self.radar.bin_size]
# fft_yrange = [-100, 0]
for r in fft_xrange:
r /= self.radar.bin_size
# Add FFT plot
self.fft_plot = self.addPlot()
......@@ -65,7 +63,8 @@ class FftWidget(pg.GraphicsLayoutWidget):
self.fft_plot.setClipToView(True)
# self.fft_plot.setLogMode(x=False, y=True) # Log Y-axis of FFT views
self.fft_plot.setRange(disableAutoRange=True,
xRange=fft_xrange, yRange=fft_yrange)
xRange=np.array(fft_xrange)/self.radar.bin_size,
yRange=fft_yrange)
self.fft_plot.setLimits(
xMin=fft_xrange[0], xMax=fft_xrange[1],
yMin=fft_yrange[0], yMax=fft_yrange[1])
......@@ -106,11 +105,11 @@ class FftWidget(pg.GraphicsLayoutWidget):
def update_fft(self):
if self.radar.cfft_data is not None:
log_fft = 10 * np.log(self.radar.cfft_data)
max_log_fft = np.max(log_fft)
self.fft_pw.setData(log_fft)
self.fft_pw.setPos(-self.radar.center_bin, 0)
# draw max FFT lines
max_log_fft = np.nanmax(log_fft)
self.fft_max_freq_line.setValue(self.radar.fmax
/ self.radar.bin_size)
self.fft_max_pwr_line.setValue(max_log_fft)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment