Skip to content

Commit

Permalink
Update TDR.py
Browse files Browse the repository at this point in the history
Fix math with TDR
  • Loading branch information
EnPassant123 authored and zarath committed Oct 2, 2024
1 parent 5cc1ee1 commit 3e54d95
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/NanoVNASaver/Windows/TDR.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,23 @@ def updateTDR(self):
return

s11 = [complex(d.re, d.im) for d in self.app.data.s11]
window = np.blackman(len(self.app.data.s11))
s11 = np.array(s11)
s11 = np.concatenate([s11, np.conj(s11[-1:0:-1])]) # Include negative frequencies
s11 = np.fft.fftshift(s11)

window = np.blackman(len(s11))
windowed_s11 = window * s11 # Now windowing eliminates higher frequencies while leaving low frequencies untouched

pad_points = (FFT_POINTS - len(windowed_s11)) // 2
windowed_s11 = np.pad(windowed_s11, [pad_points + 1, pad_points]) # Pad array to length FFT_POINTS
windowed_s11 = np.fft.ifftshift(windowed_s11)

td = np.fft.ifft(windowed_s11)

windowed_s11 = window * s11
td = np.abs(np.fft.ifft(windowed_s11, FFT_POINTS))
step = np.ones(FFT_POINTS)
step_response = convolve(td, step)

self.step_response_Z = 50 * (1 + step_response) / (1 - step_response)
self.step_response_Z = np.abs(50 * (1 + step_response) / (1 - step_response)) #Can plot impedance in terms of real and imaginary too

time_axis = np.linspace(0, 1 / step_size, FFT_POINTS)
self.distance_axis = time_axis * v * speed_of_light
Expand Down

0 comments on commit 3e54d95

Please sign in to comment.