This repository contains a Python script for analyzing accelerometer data obtained from drop tests. The script processes the data, performs interpolation and convolution, and visualizes the acceleration over time for each drop test.
To run the script, you need to have the following dependencies installed:
pandas: A library for data manipulation and analysis.numpy: A library for numerical computing in Python.scipy: A library for scientific computing in Python, used for interpolation and signal processing.matplotlib: A plotting library for creating visualizations.seaborn: A data visualization library based on matplotlib.
You can install the required dependencies using pip:
pip install pandas numpy scipy matplotlib seaborn
-
Clone the repository to your local machine or download the code files.
-
Ensure that you have the accelerometer data files in CSV format stored in the specified folder (
/home/jamie/Documents/Accelerometer_Drop_Testing/2023-05-26 Drop Test C25). -
Open the Python script in a Jupyter Notebook or any Python IDE.
-
Set the
sample_rate_hzvariable to the desired sample rate of the accelerometer data. -
Run the script.
The script will iterate through each CSV file in the specified folder, process the data, and generate plots showing the acceleration over time for each drop test. The processed data includes interpolation and convolution to enhance the accuracy of the results.
The script generates two sets of plots:
-
Raw Acceleration Data: This set of plots shows the raw acceleration data for each drop test. Each plot represents a different drop test, with the time (ms) on the x-axis and acceleration (m/s^2) on the y-axis.
-
Convolved Acceleration Data: This set of plots shows the convolved acceleration data for each drop test. Convolution is applied to smooth the acceleration signal and reduce noise. Similar to the raw data plots, each plot represents a different drop test, with time (ms) on the x-axis and convolved acceleration (m/s^2) on the y-axis.
The plots provide insights into the acceleration profiles during the drop tests, allowing for further analysis and interpretation of the results.
The AccelerometerDropTest class is defined in the code to encapsulate the functionality related to processing accelerometer data for drop tests. Here is a breakdown of the class and its methods:
The constructor method initializes an instance of the AccelerometerDropTest class. It takes in the path to the accelerometer data file (path) and the sample rate in hertz (sample_rate_hz). Within this method:
- The file name is extracted from the given path.
- The first line of the CSV file is modified to ensure it ends with a comma.
- The data is read from the CSV file into a
pandasDataFrame. - Column names are renamed to more descriptive labels.
- Additional columns for time in milliseconds (
Time (ms)) and acceleration in meters per second squared (Acceleration m/s^2) are added to the DataFrame based on the index and the accelerometer data in the original columns.
This method performs interpolation on the acceleration data to create a uniformly spaced time series of acceleration values. The interpolated data is stored in a new DataFrame called TC_data. The steps involved are:
- The minimum and maximum time values from the original data are determined.
- The number of points required for interpolation is calculated based on a time resolution of 0.25 milliseconds.
- The
TC_dataDataFrame is created with a new column for time. - The
interp1dfunction fromscipy.interpolateis used to perform cubic interpolation on the original acceleration data, generating a smooth curve for the new time series.
This method calculates the velocity based on the interpolated acceleration data in the TC_data DataFrame. The velocity is computed using the cumtrapz function from scipy.integrate with the time and acceleration data as inputs. The resulting velocity values are stored in a new column called Velocity m/s.
This method applies convolution to the velocity data in the TC_data DataFrame to smooth the signal and reduce noise. The convolution is performed using a kernel created from a vector of ones divided by the specified length_of_kernel. The resulting convolved velocity values are stored in a new column called Convolved Velocity m/s.
Similar to the previous method, this method applies convolution to the acceleration data in the TC_data DataFrame to smooth the signal and reduce noise. The resulting convolved acceleration values are stored in a new column called Convolved Acceleration m/s^2.
The __repr__ method overrides the default representation of the class and returns a string that provides information about the accelerometer drop test, including the name of the file.
This class provides a convenient way to process accelerometer data for drop tests and perform operations such as interpolation, velocity calculation, and convolution on the data.