Skip to content

Commit

Permalink
Fix size of frequencies and amplitude spectrum
Browse files Browse the repository at this point in the history
We need to drop the zero-frequency term.
According to the `numpy` documentation, the zero-frequency term is the
*sum of the signal*.  That's not what we want.
The range of frequencies and the amplitudes now look meaningful for test
data.
  • Loading branch information
stefanscherzinger committed Dec 1, 2022
1 parent d092eaa commit c08ebee
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cartesian_controller_utilities/scripts/stability_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ def sensor_cb(self, data):

# Amplitude spectrum.
# We are interested only in the first half (= positive frequencies).
# Also drop the 0th element that holds the sum over all signals.
amplitude_spec = np.abs(np.fft.fftn(self.data))
amplitude_spec = amplitude_spec[0:int(self.N / 2)]
amplitude_spec = amplitude_spec[1:int(self.N / 2)]

# Compute the index where the frequencies are greater than the cross over frequency.
# The frequency spectrum is defined by the sensor rate and the sample count.
# Like with the amplitudes, we select only the relevant frequencies.
timestep = 1.0 / self.rate # sensor
freq = np.fft.fftfreq(self.N, d=timestep)
freq = freq[1:int(self.N / 2)]
if max(freq) > self.wc:
index = next(x[0] for x in enumerate(freq) if x[1] > self.wc)
else:
Expand Down

0 comments on commit c08ebee

Please sign in to comment.