1 | function [BPM_list bufferX bufferZ pxfftaff_all pzfftaff_all Xintegrale_all Zintegrale_all f_bpm]=Compute_FFT_on_FA_data(buffer_length,fmin,fmax,save2xls) |
---|
2 | |
---|
3 | clk=clock; |
---|
4 | year=num2str(clk(1)); |
---|
5 | month=num2str(clk(2),'%.2d'); |
---|
6 | day=num2str(clk(3),'%.2d'); |
---|
7 | hour=[num2str(clk(4),'%.2d'),'h']; |
---|
8 | min=[num2str(clk(5),'%.2d'),'mn']; |
---|
9 | date=['_',year,'_',month,'_',day,'_',hour,'_',min]; |
---|
10 | filename=['/home/operateur/GrpDiagnostics/matlab/data/Enregistrement',date,'.mat']; |
---|
11 | |
---|
12 | |
---|
13 | dev='ANS/DG/fofb-sniffer.2'; |
---|
14 | fech=10079; |
---|
15 | fmin_display=fmin; |
---|
16 | fmax_display=fmax; |
---|
17 | fmax_record=2000; |
---|
18 | |
---|
19 | [selection ok]=listdlg('liststring',family2tangodev('BPMx'),'Name','Select BPM(s)') |
---|
20 | if ok |
---|
21 | Nbpm=size(selection,2); |
---|
22 | h1=waitbar(0,'please wait...'); |
---|
23 | tango_write_attribute2(dev,'recordLengthInSecs',buffer_length) |
---|
24 | pause(1) |
---|
25 | record_length=tango_read_attribute2(dev,'recordLengthInSecs'); |
---|
26 | for i=1:buffer_length+2 |
---|
27 | pause(1) |
---|
28 | waitbar(i/buffer_length,h1); |
---|
29 | end |
---|
30 | close(h1) |
---|
31 | %tango_command_inout2(dev,'StartRecording'); |
---|
32 | %pause(record_length.value(1)+3); |
---|
33 | h2=waitbar(0,'please wait...'); |
---|
34 | |
---|
35 | for j=1:1:Nbpm |
---|
36 | bufferX(j,:)=(tango_command_inout2(dev,'GetXPosData',uint16(selection(j)))); |
---|
37 | bufferZ(j,:)=(tango_command_inout2(dev,'GetZPosData',uint16(selection(j)))); |
---|
38 | waitbar(j/Nbpm,h2) |
---|
39 | end |
---|
40 | Nsamples=size(bufferX(j,:),2); |
---|
41 | [pxfftaff,pzfftaff,Xintegrale_bpm,Zintegrale_bpm,f_bpm]=fft_and_noise_calcul_group(bufferX(:,1:Nsamples),bufferZ(:,1:Nsamples),fech); |
---|
42 | pxfftaff_all=pxfftaff; |
---|
43 | pzfftaff_all=pzfftaff; |
---|
44 | Xintegrale_all(:,1:Nsamples)=Xintegrale_bpm; |
---|
45 | Zintegrale_all(:,1:Nsamples)=Zintegrale_bpm; |
---|
46 | |
---|
47 | |
---|
48 | end |
---|
49 | close(h2) |
---|
50 | % answer=questdlg(['Display FFT and noise for ',num2str(Nbpm),' BPMs?']); |
---|
51 | % switch answer |
---|
52 | % case 'Yes' |
---|
53 | % for j=1:1:Nbpm |
---|
54 | % figure |
---|
55 | % |
---|
56 | % subplot(2,2,1) |
---|
57 | % semilogy(f_bpm,pxfftaff_all(j,2:Nsamples)); |
---|
58 | % xlim([fmin_display fmax_display]); |
---|
59 | % ylim([10^-3 10^2]); |
---|
60 | % xlabel('frequency (Hz)') |
---|
61 | % ylabel('µm/sqrt(Hz)') |
---|
62 | % title(family2tangodev('BPMx',selection(j))); |
---|
63 | % legend('fft plan H'); |
---|
64 | % grid on; |
---|
65 | % |
---|
66 | % subplot(2,2,2) |
---|
67 | % semilogy(f_bpm,pzfftaff_all(j,2:Nsamples)); |
---|
68 | % xlim([fmin_display fmax_display]); |
---|
69 | % ylim([10^-3 10^1]); |
---|
70 | % xlabel('frequency (Hz)') |
---|
71 | % ylabel('µm/sqrt(Hz)') |
---|
72 | % title(family2tangodev('BPMx',selection(j))); |
---|
73 | % legend('fft plan V'); |
---|
74 | % grid on; |
---|
75 | % |
---|
76 | % subplot(2,2,3) |
---|
77 | % plot(f_bpm,Xintegrale_all(j,2:Nsamples)); |
---|
78 | % xlim([fmin_display fmax_display]); |
---|
79 | % xlabel('frequence (Hz)'); |
---|
80 | % ylabel('µm'); |
---|
81 | % legend('bruit integré plan H'); |
---|
82 | % grid on; |
---|
83 | % |
---|
84 | % subplot(2,2,4) |
---|
85 | % plot(f_bpm,Zintegrale_all(j,2:Nsamples)) |
---|
86 | % xlim([fmin_display fmax_display]); |
---|
87 | % xlabel('frequence (Hz)'); |
---|
88 | % ylabel('µm'); |
---|
89 | % legend('bruit integré plan V'); |
---|
90 | % grid on; |
---|
91 | % |
---|
92 | % end |
---|
93 | % otherwise |
---|
94 | % end |
---|
95 | |
---|
96 | BPM_list=family2tangodev('BPMx',selection(:)); |
---|
97 | %uisave({'BPM_list','bufferX','bufferZ','pxfftaff_all','pzfftaff_all','Xintegrale_all','Zintegrale_all','f_bpm'},filename) |
---|
98 | uisave({'BPM_list','bufferX','bufferZ'},filename) |
---|
99 | if save2xls |
---|
100 | filename_xls={['Enregistrement',date]}; |
---|
101 | answer = inputdlg('Filename:','Save results in an exel file?',1,filename_xls,'on'); |
---|
102 | if isempty(answer) |
---|
103 | else |
---|
104 | index=max(find(f_bpm<fmax_record)); |
---|
105 | |
---|
106 | for i=1:1:Nbpm |
---|
107 | bpm_name=BPM_list{i}; |
---|
108 | bpm_name(8)='_'; |
---|
109 | bpm_name(11)='_'; |
---|
110 | bpm_name(15)='_' |
---|
111 | |
---|
112 | filename=[answer{1},'_',bpm_name,'.xls']; |
---|
113 | fid=fopen(filename,'w'); |
---|
114 | first_line='frequence:Spectre_X:Spectre_Z\n'; |
---|
115 | fprintf(fid,first_line); |
---|
116 | for j=1:1:index-1 |
---|
117 | fprintf(fid,'%d:%d:%d\n',f_bpm(j),pxfftaff_all(i,j+1),pzfftaff_all(i,j+1)); |
---|
118 | end |
---|
119 | fclose(fid) |
---|
120 | fprintf('Le fichier %s est bien enregistré\n',filename); |
---|
121 | end |
---|
122 | end |
---|
123 | end |
---|
124 | end |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|