Hello.
I'm trying to do a performance analysis of hand muscles for my capstone project, and I'm using EMG sensor to help me. The process is to obtain the time domain values and convert them into frequency domain which I need for the next step of the performance analysis.
I'm using MyoWare EMG sensor which gives a signal that is already filterd, rectified and amplified.
The sensor has three chennels and I obtained the signals through each one of them. And then, I plotted the time domain of them. And as you can see, the signals are not periodic.
Then I applyed FFT function on them and plotted the frequency domain as well.
And this is my full code:
clear; clc; clf;
t = 0:1/100:10-1/100; % Time vector
a = arduino();
% Preallocate the y array to store data from all channels
num_channels = 3; % Number of channels (A0, A1, A2)
x = zeros(num_channels, length(t));
y = zeros(num_channels, length(t));
for i = 1:length(t)
% Read voltage from each channel
for channel = 0:num_channels-1
x(channel+1, i) = readVoltage(a, ['A' num2str(channel)]);
end
end
% Compute DFT of x
for channel = 1:num_channels
y(channel, :) = fft(x(channel, :));
end
% Magnitude of FFT
m = abs(y);
% Plot time-domain
for channel = 1:num_channels
figure(1);
subplot(num_channels,1,channel);
plot(t, x(channel, :));
xlabel('Time (s)');
ylabel('Voltage');
title(['Time Domain Signal - Channel ' num2str(channel)]);
ax = gca;
ax.XTick = [15 40 60 85];
end
% Phase calculation and plot in the frequency domain
p = unwrap(angle(y)); % Phase
f = (0:length(y)-1)*100/length(y); % Frequency vector
for channel = 1:num_channels
figure(2);
subplot(num_channels,1,channel);
plot(f, p(channel, :)*180/pi);
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
title(['Frequency Domain Phase - Channel ' num2str(channel)]);
ax = gca;
ax.XTick = [15 40 60 85];
end
My questions are:
- Are my frequency domain graphs correct (Taking into consideration that my original signals are not perodic)? So am I ready to go to the next step?
- Is there any advices or adjustment that you think will help me improve my code overall?