%本程序作用说明:用来实现5元、10元、20元、50元、100元峰值和峰谷数据范围的获取
%关闭所有的窗口,清除所有的内存数据,清除命令窗口中的数据
clf;
close all;
clear all;
clc;
%读取数据
%读取18个5元的样本数据
x51=xlsread('5反上下1.xls','A700:A1904');
x52=xlsread('5反上下2.xls','A700:A1904');
x53=xlsread('5反上下3.xls','A700:A1904');
x54=xlsread('5正上下1.xls','A700:A1904');
x55=xlsread('5正上下2.xls','A700:A1904');
x56=xlsread('5反下上1.xls','A700:A1904');
x57=xlsread('5反下上2.xls','A700:A1904');
x58=xlsread('5反下上3.xls','A700:A1904');
x59=xlsread('5反下上4.xls','A700:A1904');
x510=xlsread('5反下上5.xls','A700:A1904');
x511=xlsread('5正上下3.xls','A700:A1904');
x512=xlsread('5正上下4.xls','A700:A1904');
x513=xlsread('5正上下5.xls','A700:A1904');
x514=xlsread('5正下上1.xls','A700:A1904');
x515=xlsread('5正下上2.xls','A700:A1904');
x516=xlsread('5正下上3.xls','A700:A1904');
x517=xlsread('5正下上4.xls','A700:A1904');
x518=xlsread('5正下上5.xls','A700:A1904');
%将18组列向量进行数据预处理
%滑动滤波
m=11;%表示平滑滤波窗函数,前m/2,后m/2个点没有滤波,设为原来的值就行
for i=1:length(x51)-m+1
y51(i+(m-1)/2)=sum(x51(i:i+m-1))/m;
end
for i=1:length(x52)-m+1
y52(i+(m-1)/2)=sum(x52(i:i+m-1))/m;
end
for i=1:length(x53)-m+1
y53(i+(m-1)/2)=sum(x53(i:i+m-1))/m;
end
for i=1:length(x54)-m+1
y54(i+(m-1)/2)=sum(x54(i:i+m-1))/m;
end
for i=1:length(x55)-m+1
y55(i+(m-1)/2)=sum(x55(i:i+m-1))/m;
end
for i=1:length(x56)-m+1
y56(i+(m-1)/2)=sum(x56(i:i+m-1))/m;
end
for i=1:length(x57)-m+1
y57(i+(m-1)/2)=sum(x57(i:i+m-1))/m;
end
for i=1:length(x58)-m+1
y58(i+(m-1)/2)=sum(x58(i:i+m-1))/m;
end
for i=1:length(x59)-m+1
y59(i+(m-1)/2)=sum(x59(i:i+m-1))/m;
end
for i=1:length(x510)-m+1
y510(i+(m-1)/2)=sum(x510(i:i+m-1))/m;
end
for i=1:length(x511)-m+1
y511(i+(m-1)/2)=sum(x511(i:i+m-1))/m;
end
for i=1:length(x512)-m+1
y512(i+(m-1)/2)=sum(x512(i:i+m-1))/m;
end
for i=1:length(x513)-m+1
y513(i+(m-1)/2)=sum(x513(i:i+m-1))/m;
end
for i=1:length(x514)-m+1
y514(i+(m-1)/2)=sum(x514(i:i+m-1))/m;
end
for i=1:length(x515)-m+1
y515(i+(m-1)/2)=sum(x515(i:i+m-1))/m;
end
for i=1:length(x516)-m+1
y516(i+(m-1)/2)=sum(x516(i:i+m-1))/m;
end
for i=1:length(x517)-m+1
y517(i+(m-1)/2)=sum(x517(i:i+m-1))/m;
end
for i=1:length(x518)-m+1
y518(i+(m-1)/2)=sum(x518(i:i+m-1))/m;
end
%数据压缩
t=0;
for i=1:8:length(y51)
t=t+1;
z51(t)=(y51(i)+y51(i+1)+y51(i+2)+y51(i+3)+y51(i+4)+y51(i+5)+y51(i+6)+y51(i+7))/8;
end
t=0;
for i=1:8:length(y52)
t=t+1;
z52(t)=(y52(i)+y52(i+1)+y52(i+2)+y52(i+3)+y52(i+4)+y52(i+5)+y52(i+6)+y52(i+7))/8;
end
t=0;
for i=1:8:length(y53)
t=t+1;
z53(t)=(y53(i)+y53(i+1)+y53(i+2)+y53(i+3)+y53(i+4)+y53(i+5)+y53(i+6)+y53(i+7))/8;
end
t=0;
for i=1:8:length(y54)
t=t+1;
z54(t)=(y54(i)+y54(i+1)+y54(i+2)+y54(i+3)+y54(i+4)+y54(i+5)+y54(i+6)+y54(i+7))/8;
end
t=0;
for i=1:8:length(y55)
t=t+1;
z55(t)=(y55(i)+y55(i+1)+y55(i+2)+y55(i+3)+y55(i+4)+y55(i+5)+y55(i+6)+y55(i+7))/8;
end
t=0;
for i=1:8:length(y56)
t=t+1;
z56(t)=(y56(i)+y56(i+1)+y56(i+2)+y56(i+3)+y56(i+4)+y56(i+5)+y56(i+6)+y56(i+7))/8;
end
t=0;
for i=1:8:length(y57)
t=t+1;
z57(t)=(y57(i)+y57(i+1)+y57(i+2)+y57(i+3)+y57(i+4)+y57(i+5)+y57(i+6)+y57(i+7))/8;
end
t=0;
for i=1:8:length(y58)
t=t+1;
z58(t)=(y58(i)+y58(i+1)+y58(i+2)+y58(i+3)+y58(i+4)+y58(i+5)+y58(i+6)+y58(i+7))/8;
end
t=0;
for i=1:8:length(y59)
t=t+1;
z59(t)=(y59(i)+y59(i+1)+y59(i+2)+y59(i+3)+y59(i+4)+y59(i+5)+y59(i+6)+y59(i+7))/8;
end
t=0;
for i=1:8:length(y510)
t=t+1;
z510(t)=(y510(i)+y510(i+1)+y510(i+2)+y510(i+3)+y510(i+4)+y510(i+5)+y510(i+6)+y510(i+7))/8;
end
t=0;
for i=1:8:length(y511)
t=t+1;
z511(t)=(y511(i)+y511(i+1)+y511(i+2)+y511(i+3)+y511(i+4)+y511(i+5)+y511(i+6)+y511(i+7))/8;
end
t=0;
for i=1:8:length(y512)
t=t+1;
z512(t)=(y512(i)+y512(i+1)+y512(i+2)+y512(i+3)+y512(i+4)+y512(i+5)+y512(i+6)+y512(i+7))/8;
end
t=0;
for i=1:8:length(y513)
t=t+1;
z513(t)=(y513(i)+y513(i+1)+y513(i+2)+y513(i+3)+y513(i+4)+y513(i+5)+y513(i+6)+y513(i+7))/8;
end
t=0;
for i=1:8:length(y514)
t=t+1;
z514(t)=(y514(i)+y514(i+1)+y514(i+2)+y514(i+3)+y514(i+4)+y514(i+5)+y514(i+6)+y514(i+7))/8;
end
t=0;
for i=1:8:length(y515)
t=t+1;
z515(t)=(y515(i)+y515(i+1)+y515(i+2)+y515(i+3)+y515(i+4)+y515(i+5)+y515(i+6)+y515(i+7))/8;
end
t=0;
for i=1:8:length(y516)
t=t+1;
z516(t)=(y516(i)+y516(i+1)+y516(i+2)+y516(i+3)+y516(i+4)+y516(i+5)+y516(i+6)+y516(i+7))/8;
end
t=0;
for i=1:8:length(y517)
t=t+1;
z517(t)=(y517(i)+y517(i+1)+y517(i+2)+y517(i+3)+y517(i+4)+y517(i+5)+y517(i+6)+y517(i+7))/8;
end
t=0;
for i=1:8:length(y518)
t=t+1;
z518(t)=(y518(i)+y518(i+1)+y518(i+2)+y518(i+3)+y518(i+4)+y518(i+5)+y518(i+6)+y518(i+7))/8;
end
%重组矩阵
A5=[z51;z52;z53;z54;z55;z56;z57;z58;z59;z510;z511;z512;z513;z514;z515;z516;z517;z518];
%计算峰值和峰谷个数
%计算峰值个数
i=0;%18行依次循环
j=0;%150列依次循环
cnt5=zeros(1,18);%构建1行18列的矩阵,用来存储峰值个数的2倍值,将来计算峰值实际个数时,记得除以2
for i=1:18
for j= 1:150
if A5(i,j)>=0.4 && A5(i,j)<=0.5 && j<=150
cnt5(1,i)=cnt5(1,i)+1;
end
end
end