Calculating Velocity and Displacement from Vibration Data

0 Comments
Share This
Share This

Calculating Velocity and Displacement from Vibration Data

 

You can convert acceleration data into velocity and displacement by integrating it once for velocity and twice for displacement. Direct integration usually fails because sensor bias and low-frequency noise cause integration drift. Applying a high-pass filter and a Tukey window before integrating removes most of that drift, and the enDAQ Python library automates these steps. This guide walks through the method, a full Python example, and a validation against a laser displacement sensor. 

Content

  1. Introduction

  2. The Relationship Between Acceleration, Velocity, and Displacement

  3. Numerical Integration of Measured Data

  4. Why Direct Integration Often Fails

  5. Reducing Integration Drift

    5.1. High-Pass Filtering

    5.2. Windowing and Tapering

     

  6. Using the enDAQ Library for Motion Analysis

  7. Example: Converting Acceleration to Velocity and Displacement Using Python

  8. Comparing measured displacement with converted displacement

  9. Web-based app

    9.1. Web Application Link:

    9.2. Step 1: Upload an IDE File.

    9.3. Step 2: Select the Measurement Axis

    9.4. Step 3: Select the Time Interval

    9.5. Step 4: Adjust Advanced Parameters (Optional)

    9.6. Step 5: Process the Signal

    9.7. Step 6: Download the Results

  10. Light offline app
  11. Conclusions

Introduction

Accelerometers are among the most widely used sensors in engineering applications, including structural health monitoring, machinery diagnostics, predictive maintenance, automotive testing, and aerospace systems. These sensors directly measure acceleration, which is the rate of change of velocity with respect to time. However, engineers are often interested in other quantities such as velocity and displacement, since they can provide more intuitive information about motion and vibration behavior.

Fortunately, velocity and displacement can be obtained from acceleration measurements through a mathematical process known as integration. While the concept is straightforward, practical implementation requires careful signal processing to avoid errors caused by sensor noise and bias.

This article explains how acceleration is converted into velocity and displacement and discusses the challenges associated with the process.


The Relationship Between Acceleration, Velocity, and Displacement

The three motion quantities are mathematically related through differentiation and integration.

Acceleration is defined as the rate of change of velocity:

Similarly, velocity is the rate of change of displacement:

By reversing these relationships, velocity can be obtained by integrating acceleration:

Displacement is then obtained by integrating velocity:

Combining both steps results in:

In other words:

    1. One integration converts acceleration to velocity.
    2. Two integrations convert acceleration to displacement.

Numerical Integration of Measured Data

Real-world acceleration data are collected at discrete time intervals rather than as continuous functions. Therefore, numerical methods must be used to perform integration.

One of the most common approaches is the trapezoidal integration method. For a signal sampled at a constant time interval Δt, velocity can be approximated as:

Similarly, displacement can be calculated from the velocity signal:

These calculations are repeated for every sample in the dataset.


Why Direct Integration Often Fails

Although the mathematics is simple, direct integration of measured acceleration data often produces unrealistic results.

The reason is that accelerometers are not perfect. Measurements typically contain:

    1. Sensor bias
    2. Electronic noise
    3. Temperature drift
    4. Quantization errors
    5. Low-frequency disturbances

Consider an accelerometer with a small offset of only 0.01 m/s². Integrating this constant error produces a velocity that grows linearly with time:

A second integration produces displacement that grows quadratically:

Even a tiny measurement bias can therefore generate enormous displacement errors after a few minutes of data collection.

This phenomenon is known as integration drift.


Reducing Integration Drift

To obtain meaningful velocity and displacement measurements, signal conditioning is typically applied before integration.

High-Pass Filtering

A high-pass filter removes very low-frequency content, including DC offsets and sensor bias.

For example, a cutoff frequency of 1 Hz removes signal components below 1 Hz while preserving higher-frequency vibration content.

This significantly reduces drift during integration.

However, there is a tradeoff. If the system actually contains meaningful motion below the cutoff frequency, that information will also be removed.

Windowing and Tapering

Another common technique is applying a window function before integration.

A popular choice is the Tukey window, which gradually reduces the signal amplitude near the beginning and end of the record.

Benefits include:

  1. Reduced edge effects
  2. Smoother signal transitions
  3. Improved integration stability
  4. Lower spectral leakage during frequency-domain processing

A Tukey window is particularly useful when analyzing finite-duration vibration events.


Using the enDAQ Library for Motion Analysis

While the mathematical concepts behind acceleration, velocity, and displacement are straightforward, implementing them correctly requires careful signal processing to minimize integration drift and noise. The Python enDAQ library provides built-in tools that automate many of these processing steps, making it easier to obtain reliable velocity and displacement measurements from acceleration data.

In addition to numerical integration, the enDAQ library offers a wide range of capabilities for vibration and shock analysis, including time-domain visualization, frequency analysis, filtering, power spectral density (PSD) calculations, shock response spectrum (SRS) analysis, data extraction from IDE files, and interactive plotting. These tools allow engineers and researchers to process, analyze, and visualize sensor data using a consistent workflow.

The example presented in this article uses the enDAQ library to convert acceleration measurements into velocity and displacement while applying signal conditioning techniques such as high-pass filtering and Tukey windowing to reduce integration drift.

The enDAQ Python library can be installed directly from PyPI using:

pip install endaq

or, within a Jupyter Notebook:

!pip install endaq

Note: Plotly libraries is also used, which may need to be installed (if they are not already available in your Python environment.) using

!pip install plotly


Example: Converting Acceleration to Velocity and Displacement Using Python

The following example demonstrates a complete workflow for converting acceleration data stored in an IDE file into velocity and displacement.

To this end, an enDAQ accelerometer was mounted on the top surface of a shaker, as shown in Figure 1. To validate the measurements, the shaker displacement was simultaneously measured using a laser displacement sensor mounted above the enDAQ and directed toward its top surface. The shaker acceleration was recorded for approximately 100 seconds.

Figure 1
Figure 1: Experimental setup for measuring shaker acceleration using an enDAQ accelerometer. A laser displacement sensor is mounted above the enDAQ to simultaneously measure the shaker displacement.

 

The process consists of:

  1. Plotting the raw acceleration signal.
  2. Selecting the time range of interest.
  3. Extracting the desired portion of the recording.
  4. Computing velocity and displacement through numerical integration.
  5. Visualizing the results.
  6. Exporting the processed data to a CSV file.

Step 1 – Plot the Raw Acceleration Signal

Before processing, it is often helpful to visualize the entire acceleration record and identify the time interval of interest.


# =========================
# PARAMETERS
# =========================

# Full path to the IDE file
ide_path = r"C:\Users\hdabiri\Downloads\DAQ18302_000105_Sin_Sweep_1.IDE"
# >>>>>>>> change the file path to your IDE file

ACCEL_40G = 80      # Channel number for 40g accelerometer (change if different in your IDE file)
X, Y, Z = [0, 1, 2] # Subchannel indices for X, Y, Z axes (change if different in your IDE file)
G_TO_M2S = 9.81      # Convert g to m/s^2


# =========================
# FUNCTION TO LOAD AND PLOT RAW ACCELERATION
# Helps user choose start/end times
# =========================

def plot_raw_acceleration(ide_path, accel_channel, axis, g_to_m2s=9.81):
    """
    Load an IDE file and plot the raw acceleration signal for a chosen axis.

    Parameters:
    - ide_path: Full path to the IDE file.
    - accel_channel: Channel number for the accelerometer (e.g., 80 for 40g accelerometer).
    - axis: Subchannel index for the axis to plot (0 = X, 1 = Y, 2 = Z).
    - g_to_m2s: Conversion factor from g to m/s^2 (default is 9.81).

    Returns:
    - doc_full: The full loaded IDE document (for reuse in further processing).
    - df_preview: DataFrame containing the acceleration data in m/s^2, indexed by time [s].
    """
    # Load ORIGINAL IDE file
    doc_full = endaq.ide.get_doc(ide_path)

    # Read acceleration channel
    df_preview = endaq.ide.to_pandas(
        doc_full.channels[accel_channel].subchannels[axis],
        time_mode='seconds',  # Time in seconds
    ) * g_to_m2s  # Convert g to m/s^2

    # Rename column
    df_preview.columns = ['acceleration']

    return doc_full, df_preview


# Example Usage
# Load and plot raw acceleration for the Z axis (change axis to X or Y if desired)
doc_full, df_preview = plot_raw_acceleration(
    ide_path, ACCEL_40G, Z, g_to_m2s=G_TO_M2S
)

# Plotting the raw acceleration signal using Plotly

fig_preview = go.Figure()

# Add trace for the selected axis acceleration
fig_preview.add_trace(go.Scatter(
    x=df_preview.index,
    y=df_preview['acceleration'],
    mode='lines',
    name='Acceleration',
    line=dict(color='blue')
))

# Update layout for the plot
fig_preview.update_layout(
    title="Raw Acceleration Signal",
    xaxis_title="Time [s]",
    yaxis_title="Acceleration [m/s²]",
    legend_title="Channels",
    template="plotly",   # Use the default white background
    plot_bgcolor='white',  # Set plot background to white
    paper_bgcolor='white',  # Set paper background to white
    height=800,
    hovermode='x unified',
    showlegend=True
)

# Show the plot
fig_preview.show()
Figure 2
Figure 2: Raw acceleration data
The second part of the script, convert acceleration to velocity and displacement, plots the results, and save them as csv in the same folder where the ide file exists. How the conversion is performed is described below.
## =========================
## USER INPUTS (EDIT ONLY THESE)
## =========================

# Start and end times in seconds
start_time = 60
end_time = 70

## =========================    (DO NOT CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING)
## IMPORT LIBRARIES
## =========================

import os
import plotly.express as px
import endaq

# Optional theme
# endaq.plot.utilities.set_theme('endaq_light')

## =========================
## CREATE OUTPUT FILE NAMES
## =========================

# Get folder and file name
folder_path = os.path.dirname(ide_path)

# File name without extension
base_name = os.path.splitext(os.path.basename(ide_path))[0]

# Extracted IDE file name
extracted_ide_path = os.path.join(folder_path, f"{base_name}_EXTRACTED.ide")

# CSV output file name
csv_output_path = os.path.join(folder_path, f"{base_name}_CSV.csv")

## =========================
## EXTRACT TIME RANGE (start_time to end_time)
## =========================

endaq.ide.extract_time(    
    ide_path,
    extracted_ide_path,
    start=str(start_time),
    end=str(end_time)
)

## =========================
## LOAD ACCELERATION DATA
## =========================

doc = endaq.ide.get_doc(extracted_ide_path)

df_accel = endaq.ide.to_pandas(                         # Read acceleration channel
    doc.channels[80].subchannels[2],
    time_mode='seconds',
) * 9.81   # Convert g to m/s^2                        

## =========================
## CALCULATE VELOCITY & DISPLACEMENT
## =========================

integrals = endaq.calc.integrate.integrals(
    df_accel,
    n=2,                                                # Number of integrals to compute (1 for velocity, 2 for displacement)
    highpass_cutoff=5.0,                                # Remove low-frequency drift (adjust cutoff as needed)
    tukey_percent=0.2                                   # Apply a Tukey window to minimize edge effects (adjust percentage as needed) 
)

df_velocity = integrals[1]                              # Velocity is the first integral

df_displacement = integrals[2]                          # Displacement is the second integral

# Rename columns
df_accel.columns = ['acceleration']
df_velocity.columns = ['velocity']
df_displacement.columns = ['displacement']

# Convert:
# velocity: m/s -> mm/s
# displacement: m -> mm
df_velocity = df_velocity * 1e3                         # Convert m/s to mm/s
df_displacement = df_displacement * 1e3                 # Convert m to mm    

# Combine all data
df_accel = df_accel.join(df_velocity, how='left')
df_accel = df_accel.join(df_displacement, how='left')

## =========================
## PLOT RESULTS
## =========================

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(
    rows=3,                             # number of rows
    cols=1,                             # number of columns
    shared_xaxes=True,                  # share x-axis across all subplots
    vertical_spacing=0.05,              # space between subplots
    subplot_titles=(                    
        "Acceleration",                 # titles for each subplot
        "Velocity",
        "Displacement"
    )
)

# Acceleration
fig.add_trace(
    go.Scatter(
        x=df_accel.index,               # time in seconds
        y=df_accel["acceleration"],     # acceleration in m/s^2
        name="Acceleration"             # trace name (appears in legend and hover)
    ),
    row=1,                              # subplot row
    col=1                               # subplot column
)

# Velocity
fig.add_trace(
    go.Scatter(
        x=df_accel.index,               # time in seconds
        y=df_accel["velocity"],         # velocity in mm/s     
        name="Velocity"                 # trace name (appears in legend and hover)
    ),
    row=2,
    col=1
)

# Displacement
fig.add_trace(
    go.Scatter(
        x=df_accel.index,               # time in seconds  
        y=df_accel["displacement"],     # displacement in mm
        name="Displacement"             # trace name (appears in legend and hover)
    ),
    row=3,                              # subplot row
    col=1                               # subplot column
)

# Axis labels
fig.update_yaxes(
    title_text="m/s²",                  # y-axis label for acceleration
    row=1,
    col=1
)

fig.update_yaxes(
    title_text="mm/s",                  # y-axis label for velocity
    row=2,
    col=1
)

fig.update_yaxes(
    title_text="mm",                    # y-axis label for displacement
    row=3,
    col=1
)

fig.update_xaxes(
    title_text="Time [s]",              # x-axis label for all subplots
    row=3,
    col=1
)

# Layout
fig.update_layout(
    height=900,                                         # adjust height of the plot as needed
    width=1300,                                         # adjust width as needed
    hovermode="x unified",                              # better hover interaction across subplots
    showlegend=False,                                   # legend is not needed since we have titles, but can be enabled if desired
    title="Acceleration, Velocity, and Displacement"    # overall title for the figure
)

fig.show()

## =========================
## SAVE CSV
## =========================

df_accel.to_csv(csv_output_path)

print("\nCSV file saved to:")
print(csv_output_path)

## =========================
## SAVE xlsx (optional)
## =========================

# df_accel.to_excel(xlsx_output_path, index=False)   # Save to Excel without the index column

# print("\nExcel file saved to:")
# print(csv_output_path)

 

After examining the plot, choose the start and end times of the event you want to analyze.

Step 2 – Specify the Analysis Window

# Start and end times in seconds
start_time = 60
end_time = 70

 

Step 3 – Extract the Desired Time Range

The selected portion of the recording is extracted into a new IDE file.

endaq.ide.extract_time(
    ide_path,
    extracted_ide_path,
    start=str(start_time),
    end=str(end_time)
)

 

Step 4 – Load the Acceleration Data

The acceleration data are converted from units of g to m/s².

df_accel = endaq.ide.to_pandas(
    doc.channels[80].subchannels[2],
    time_mode='seconds',
) * 9.81   # Convert g to m/s^2

Step 5 – Calculate Velocity and Displacement

Velocity is obtained through one integration of the acceleration signal, while displacement is obtained through a second integration.

The endaq.calc.integrate.integrals() function automatically applies:

    • A 1 Hz high-pass filter to reduce drift.
    • A 5% Tukey window to reduce edge effects.
    • Numerical integration using the filtered signal.
integrals = endaq.calc.integrate.integrals(
    df_accel,
    n=2,                                                # Number of integrals to compute (1 for velocity, 2 for displacement)
    highpass_cutoff=5.0,                                # Remove low-frequency drift (adjust cutoff as needed)
    tukey_percent=0.2                                   # Apply a Tukey window to minimize edge effects (adjust percentage as needed) 
)

df_velocity = integrals[1]                              # Velocity is the first integral

df_displacement = integrals[2]                          # Displacement is the second integral

# Rename columns
df_accel.columns = ['acceleration']
df_velocity.columns = ['velocity']
df_displacement.columns = ['displacement']


 

Step 6 – Convert Engineering Units

For vibration analysis, velocity and displacement are often reported in millimeters rather than meters.

# Convert:
# velocity: m/s -> mm/s
# displacement: m -> mm
df_velocity = df_velocity * 1e3
df_displacement = df_displacement * 1e3

Step 7 – Plot the Results

The acceleration, velocity, and displacement signals can then be displayed together.

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(
    rows=3,                             # number of rows
    cols=1,                             # number of columns
    shared_xaxes=True,                  # share x-axis across all subplots
    vertical_spacing=0.05,              # space between subplots
    subplot_titles=(                    
        "Acceleration",                 # titles for each subplot
        "Velocity",
        "Displacement"
    )
)

# Acceleration
fig.add_trace(
    go.Scatter(
        x=df_accel.index,               # time in seconds
        y=df_accel["acceleration"],     # acceleration in m/s^2
        name="Acceleration"             # trace name (appears in legend and hover)
    ),
    row=1,                              # subplot row
    col=1                               # subplot column
)

# Velocity
fig.add_trace(
    go.Scatter(
        x=df_accel.index,               # time in seconds
        y=df_accel["velocity"],         # velocity in mm/s     
        name="Velocity"                 # trace name (appears in legend and hover)
    ),
    row=2,
    col=1
)

# Displacement
fig.add_trace(
    go.Scatter(
        x=df_accel.index,               # time in seconds  
        y=df_accel["displacement"],     # displacement in mm
        name="Displacement"             # trace name (appears in legend and hover)
    ),
    row=3,                              # subplot row
    col=1                               # subplot column
)

# Axis labels
fig.update_yaxes(
    title_text="m/s²",                  # y-axis label for acceleration
    row=1,
    col=1
)

fig.update_yaxes(
    title_text="mm/s",                  # y-axis label for velocity
    row=2,
    col=1
)

fig.update_yaxes(
    title_text="mm",                    # y-axis label for displacement
    row=3,
    col=1
)

fig.update_xaxes(
    title_text="Time [s]",              # x-axis label for all subplots
    row=3,
    col=1
)

# Layout
fig.update_layout(
    height=900,                                         # adjust height of the plot as needed
    width=1300,                                         # adjust width as needed
    hovermode="x unified",                              # better hover interaction across subplots
    showlegend=False,                                   # legend is not needed since we have titles, but can be enabled if desired
    title="Acceleration, Velocity, and Displacement"    # overall title for the figure
)

fig.show()


Figure 2
Figure 3: Top: raw acceleration data in the selected time windows (start and end time); middle: velocity (mm/s); bot: displacement (mm)

 

Step 8 – Export the Data

Finally, the processed data can be exported to a CSV file for further analysis.

## =========================
## SAVE CSV
## =========================

df_accel.to_csv(csv_output_path)

print("\nCSV file saved to:")
print(csv_output_path)


Or xlsx, if needed:

## =========================
## SAVE xlsx (optional)
## =========================

# df_accel.to_excel(xlsx_output_path, index=False)   # Save to Excel without the index column

# print("\nExcel file saved to:")
# print(csv_output_path)

This workflow provides a practical method for converting measured acceleration data into velocity and displacement while minimizing integration drift through filtering and windowing.


Comparing measured displacement with converted displacement

Figure 4 compares the displacement measured by the laser displacement sensor (blue line) with the displacement converted by the algorithm presented in this article over three time windows: 30–40 s (red line), 60–70 s (green line), and 80–90 s (purple line). As shown, the converted displacement closely matches the measured displacement across all three time windows, demonstrating that the proposed algorithm accurately reconstructs the displacement signal.

a

Figure 4a

b

Figure 4b
Figure 4: (a): comparing measured displacement (blue line) with converted displacement using the Algo for three different windows: 30-40 s (red line), 60-70 s (green line) and 80-90 s (purple line); (b): zoomed-in plot for 60-70 s (green line).

 

Web-based app

The script has been implemented in a web-based application that allows users to upload an IDE file, visualize the recorded data, convert acceleration to velocity and displacement, and download the processed results as a CSV file. This section briefly explains how to use the web-based application.

Web Application Link:

https://mideaccelerationtodisplacement-8uddn3q8b8fp8pmojrug3e.streamlit.app/

Step 1: Upload an IDE File

First, upload the IDE file that contains the recorded acceleration data. Please note that the uploaded file must be smaller than 200 MB.

Step 2: Select the Measurement Axis

After uploading the file, select the axis (X, Y, or Z) for which you want to convert the acceleration data into velocity and displacement.

Once the file has been uploaded and the axis has been selected, the application displays the acceleration (m/s²) versus time (s) plot.

Figure 4

Step 3: Select the Time Interval

Specify the start and end times of the interval you want to process. For example, if you want to analyze the data between 80 and 90 seconds, enter 80 as the start time and 90 as the end time.

Step 4: Adjust Advanced Parameters (Optional)

The application also provides two advanced parameters that can be adjusted if needed:

    • High-Pass Cutoff Frequency (Hz): Removes the DC offset and very low-frequency drift before integration. Increasing this value reduces integration drift but may also remove genuine low-frequency motion from the signal.
    • Tukey Window Percentage: Applies a Tukey window to taper the beginning and end of the selected signal, reducing edge effects during numerical integration. Typical values range from 0.02 to 0.10.

The default values are:

    • High-Pass Cutoff Frequency: 5.0 Hz
    • Tukey Window Percentage: 0.20
Figure 5

Step 5: Process the Signal

Click "Process Signal" to convert the selected acceleration data into:

    • Velocity (m/s)
    • Displacement (mm)
Figure 6

The application then plots the acceleration, velocity, and displacement signals.

Step 6: Download the Results

After processing is complete, click "Download CSV (Acceleration, Velocity + Displacement)" to download a CSV file containing the acceleration, velocity, and displacement data for the selected time interval.

Figure 7

Light offline app

An offline application has also been developed to convert acceleration data into velocity and displacement:

The offline application uses the same parameters as those described for the web-based application. Users can select an IDE file to convert acceleration data into velocity and displacement, with the results exportable as a CSV file:

Conclusions

This work presents a practical workflow for converting acceleration measurements from IDE files into velocity and displacement using numerical integration and signal-processing techniques to minimize integration drift. The converted displacement was compared with measurements from a laser displacement sensor, showing good agreement across multiple time intervals. Both web-based and offline applications have also been developed to simplify data processing, visualization, and CSV export, providing users with accessible tools for vibration analysis and motion characterization.

 

“The accuracy of velocity and displacement calculations begins with the quality of the acceleration data. High-resolution, low-noise acceleration data lead to more reliable integration results.”

Share This

Hamed Dabiri

Hamed earned his PhD in 2022, focusing on ML applications in structural dynamics. He then completed a postdoctoral fellowship at Imperial College London, studying Material Strength and ML. With over 27 published papers, his research spans ML, structural dynamics, and material behavior. In 2024, Hamed became a Senior ML Engineer at Mide Technology, applying his...

By signing up you are agreeing to our Privacy Policy