function [emg_env, emg_filt] = signalProcess(emg_rawdata, fs, lowpass_coef, highpass_coef) % signalProcess processes raw EMG signals by applying bandpass filtering, % rectification, outlier removal, and RMS envelope extraction. % INPUTS: % emg_rawdata : Raw EMG signal data (nFrames × nEMGs) % fs : EMG sampling frequency (e.g., 2000 Hz) % lowpass_coef : Lower cutoff frequency for bandpass filter (Hz) % highpass_coef : Upper cutoff frequency for bandpass filter (Hz) % OUTPUTS: % emg_env : Processed EMG envelope (RMS filtered signal) % emg_filt : Bandpass-filtered and rectified EMG signal % % Author: Junyo Boo (2025) % Data DOI: https://doi.org/10.6084/m9.figshare.27677016 % % The following script is provided under the Creative Commons Attribution 4.0 % International License (CC-BY 4.0). % % You are free to share and adapt this material for any purpose, even commercially, % provided you give appropriate credit, provide a link to the license, and indicate % if changes were made. The full license text can be found at: % % https://creativecommons.org/licenses/by/4.0/ % %--------------------------------------------------------------------------------------- [b, a] = butter(2,[lowpass_coef/(fs/2) highpass_coef/(fs/2)],'bandpass'); detrend_emg = detrend(emg_rawdata); %% zeroing filtered_emg = filtfilt(b,a,detrend_emg); %% bandpass filter rec_filtered_emg = abs(filtered_emg); %% absolute outlier_removed_emg = hampel(rec_filtered_emg, 250, 3); %% outlier detection movav_emg = sqrt(movmean(outlier_removed_emg.^2,250,1)); %% rms window visible = false; if visible figure; subplot(5,1,1); plot(emg_rawdata); subplot(5,1,2); plot(detrend_emg); subplot(5,1,3); plot(filtered_emg); subplot(5,1,4); plot(rec_filtered_emg); subplot(5,1,5); plot(movav_emg); end emg_filt = outlier_removed_emg; emg_env = movav_emg; end