# Measuring Resonances

<figure><img src="https://3855363247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fcs6QyzgclSdyKWWV05Sb%2Fuploads%2F8OcHCgsLKJs00nnI1r87%2F15fbbf76ad288ea6d85256ed16c4538.jpg?alt=media&#x26;token=cec4c6e7-65ed-47fd-a6ad-9b24fe44da82" alt=""><figcaption></figcaption></figure>

Input Shaper is a Klipper-specific software technique for reducing ringing (also known as echoing, ghosting or rippling) in prints. See the Klipper guide on [configuring Input Shaper](https://github.com/KevinOConnor/klipper/blob/master/docs/Resonance_Compensation.md) for more details and the complete process.

**1. Preparation**

1. **Check Connections** Ensure that your accelerometer is properly connected. To test the connection, enter the following command in Mainsail:

   ```
   ACCELEROMETER_QUERY
   ```

   You should see the current measurements from the accelerometer, including the gravity value. For example:

   ```
   Recv: // adxl345 values (x, y, z): 470.719200, 941.438400, 9728.196800
   ```
2. **Check Sensor Noise** Run the following command to measure the baseline noise on the axes:

   ```
   MEASURE_AXES_NOISE
   ```

   You should receive baseline numbers for accelerometer noise on the axes (ideally in the range of \~1-100). High noise levels (e.g., 1000 and above) may indicate sensor issues, power problems, or excessive and unbalanced fan noise.

**2. Measure Resonance**

1. **Run Resonance Tests** To perform resonance tests, use the following command:

   ```
   TEST_RESONANCES AXIS=X
   ```

   This will generate vibrations along the X-axis. If input shaping is enabled, it will be temporarily disabled, as resonance testing is ineffective with input shaping active.

   **Warning**: Observe the printer during the test to ensure vibrations do not become excessive. You can stop the test in an emergency using the command if necessary. If vibrations are too strong, consider adjusting the `accel_per_hz` parameter in the `[resonance_tester]` section of your configuration file:

   ```
   [resonance_tester]
   accel_chip: adxl345
   accel_per_hz: 50  # default is 75
   probe_points: ...
   ```

   Repeat the test for the Y-axis:

   ```
   TEST_RESONANCES AXIS=Y
   ```

   This will generate two CSV files:`/tmp/resonances_x_*.csv` and `/tmp/resonances_y_*.csv` .
2. Process these files using the script on your Pi via an [SSH tool](https://docs.siboor.com/siboor-trident-june/the-build/ssh-quick-guide). You can either use a single CSV file for each axis or average results from multiple CSV files if you performed tests at different points. If you do not wish to average results, delete any extra CSV files.Process the CSV files with:

   ```
   ~/klipper/scripts/calibrate_shaper.py /tmp/resonances_x_*.csv -o /tmp/shaper_calibrate_x.png
   ~/klipper/scripts/calibrate_shaper.py /tmp/resonances_y_*.csv -o /tmp/shaper_calibrate_y.png
   ```

   This script will generate charts at `/tmp/shaper_calibrate_x.png` and `/tmp/shaper_calibrate_y.png`, showing frequency responses. You’ll also receive recommended frequencies and shapers for your settings. For example:

<figure><img src="https://3855363247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fcs6QyzgclSdyKWWV05Sb%2Fuploads%2FtuaFPxrjF03rYgD1H3r1%2Fimage.png?alt=media&#x26;token=8e0c42d9-9a34-4c4e-9ffe-312ee768fa8b" alt=""><figcaption></figcaption></figure>

```
Fitted shaper 'zv' frequency = 34.4 Hz (vibrations = 4.0%, smoothing ~= 0.132)
To avoid too much smoothing with 'zv', suggested max_accel <= 4500 mm/sec^2
Fitted shaper 'mzv' frequency = 34.6 Hz (vibrations = 0.0%, smoothing ~= 0.170)
To avoid too much smoothing with 'mzv', suggested max_accel <= 3500 mm/sec^2
Fitted shaper 'ei' frequency = 41.4 Hz (vibrations = 0.0%, smoothing ~= 0.188)
To avoid too much smoothing with 'ei', suggested max_accel <= 3200 mm/sec^2
Fitted shaper '2hump_ei' frequency = 51.8 Hz (vibrations = 0.0%, smoothing ~= 0.201)
To avoid too much smoothing with '2hump_ei', suggested max_accel <= 3000 mm/sec^2
Fitted shaper '3hump_ei' frequency = 61.8 Hz (vibrations = 0.0%, smoothing ~= 0.215)
To avoid too much smoothing with '3hump_ei', suggested max_accel <= 2800 mm/sec^2
Recommended shaper is mzv @ 34.6 Hz

```

Add the recommended configuration to the `[input_shaper]` section of your `printer.cfg`:

```
[input_shaper]
shaper_freq_x: ...
shaper_type_x: ...
shaper_freq_y: 34.6
shaper_type_y: mzv

[printer]
max_accel: 3000  # should not exceed the estimated max_accel for X and Y axes
```

Alternatively, select other configurations based on the charts. The peaks in the power spectral density on the charts correspond to the resonance frequencies of the printer.

**3. Automatic Input Shaper Calibration**

1. **Run Automatic Calibration** Instead of manually selecting shaper parameters, you can run automatic input shaper calibration from Klipper. Use the following command in Octoprint:

   ```
   SHAPER_CALIBRATE
   ```

   This will perform a full test for both axes and generate frequency response and suggested shaper CSV output (`/tmp/calibration_data_*.csv` by default). Recommended shapers and frequencies will be displayed in the Octoprint console. For example:

   ```
   Calculating the best input shaper parameters for y axis
   Fitted shaper 'mzv' frequency = 36.8 Hz (vibrations = 1.7%, smoothing ~= 0.150)
   ```

   If you agree with the suggested parameters, use the `SAVE_CONFIG` command to save them and restart Klipper. Note that this does not update the `max_accel` value in the `[printer]` section. You should manually update it based on the recommendations.
