Currently, the velocity of the resonance test signal is a triangle wave, with square wave acceleration.
By incorporating brief constant velocity sections into the test signal, it is possible to achieve a better sine wave. All we have to do is reduce the maximum velocity:
diff --git a/klippy/extras/resonance_tester.py b/klippy/extras/resonance_tester.py
index db03e3207..64b9afcc7 100644
--- a/klippy/extras/resonance_tester.py
+++ b/klippy/extras/resonance_tester.py
@@ -91,11 +91,11 @@ class VibrationPulseTest:
gcmd.respond_info("Testing frequency %.0f Hz" % (freq,))
while freq <= self.freq_end + 0.000001:
t_seg = .25 / freq
- accel = self.accel_per_hz * freq
- max_v = accel * t_seg
+ accel = self.accel_per_hz * freq * 1.08813
+ max_v = accel * t_seg * 0.74202
toolhead.cmd_M204(self.gcode.create_gcode_command(
"M204", "M204", {"S": accel}))
- L = .5 * accel * t_seg**2
+ L = 0.46672 * accel * t_seg**2
dX, dY = axis.get_point(L)
nX = X + sign * dX
nY = Y + sign * dY
I obtained this factor by maximizing the SNR of the fundamental harmonic over higher harmonics. The optimal duration of the acceleration is 0.742 time shorter than in a pure square wave. There is no closed form solution, but you can ask for the derivation details. This should yield a 40% reduction in the ratio of higher harmonic power to fundamental harmonic power.
Hereâs the square-wave acceleration signal currently used by the resonance tester:
SNR: 2.07
- blue: square wave signal,
- green: fundamental harmonic,
- orange: sum of the 10 following harmonics, acting like the differences of the blue and green curve with a low-pass filter.
Introducing cruised segments between accelerations reduces the higher harmonics:
SNR: 3.45
(note the segments with zero acceleration around x=0.25)
Velocity signal:
- orange: current velocity signal,
- blue: velocity with cruised sections,
- green: true sine wave (fundamental harmonic)
The effect on the position signal more subtle.
The question arises as to whether we should reduce these higher harmonics. I donât believe that their presence is negatively impacting the accuracy of the test. Currently, the accelerometerâs spectra are averaged throughout the entire sweep, rendering it inconsequential which vibration mode is stimulated at any given moment. When we stimulate at 50 Hz, a certain amount of energy is inevitably distributed to 150 Hz, 250 Hz, and so on, with the resonance amplitudes contributing to the final results within these frequency bins. This leads to an increase in gain at higher frequencies, but this outcome is actually desired. I believe the accel_per_hz
parameter was added to intentionally increase the sensibility at higher frequencies.
On the other hand, having 1/3 of the energy in higher harmonics might exerts more strain on the printer when measuring high frequencies. Although, it is possible that the springiness of the steppers take them out.
TEST_RESONANCES
is sometime used with a very slow hz_per_sec
, targeting a single frequency in order to pinpoint a resonance or find rattling parts. This use case may benefit from a cleaner test signal.
This could also prove handy if a future method for measuring resonances correlates the test signal frequency with the accelerometer output. Increasing the number of movement segments would yield an even cleaner test signal, albeit not entirely free of harmonics due to inherent non-linearities in the stepper and mechanical components.
In the end, itâs a bit of a moot point, but the modification is straightforward.
Iâm currently testing this to see if I see positive changes in the spectrograms.