Plot mean frequency of EMG signals

63 vues (au cours des 30 derniers jours)
Prawee Pongsing
Prawee Pongsing le 3 Jan 2023
Commenté : William Rose le 4 Jan 2023
Hello everyone, I'm a newbie in matlab coding. Now I have an EMG signals and I want to plot it to see the change in mean frequency like the one in this paper which I have tried to write as below:
% Load the data from the CSV file
data = readmatrix('data_emg_test.csv');
% Extract the time and EMG data columns
time = data(:,1);
emg = data(:,2);
% Compute the Fourier transform of the EMG signal
fourier_transform = fft(emg);
% Compute the power spectrum of the EMG signal
power_spectrum = abs(fourier_transform).^2;
% Compute the frequency axis of the power spectrum
Fs = 1000; % Sampling frequency
N = length(emg); % Number of time points in the signal
duration = time(end) - time(1); % Duration of the signal
frequency_axis = (0:N-1)/N*Fs/duration;
% Compute the mean frequency of the EMG signal
mean_frequency = meanfreq(power_spectrum,frequency_axis);
% Plot the mean frequency over time
plot(time, mean_frequency)
% Add labels to the x- and y-axis
xlabel('Time (s)')
ylabel('Mean Frequency (Hz)')
% Add a title to the plot
title('Mean Frequency of EMG Signal')
% Display grid lines on the plot
grid on
% Set the limits of the x- and y-axis
xlim([0 time(end)])
ylim([0 max(mean_frequency)])
But I'm very inexperienced in using matlab so the results are not as good as I hoped. And I don't know how to fix it or what examples to refer to from each thread, please help me.

Réponse acceptée

William Rose
William Rose le 3 Jan 2023
Alty & Georgakis (2011), whom you cite, use their eqn.7 to compute the mean frequency.
You do not have to compute the FFT or power spectrum, since meanfreq() does that for you. You do need to extract segments of the signal. In the attached code, I use a segment duration of 0.25 s, to match the duration used by Alty & Georgakis (2011). I choose to overlap the segments by half a segment. This is a common choice. I calculate the total number of segments (Nseg) that will fit into the full recording. I also compute the midpoint time of each segment.
After doing the preparatory steps above, I do the main loop. The loop extracts each segment from the full-length record, and computes the mean frequency for that segment.
The last step is to plot the results, as shown below, using the attached script and your data.
  2 commentaires
Prawee Pongsing
Prawee Pongsing le 4 Jan 2023
Oh, it's like this. I'm beginning understand it better now. Thank you so much for the explanation and the code you attached. I'll study it further from what you suggest.
P.S. since I'm a foreigner who's really weak in language, I may not be able to communicate well. But actually telling you that "thank you very much".
William Rose
William Rose le 4 Jan 2023
Your written communication in English is perfect! You are certainly not weak in language!
You're welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by