-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdebug_fftshift.py
More file actions
48 lines (39 loc) · 1.32 KB
/
debug_fftshift.py
File metadata and controls
48 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
"""
Simple diagnostic test to understand fftshift bug
"""
import numpy as np
import test
# Simple test case
input_arr = np.array([1+0j, 2+0j, 3+0j, 4+0j], dtype=np.complex128)
print("Input:", input_arr)
print()
# Get raw FFT (no shift)
fft_result = test.test_fft1_forward(input_arr)
print("FFT (no shift):", fft_result)
print()
# Get NumPy's FFT
numpy_fft = np.fft.fft(input_arr)
print("NumPy FFT:", numpy_fft)
print("Match?", np.allclose(fft_result, numpy_fft))
print()
# Now get shifted version
fft_shifted = test.test_fft1_with_shift(input_arr)
print("FFT (with shift):", fft_shifted)
print()
# NumPy's expected shift
numpy_shifted = np.fft.fftshift(np.fft.fft(input_arr))
print("NumPy shifted: ", numpy_shifted)
print("Match?", np.allclose(fft_shifted, numpy_shifted))
print()
# Manual fftshift on raw PocketFFT result
manual_shift = np.fft.fftshift(fft_result)
print("Manual fftshift of PocketFFT:", manual_shift)
print("Match expected?", np.allclose(manual_shift, numpy_shifted))
print()
# Check the alternating sign issue
print("Debugging alternating signs:")
sign_applied = fft_result * np.array([1 if i % 2 == 0 else -1 for i in range(len(fft_result))], dtype=complex)
print("After alternating sign mask:", sign_applied)
manual_shift2 = np.fft.fftshift(sign_applied)
print("Then shifted:", manual_shift2)