clc;
close all;
clear;
workspace;
format longg;
format compact;
fontSize = 20;
signal = 0.003 * rand(1, 550) - 0.0015
signal(50:100) = 0.03 * rand(1, 51) - 0.015
signal(150:200) = 0.03 * rand(1, 51) - 0.015
signal(250:300) = 0.03 * rand(1, 51) - 0.015
signal(350:400) = 0.03 * rand(1, 51) - 0.015
signal(450:500) = 0.03 * rand(1, 51) - 0.015
subplot(3, 1, 1);
plot(signal);
title('Original Signal', 'FontSize', fontSize);
grid on;
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
filteredSignal = medfilt1(abs(signal), 13);
subplot(3, 1, 2);
plot(filteredSignal);
title('Filtered Signal', 'FontSize', fontSize);
quietParts = filteredSignal < 0.002;
subplot(3, 1, 3);
plot(quietParts, 'LineWidth', 3);
ylim([0 1.2]);
title('Quiet Parts', 'FontSize', fontSize);
startingBlockIndexes = find(diff(quietParts) < 0)
endingBlockIndexes = find(diff(quietParts) > 0)
v1 = signal(startingBlockIndexes(1):endingBlockIndexes(1));
v2 = signal(startingBlockIndexes(2):endingBlockIndexes(2));
v3 = signal(startingBlockIndexes(3):endingBlockIndexes(3));
v4 = signal(startingBlockIndexes(4):endingBlockIndexes(4));
v5 = signal(startingBlockIndexes(5):endingBlockIndexes(5));
figure;
subplot(5, 1, 1);
plot(v1);
grid on;
title('V1', 'FontSize', fontSize);
subplot(5, 1, 2);
plot(v2);
grid on;
title('V2', 'FontSize', fontSize);
subplot(5, 1, 3);
plot(v3);
grid on;
title('V3', 'FontSize', fontSize);
subplot(5, 1, 4);
plot(v4);
grid on;
title('V4', 'FontSize', fontSize);
subplot(5, 1, 5);
plot(v5);
grid on;
title('V5', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
Best Answer