1 | function [sx,sBx,sBz] = SmoothRadiaMap(PathName,FileName,x,Bx,Bz,Px,Pz,Lu,forder,funit) |
---|
2 | |
---|
3 | % smooth the Radia Map of interstion device, to make the data more smooth, |
---|
4 | % then can |
---|
5 | |
---|
6 | %% smooth the data and do spline interpolation |
---|
7 | |
---|
8 | f = 5; |
---|
9 | xn = (x(end)-x(1))/double((Px-1))/f; |
---|
10 | sx = x(1):xn:x(end); |
---|
11 | % smooth the Bx & By |
---|
12 | for i = 1:Pz |
---|
13 | sBx(i,:) = pchip(x,Bx(i,2:end),sx); |
---|
14 | sBz(i,:) = pchip(x,Bz(i,2:end),sx); |
---|
15 | end |
---|
16 | |
---|
17 | % the new horizontal and vertical points |
---|
18 | [sPz sPx] = size(sBx); |
---|
19 | |
---|
20 | %find the extension of the file |
---|
21 | exid = strfind(FileName,'.'); |
---|
22 | extension = FileName(exid:end); |
---|
23 | %find the main file name |
---|
24 | savefilename = [PathName,FileName(1:exid-1)]; |
---|
25 | |
---|
26 | %% save the data after interpolation |
---|
27 | fid =fopen([savefilename,'_interpolation',extension],'wt'); |
---|
28 | %save the headlines |
---|
29 | fprintf(fid,'%s\n','# Author: User'); |
---|
30 | fprintf(fid,'%s\n',['# ',FileName,' (after smooth)']); |
---|
31 | fprintf(fid,'%s\n','# Undulator Length [m]'); |
---|
32 | fprintf(fid,'%-10.4f\n',Lu); |
---|
33 | fprintf(fid,'%s\n','# Number of Horizontal Points'); |
---|
34 | fprintf(fid,'%d\n',sPx); |
---|
35 | fprintf(fid,'%s\n','# Number of Vertical Points'); |
---|
36 | fprintf(fid,'%d\n',sPz); |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | %save the interploted horizontal kick |
---|
41 | fprintf(fid,'%s\n',['# Horizontal ',forder,' Order Kick ',funit]); |
---|
42 | fprintf(fid,'%s\n ','START'); |
---|
43 | fprintf(fid,'% 10.5e ',sx); %the first element is non exit |
---|
44 | fprintf(fid,'\n'); |
---|
45 | for i=1:Pz |
---|
46 | fprintf(fid,'% 10.5e ',[Bz(i,1),sBz(i,:)]); |
---|
47 | fprintf(fid,'\n'); |
---|
48 | end |
---|
49 | |
---|
50 | %save the interploted vertical kick |
---|
51 | fprintf(fid,'%s\n',['# Vertical ',forder,' Order Kick ',funit]); |
---|
52 | fprintf(fid,'%s\n ','START'); |
---|
53 | fprintf(fid,'% 10.5e ',sx); %the first element is non exit |
---|
54 | fprintf(fid,'\n'); |
---|
55 | for i=1:Pz |
---|
56 | fprintf(fid,'% 10.5e ',[Bx(i,1),sBx(i,:)]); |
---|
57 | fprintf(fid,'\n'); |
---|
58 | end |
---|
59 | |
---|
60 | fclose(fid); |
---|
61 | |
---|
62 | |
---|
63 | % %% plot the data before and after interpolation |
---|
64 | % figure(1); |
---|
65 | % plot(x,Bz(:,2:end),'b-'); |
---|
66 | % hold on; |
---|
67 | % plot(sx,sBz,'r-'); |
---|
68 | % xlabel('x[m]'); |
---|
69 | % ylabel([forder, ' horizontal kick ',funit]); |
---|
70 | % legend('before smooth','after smooth'); |
---|
71 | % title(['spline interpolation, data is amplified by ', num2str(f)]); |
---|
72 | % |
---|
73 | % figure(2); |
---|
74 | % plot(x,Bx(:,2:end),'b-'); |
---|
75 | % hold on; |
---|
76 | % plot(sx,sBx,'r-'); |
---|
77 | % xlabel('x[m]'); |
---|
78 | % ylabel([forder, ' vertical kick ',funit]); |
---|
79 | % legend('before smooth','after smooth'); |
---|
80 | % title(['spline interpolation, data is amplified by ', num2str(f)]); |
---|