方法1 findpeaks
t=A;
x=B;
y=detrend(x);
plot(t,y);
grid; hold
on
[K,V]=findpeaks(x);
thr=1000;
vdex=find(V>thr);
V1=V(vdex);
K1=K(vdex);
delta=10;if (a(i)<0.5)
a(i)=0;
new(vdex) = 0.5*( y(vdex-delta)+ y(vdex+delta) ) ;
plot(t(K1),V1,'r.','linewidth',5);
title(['信号提取极值,阈值thr=' num2str(thr)]);
方法2 diff
for i=1:3000if (a(i)<0.5)a(i)=0;endend
b=find(diff(sign(diff(a)))<0)+1;% 求解极值点序号plot(t, a,t(b), a(b),'r*') % 画出去噪声后的波形,由于滤波的关系,前一秒钟的信号异常,因此只画1s以后的数据xlabel('t(s)')ylabel('Voltage(v)')axis([1 6 0 2]);title('Final Signal')grid on
方法3 localMaximum
a=mydata(:,2);a=detrend(a);
peaks = localMaximum(a,37000);