awx

← Blog

Walk-through · 24 November 2026

How to find natural frequency from vibration data in Python

Pluck a steel ruler clamped to a desk and record its motion with an accelerometer. The spectrum of that recording shows the ruler’s natural frequencies. On a Small awx computer, we found three modes with frequencies 3.8 to 5.5% below beam theory. We also estimated the damping two ways and saw why one method gave the wrong answer.

Awi the cat agent with a magnifying glass

Step 1: a computer and Python

Create a Small computer in awx. We called ours vibration-fft. Open its Terminal tab and use the commands below to install the four libraries the analysis needs. Installation took 41 seconds.

python3 -m venv ~/vib
~/vib/bin/pip install numpy scipy matplotlib pandas

Everything below runs in under four seconds on a Small computer. The libraries you just installed live in ~/vib, so use ~/vib/bin/python to run the scripts. Plain python3 does not have those libraries.

Step 2: the recording

The test setup uses a stainless steel ruler, 25 mm wide and 1 mm thick, clamped to a desk with 250 mm sticking out. When you pluck the free end, an accelerometer near the tip records the vibration at 1,000 samples a second for four seconds.

For this walk-through, we made a sample recording so you can follow along without a rig. The script make_sample.py writes ruler_pluck.csv, which contains three decaying vibrations and some sensor noise. We set the frequencies 4 to 6% below beam theory to reflect the kind of shift a real clamp and sensor produce. Use the commands below to fetch the sample and the analysis script into your home folder.

cd ~
for f in make_sample.py ruler_pluck.csv vibration.py; do curl -sO https://awanbox.com/blog/files/natural-frequency/$f; done
head -3 ruler_pluck.csv
time_s,accel_ms2
0.0000,0.0002
0.0010,3.5620

The file has two columns, one for time in seconds and one for acceleration. The samples are evenly spaced. You can run ~/vib/bin/python make_sample.py to make the same file again.

Step 3: the spectrum

The full analysis is in vibration.py. The four lines below show how it finds the peaks. First, multiply the signal by a Hann window to reduce the energy that the cut ends leak across the spectrum. Then take the FFT, scale the spectrum to amplitude and find its peaks.

w = np.hanning(len(a))
spec = np.abs(np.fft.rfft(a * w)) * 2 / w.sum()
freq = np.fft.rfftfreq(len(a), 1 / fs)
idx, props = find_peaks(spec, prominence=spec.max() * 0.02)

Run the whole script from your home folder with the Python you set up earlier.

~/vib/bin/python vibration.py

When we analysed the whole four seconds, the third mode was lost in the noise, and a noise bump at 129 Hz looked like a peak. Higher modes die out in a fraction of a second, so the script runs the same four lines on the first second (a[:1000]), while all the modes are still ringing. It finds the peaks in that shorter stretch, then uses the full recording to measure each one more precisely, with 0.25 Hz steps instead of 1 Hz.

Step 4: compare with beam theory

Beam theory gives us frequencies to compare with the peaks. For a cantilever modelled as an Euler–Bernoulli beam, the natural frequencies follow this expression.

f_n = (β_n² / 2π) × √(E I / (ρ A L⁴))     β_1 = 1.8751, β_2 = 4.6941, β_3 = 7.8548

Use E = 193 GPa and ρ = 8,000 kg/m³ for stainless steel. For the ruler’s section, use I = b h³/12 and A = b h, and take L = 0.25 m for the length sticking out. The script prints the frequencies from the recording beside those from beam theory.

4000 samples at 1000 Hz, 4.00 s
measured peaks (Hz): [12.0, 76.2, 214.2]
mode 1: measured   12.0 Hz   theory   12.7 Hz   difference -5.5%
mode 2: measured   76.2 Hz   theory   79.6 Hz   difference -4.2%
mode 3: measured  214.2 Hz   theory  222.8 Hz   difference -3.8%

All three frequencies are a few percent below theory because we chose them that way when we made the sample. With a real rig, you would see the same kind of gap. In your report, explaining the gap is where you earn the marks. The clamp allows a little rotation at the root, and the accelerometer’s mass near the tip also lowers the frequencies. There is one more effect to account for. A strip 25 times wider than it is thick bends a little more like a plate, which raises the theoretical frequencies by a few percent. To see by how much, use E / (1 − ν²) instead of E.

Step 5: the damping, two ways

The damping ratio ζ tells you how quickly the ringing dies away. You can estimate it two textbook ways, using either the width of a peak or the decay of the signal. Here, the two methods give different answers.

mode 1 damping ratio, half-power bandwidth: 0.0179  (resolution 0.25 Hz: too coarse for light damping)
mode 1 damping ratio, decay in time:       0.0121

For light damping, a good rule of thumb is to use the decay in time. If you want to estimate damping from the spectrum, record for much longer so you can resolve the narrow peak.

The result

Two charts. Top: the plucked ruler's accelerometer signal, decaying from about 11 m/s² to almost nothing over 4 seconds. Bottom: the spectrum of the first second on a log scale with peaks at 12.0, 76.2 and 214.2 Hz, each just left of a dashed line for beam theory
The signal, and the spectrum of its first second: three peaks, each just left of beam theory (dashed).

With your own rig’s data

Common questions

Why use a Hann window before the FFT?

An FFT treats the recording as though it repeats forever. If the signal is cut off mid-swing, energy leaks across the spectrum. The Hann window fades both ends of the recording to zero, greatly reducing that leakage at the cost of a somewhat wider main peak.

Why are the measured frequencies lower than beam theory?

Beam theory assumes a perfectly rigid clamp and a weightless sensor. In the test setup, the clamp allows the root to rotate a little, and the accelerometer adds mass at the tip. Both effects lower the natural frequencies by a few percent.

Is the sample data real?

We generated the sample with make_sample.py so you can follow the steps without a test rig. Since we chose the frequencies and damping ourselves, the comparison with theory demonstrates the method using generated values. The analysis script works the same way with a CSV from your own accelerometer.

Do I need MATLAB for this?

You can do the whole analysis with NumPy, SciPy and matplotlib. They are free and together handle the FFT, peak finding, filtering and plotting.

Keep reading

Getting started

Sign in with your Google account and ask to join. Once you are approved, you can create a Small computer and work through the steps above.

Open awx

Awi the cat agent celebrates with confetti

Awi, signing off.

← All posts