Batch FFT operation on EMG data

5 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2022-11-15
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by