This Python script is designed to process Electromyography (EMG) data stored in CSV format. EMG data typically represents electrical signals generated by muscle activity and is commonly used in various fields such as biomechanics, sports science, and rehabilitation.
Before running the script, ensure you have the following installed:
- Python 3.x
- Required Python packages: pandas, matplotlib, numpy, scipy
-
Input Data: The input EMG data should be stored in a CSV file format. You can specify the file path in the
input_file_path
variable within themain()
function. -
Output Data: Processed EMG data will be saved as CSV files in the 'output' directory. The file paths are specified by the
output_file_path
andrms_output_file_path
variables in themain()
function. -
Running the Script: Simply execute the script. The
main()
function orchestrates the entire data processing pipeline.
-
read_emg_data(file_path): Reads EMG data from a CSV file and returns it as a pandas DataFrame.
-
full_wave_rectification(emg_data): Performs full-wave rectification on the EMG data, converting negative values to positive.
-
non_inverting_amplifier(emg_data, gain): Simulates a non-inverting amplifier by amplifying the EMG signals by a specified gain factor.
-
butter_filter(cutoff_freq, sampling_freq, btype, order=2): Designs a Butterworth filter.
-
butter_filter_signal(emg_data, cutoff_freq, sampling_freq, btype, order=2): Applies a Butterworth filter to the EMG signal.
-
rms_smoothing(emg_data, window_size): Performs Root Mean Square (RMS) smoothing on the EMG data using a moving window.
-
movag_smoothing(emg_data, window_size): Performs Moving Average (MOVAG) smoothing on the EMG data using a moving window.
-
plot_emg_data(emg_data): Plots the EMG data.
-
save_emg_data(emg_data, file_path): Saves the EMG data to a CSV file.
-
Full Wave Rectification: Converts EMG signals to their absolute values.
-
Amplification: Increases the magnitude of EMG signals using a specified gain.
-
High-pass and Low-pass Filtering (Optional): Butterworth filters can be applied to remove unwanted noise from the EMG signals.
-
Smoothing: Two smoothing techniques are provided: Root Mean Square (RMS) and Moving Average (MOVAG).
-
Plotting and Saving: Processed EMG data can be visualized using matplotlib and saved as CSV files for further analysis.
-
Some filtering and smoothing functions are currently commented out in the
main()
function. Uncomment and adjust parameters as needed for your specific data processing requirements. -
Make sure to customize the file paths and processing parameters according to your data and analysis needs.
if __name__ == "__main__":
main()