Batch FFT operation on EMG data

5 Ansichten (letzte 30 Tage)
Ines Shekhovtsov
Ines Shekhovtsov am 15 Nov. 2022
Kommentiert: Star Strider am 22 Nov. 2022
I have a basic code to read a .dat file containing EMG data for several muscles. The code scans the file for a specific time and extracts 3 seconds worth of data into a new table. I would like to calculate and plot the FFT spectrum for each EMG channel. The code i have works and gets the job done but i would like to optimize the code and not make it so rudamentary looking. I am very new to matlab coding and wrote the code with a lot of help from google. I have attached the code for reference. A couple of things i would like to streamline with new code:
*Perform the FFT analysis in a for loop or function
*Plot the FFT for each muscle in a for loop or function
*Will also welcome any other code tips for reading the .dat file and getting the table (T) in a more efficient way
Basically, as you will see from my code, it is very repetative and i assume i can get the same output by using a couple of for loops or functions instead of just writing this code in a brute force type method.
Thank you for your help in advance.

Akzeptierte Antwort

Star Strider
Star Strider am 15 Nov. 2022
I am not certain what you want to do.
After you load the data and select the sections you want to analyse, convert the data in ‘Wanted’ to column vectors (if they are not column vectors already), then do something like this (assuming that they are now a matrix of column vectors):
Fs = ...; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = size(Wanted,1);
NFFT = 2^nextpow2(L); % For Efficiency
FTW = fft(Wanted, NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(FV, abs(FTW(Iv,:))*2) % All Channels
grid
xlabel('Frequency (Hz)')
ylabel('Magnitude')
NrSp = size(FTTW,2); % Number Of Subplots
for k = 1:NrSp
subplot(NrSp, 1, k)
plot(Fv, abs(FTW(Iv,k)*2)
xlabel(Frequency (Hz)')
ylabel('Magnitude')
title(sprintf('Column #%2d', k)
end
That may be a bit more efficient. I leave that to you to determine.
% C = websave('testCODE','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1194378/testCODE.m');
% type(C)
.
  11 Kommentare
Ines Shekhovtsov
Ines Shekhovtsov am 22 Nov. 2022
Thank you for all of your help!
Star Strider
Star Strider am 22 Nov. 2022
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by