Savitzky-Golay filtering on emg signal

58 次查看(过去 30 天)
Zainab
Zainab 2024-6-26,3:15
回答: Star Strider 2024-6-26,11:05
Hello everyone,
I am working on a project that uses SEMG signals to move a prosthetic arm. I am trying to figure out how to use the Savitzky Golay filter to smooth the "sound" on the graph. I am trying to only have the full "contractions" and the smooth the "rest" parts of the graph

回答(3 个)

Diego Caro
Diego Caro 2024-6-26,5:55
What works best for me is just filtering the EMG signal with a lowpass butterworth filter with a very low cutoff frequency.
For example:
% Take a look at the raw signal
t = time_range;
emg = raw_emg;
figure
plot(t,emg)
Now lets add the lowpass filter and compare its output.
fc = 3; % Cutoff frequency in Hz.
n = 4; % Filter order.
fs = 100; % Sample rate.
[b,a] = butter(n,fc/(fs/2),"low");
emg_filt = filter(b,a,emg);
figure
hold on
plot(t,emg)
plot(t,emg_filt,'LineWidth',1.5,'Color','r')
legend('Raw EMG','Filtered EMG')
Here I used a cutoff frequency of 3 Hz, which is very low, but you can go as low as you want if you desire a more agressive smoothing. There are several other methods you can use to smooth an EMG signal, but as I said, this is my personal preference.
Regards,
Diego.

Umar
Umar 2024-6-26,7:08
Hi Zainab,
To achieve this in Matlab, you can utilize the sgolayfilt function. This function applies the Savitzky-Golay filter to your signal. You can specify the frame length and polynomial order to control the smoothing effect. Here's a simple example of how to use the Savitzky-Golay filter in Matlab:
% Sample SEMG signal data signal = your_signal_data;
% Define parameters for the filter frame_length = 15; % Adjust based on your signal characteristics poly_order = 3; % Adjust for desired smoothing
% Apply Savitzky-Golay filter smoothed_signal = sgolayfilt(signal, poly_order, frame_length);
% Plot the original and smoothed signals figure; plot(signal, 'b', 'LineWidth', 1.5); hold on; plot(smoothed_signal, 'r', 'LineWidth', 1.5); legend('Original Signal', 'Smoothed Signal'); xlabel('Time'); ylabel('Amplitude'); title('SEM Signal Smoothing using Savitzky-Golay Filter');
By adjusting the frame_length and poly_order parameters, you can tailor the smoothing effect to enhance the "contractions" while effectively smoothing the "rest" parts of your SEMG signal graph.

Star Strider
Star Strider 2024-6-26,11:05
Calcualte the Fourier transform of the data (fft) to determine tthe frequency content of the signal, and then use a frequency-selective filter (either lowpass or bandpass) to remove the high-frequency noise and, if necessary, baseline offset and baseline drift. The Savitzky-Golay filter is essentially a multiband FIR filter that while appropriate in some applications, is simply too slow for any sort of real-time application. Experiment with the discrete (digital) filters with your recorded signals, and then implement them in hardware for your intended real-time continuous application.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by