资源简介
matlab源程序,能够迅速得到布拉格衍射峰的峰位、峰强以及半峰宽
代码片段和文件信息
function get_peak();
directory=‘E:\MATLAB701\work\yl\data\‘;
dirname=strcat(directory‘*.txt‘);%.txt‘);
namelist=dir(dirname);
a=length(namelist);
answer=zeros(8a-1);%记录结果
%answer(:1)=[‘名称‘‘峰高‘‘半高宽‘‘基线‘‘峰位‘‘半高位1‘‘半高位2‘‘半高位纵坐标‘];
for k=1:a;
if strcmp(namelist(k).name‘base.txt‘);
filename=strcat(directorynamelist(k).name);
fid=fopen(filename‘rt‘);
filecontent=textscan(fid‘%n%n‘);
m=length(filecontent{1});%行数
data_base=zeros(m2);
for n=1:2;
data_base(:n)=filecontent{n};
end;
fclose(fid);
end;
end;
kkk=0;
for k=1:a;
if strcmp(namelist(k).name‘base.txt‘);
else
kkk=kkk+1;
filename=strcat(directorynamelist(k).name);
fid=fopen(filename‘rt‘);
filecontent=textscan(fid‘%n%n‘);
m=length(filecontent{1});%行数
data=zeros(m2);
for n=1:2;
data(:n)=filecontent{n};
end;
data(:2)=data(:2)./data_base(:2);
data(:2)=smooth(data(:2)10);%平滑曲线!!!!!!!!!!!!
data_write=data‘;
directory_temp=‘E:\MATLAB701\work\yl\output\‘;
outputname=strcat(directory_tempnamelist(k).name);
fid2=fopen(outputname‘wt‘);
fprintf(fid2‘%6f\t%6f\n‘data_write);
fclose(fid2);
x2=data(11):0.2:data(m1);
y2=interp1(data(:1)data(:2)x2‘spline‘);
%baseline=(data(m-42)+data(m-32)+data(m-22)+data(m-12)+data(m2))/5;%基线
baseline=(data(12)+data(22)+data(32)+data(m-22)+data(m-12)+data(m2))/6;%基线
%baseline=0;
max_y2=y2(1);
max_x2=1;
for ii=2:length(x2);
if y2(ii)>max_y2;
max_y2=y2(ii);
max_x2=ii;
end;
end;
height_peak=max_y2-baseline;%峰高
peakline=baseline+0.9*height_peak;
num_temp=0;
peak_pos=0;%峰位的序号
for kk=1:length(x2);
if y2(kk)>peakline;
num_temp=num_temp+1;
peak_pos=peak_pos+kk;
end;
end;
peak_pos=fix(peak_pos/num_temp);
height_peak2=mean(y2(peak_pos-3:peak_pos+3))-baseline;%修正后的峰值
half_y=baseline+height_peak/2;
half_x1=x2(1);
half_x2=x2(length(x2));
for jj=2:max_x2;
if y2(jj-1)<=half_y&&y2(jj)>=half_y;
half_x1=x2(jj);
end;
end;
for jj=max_x2:length(x2);
if y2(jj-1)>=half_y&&y2(jj)<=half_y;
half_x2=x2(jj);
end;
end;
% half_x1=interp1(y2(1:max_x2)x2(1:max_x2)half_y);
% half_x2=interp1(y2(max_x2:length(x2))x2(max_x2:length(x2))half_y);
half_width_peak=half_x2-half_x1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data2=data;
data2(:2)=data2(:2)-baseline;
data2(:2)=data2(:2)/height_peak2;
data_write2=data2
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4623 2011-12-14 16:31 get_peak.m
- 上一篇:将二进小波变换用于图像增强的MATLAB代码
- 下一篇:能量检测matlab代码
评论
共有 条评论