clear
clc
close all
fs=200;
t=(1/200:1/200:30)';
signal=sin(2*pi*0.1*t);
LL=1:1:length(t);
figure(1)
plot(LL,signal)
zero_indices = []; % 存储最靠近0的点的索引
start_indices = []; % 存储开始点的索引
end_indices = []; % 存储结束点的索引
for i = 2:length(signal)-1 % 从第2个点开始,到倒数第2个点结束
% 检查当前点及其相邻点,确保中间点是极小值
if abs(signal(i)) < abs(signal(i-1)) && abs(signal(i)) < abs(signal(i+1))
zero_indices = [zero_indices; i];
% 检查零点右侧的点是正还是负,以确定是开始点还是结束点
if signal(i+1) > 0
start_indices = [start_indices; i];
elseif signal(i+1) < 0
end_indices = [end_indices; i];
end
end
end
% 绘制图像
figure(1)
plot(LL, signal)
hold on
plot(zero_indices, signal(zero_indices), 'ro', 'MarkerSize', 10)
plot(start_indices, signal(start_indices), 'go', 'MarkerSize', 10)
plot(end_indices, signal(end_indices), 'bo', 'MarkerSize', 10)
legend('Signal', 'Zero Points', 'Start Points', 'End Points')
hold off