Matlab-基础

自己写的实验相关的函数

  1. findedge

改进前

% this function shows finds the edge of the integration intensity of the spectra, the number of 
% the band should be equal to 18. otherwise change the value 18.
% the value of 10000 can be changed according to the specific situation
% the real position should be around +1/-1,+2/-2,or 0/0 of the f.
% trying several times to check which is the best one.

function [f] = findedge(a)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
b=diff(a); 
c=findpeaks(b);  %b is the values of local maximam%
index=c>1000000;   % find the position where the local maximam is much larger than the neighboring values.
d=c(index);   % find the elements in b bigger than 10000, to determine the edge%
for i=1:18
    e(i)=find(b==d(i)) % find the position of a vector where its element value equals c(i)
end
f=sort(e);
end

 

改进后-1

function [f] = findedge(a,n,m)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
b=diff(a); 
c=findpeaks(b);  %b is the values of local maximam%
index=c>m;   % find the position where the local maximam is much larger than the neighboring values.
d=c(index);   % find the elements in b bigger than 10000, to determine the edge%
for i=1:n
    e(i)=find(b==d(i)) % find the position of a vector where its element value equals c(i)
end
f=sort(e);
end

 

改进后-2

function [f,g] = findedge(a,n,m)
%UNTITLED4 Summary of this function goes here
%   Detailed explanation goes here
b=diff(a); 
c=findpeaks(b);  %b is the values of local maximam%
index=c>m;   % find the position where the local maximam is much larger than the neighboring values.
d=c(index);   % find the elements in b bigger than 10000, to determine the edge%
for i=1:n
    e(i)=find(b==d(i)) % find the position of a vector where its element value equals c(i)
end
f=sort(e);

b=diff(-a); 
c=findpeaks(b);  %b is the values of local maximam%
index=c>m;   % find the position where the local maximam is much larger than the neighboring values.
d=c(index);   % find the elements in b bigger than 10000, to determine the edge%
for i=1:n
    e(i)=find(b==d(i)) % find the position of a vector where its element value equals c(i)
end
g=sort(e);
end

 

2. 实验代码:

load princeton
load calibration

wavelength=princeton(1,3:end);
intensity=princeton(2:end,3:end);  %提取出纯光谱信息
time=princeton(2:end,1);

background=sum(intensity(1:100,:),1)./100; %提取出平均背底光谱

intensity=intensity-background;   %扣背底
intensity=intensity.*calibration(:,2)';   %校准光谱

intensity2=intensity(:,857:1182); %570 nm to 680 nm 积分强度

%%

 

Leave a Reply