add new old fourier
This commit is contained in:
@ -5,6 +5,7 @@ import tempfile
|
||||
import numpy as np
|
||||
import unittest
|
||||
|
||||
from rfg_adc_plotter.constants import FFT_LEN, SWEEP_FREQ_MAX_GHZ, SWEEP_FREQ_MIN_GHZ
|
||||
from rfg_adc_plotter.processing.calibration import (
|
||||
build_calib_envelope,
|
||||
calibrate_freqs,
|
||||
@ -12,7 +13,12 @@ from rfg_adc_plotter.processing.calibration import (
|
||||
recalculate_calibration_c,
|
||||
save_calib_envelope,
|
||||
)
|
||||
from rfg_adc_plotter.processing.fft import compute_distance_axis, compute_fft_mag_row, compute_fft_row
|
||||
from rfg_adc_plotter.processing.fft import (
|
||||
build_symmetric_ifft_spectrum,
|
||||
compute_distance_axis,
|
||||
compute_fft_mag_row,
|
||||
compute_fft_row,
|
||||
)
|
||||
from rfg_adc_plotter.processing.normalization import (
|
||||
build_calib_envelopes,
|
||||
normalize_by_calib,
|
||||
@ -94,6 +100,23 @@ class ProcessingTests(unittest.TestCase):
|
||||
self.assertEqual(axis.shape, (513,))
|
||||
self.assertTrue(np.all(np.diff(axis) >= 0.0))
|
||||
|
||||
def test_symmetric_ifft_spectrum_has_zero_gap_and_mirrored_band(self):
|
||||
sweep = np.linspace(1.0, 2.0, 128, dtype=np.float32)
|
||||
freqs = np.linspace(SWEEP_FREQ_MIN_GHZ, SWEEP_FREQ_MAX_GHZ, 128, dtype=np.float64)
|
||||
spectrum = build_symmetric_ifft_spectrum(sweep, freqs, fft_len=FFT_LEN)
|
||||
|
||||
self.assertIsNotNone(spectrum)
|
||||
freq_axis = np.linspace(-SWEEP_FREQ_MAX_GHZ, SWEEP_FREQ_MAX_GHZ, FFT_LEN, dtype=np.float64)
|
||||
neg_idx_all = np.flatnonzero(freq_axis <= (-SWEEP_FREQ_MIN_GHZ))
|
||||
pos_idx_all = np.flatnonzero(freq_axis >= SWEEP_FREQ_MIN_GHZ)
|
||||
band_len = int(min(neg_idx_all.size, pos_idx_all.size))
|
||||
neg_idx = neg_idx_all[:band_len]
|
||||
pos_idx = pos_idx_all[-band_len:]
|
||||
zero_mask = (freq_axis > (-SWEEP_FREQ_MIN_GHZ)) & (freq_axis < SWEEP_FREQ_MIN_GHZ)
|
||||
|
||||
self.assertTrue(np.allclose(spectrum[zero_mask], 0.0))
|
||||
self.assertTrue(np.allclose(spectrum[neg_idx], spectrum[pos_idx][::-1]))
|
||||
|
||||
def test_peak_helpers_find_reference_and_peak_boxes(self):
|
||||
xs = np.linspace(0.0, 10.0, 200)
|
||||
ys = np.exp(-((xs - 5.0) ** 2) / 0.4) * 10.0 + 1.0
|
||||
|
||||
@ -39,6 +39,23 @@ class RingBufferTests(unittest.TestCase):
|
||||
self.assertIsNotNone(ring.last_fft_db)
|
||||
self.assertEqual(ring.last_fft_db.shape, (ring.fft_bins,))
|
||||
|
||||
def test_ring_buffer_can_switch_fft_mode_and_rebuild_fft_rows(self):
|
||||
ring = RingBuffer(max_sweeps=2)
|
||||
sweep = np.linspace(0.0, 1.0, 64, dtype=np.float32)
|
||||
freqs = np.linspace(3.3, 14.3, 64, dtype=np.float64)
|
||||
ring.push(sweep, freqs)
|
||||
fft_before = ring.last_fft_db.copy()
|
||||
axis_before = ring.distance_axis.copy()
|
||||
|
||||
changed = ring.set_symmetric_fft_enabled(False)
|
||||
|
||||
self.assertTrue(changed)
|
||||
self.assertFalse(ring.fft_symmetric)
|
||||
self.assertEqual(ring.get_display_raw().shape[1], 2)
|
||||
self.assertEqual(ring.last_fft_db.shape, fft_before.shape)
|
||||
self.assertFalse(np.allclose(ring.last_fft_db, fft_before))
|
||||
self.assertFalse(np.allclose(ring.distance_axis, axis_before))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user