I created two signals to experiment with this. The code is straightforward:
t = linspace(0, 100, 1000);
EMG = sin(2*pi*t/20) .* cos(2*pi*t/50) + 1;
AB = sin(2*pi*t/25 + 0.2) .* cos(2*pi*t/40) + 1;
EMGT = 1*(EMG > 0.25) + 0*(EMG <= 0.25);
ABT = 1*(AB > 0.25) + 0*(AB <= 0.25);
Active = EMGT .* ABT;
ActivePct = 100 * sum(Active)/numel(Active);
figure(1)
subplot(3,1,1)
plot(t, EMG, '-b')
hold on
plot(t, AB, '-r')
hold off
legend('EMG', 'Model')
grid
subplot(3,1,2)
plot(t, EMGT, '-c')
hold on
plot(t, ABT, '-m')
hold off
axis([xlim -0.1 1.1])
legend('EMG', 'Model')
grid
subplot(3,1,3)
plot(t, Active, '-g', 'LineWidth',2)
axis([xlim -0.1 1.5])
text(mean(t), 1.25, sprintf('Percent Both Active = %.2f', ActivePct), 'HorizontalAlignment','center', 'VerticalAlignment','middle')
grid
Experiment to get the result you want.
Best Answer