Commit 1b191c44 by Simone Liuzzo

### site specific functions

parent d8030d0a
findtunetom2.m 0 → 100644
 function [tunef,numdc,peakss,phasef,camp,uvect]=findtunetom2(M,divider,window) %[tunef,numdc]=findtunetom2(M,divider) %finds thew tune for real or complex sets of orbits. ALl orbits should have %the same length. one orbit is one collumn, and there ashould be as many %collums %as there are different orbits to treat. % the size of M should be orbit_lengthxnumber_of _orbits. % WINDOW should be equal to 1 if a hanex window should be aplied. %******************************************************************* %THE VALUE OF THE TUNE IS GIVEN CONSIDERED THAT THE ORBITS ARE RED ON A %SINGLE BPM (SAMPELING AT REVOLUTION FREQUENCY). IF THE ORBIT IS READ ON %MORE THAN ONE BPM THE GIVEN TUNE VALUE SHOULD BE MULTIPLIED BY THE NUMBER %OF BPMS CONSIDERED. %EG: ALL 224 BPM ON A FIRST TURN: MULTIPLY THE COMPUTED TUNE %VALUE BY 224 %******************************************************************* % tune is then a line vector containing the tunes. The tune is calculated % doing a hanning window and making an interpolation to find the right peak % value on the spectrum. %M is the orbit matrix, DIVIDER is the step to resolve the main peak (Hz). step= %FFTstep/DIVIDER phases=NaN; tune=NaN; pointnotok=~isfinite(M); size(M); indbaddata=sum(pointnotok,1)>size(M,1)*0.15; M(pointnotok)=0; numdc=0; c=size(M,2); n=size(M,1); nu=[0:1:n-1]; han=(0.53836-0.46164*cos(2*pi*nu./(n-1)))'; hanext=han(:,ones(1,c)); if nargin>2 if window==1 M=M.*hanext; end end res=abs(fft(M(:,~indbaddata))); Mok=M(:,~indbaddata); res([1:3 end-3:end],:)=0; matexp=(i*2*pi*nu./n)'; [bid,ind]=max(res); if isreal(M) res(round(n/2):n,:)=0; end for k=1:size(res,2) serie=res(:,k); if ind(k)==1 subind=[0:1/(divider-1):1]; col=Mok(:,k); matcomp=sum(exp(matexp(:,ones(1,divider)).*subind(ones(n,1),:)).*col(:,ones(1,divider))); prodscal=abs((matcomp)); p=phase((matcomp)); [bid,indn]=sort(prodscal,2,'descend'); peakss(k)=prodscal(indn(1)); tune(k)=(subind(indn(1)))/n; phases(k)=p(indn(1)); camp(k)=matcomp(indn(1))/n; size(matexp(:,ones(1,divider))) size(subind(ones(n,1),:)) uvect(:,k)=exp(matexp.*subind(indn(1))); %exp(matexp(:,ones(1,divider).*subind(ones(n,1),:))); %peak(k)=0 % tune(k)=0; % numdc=numdc+1; %elseif ind(k)==n %tune(k)=1-1/n; else a=ind(k); col=Mok(:,k); %subind=[ind(k)-1.5:1/(divider-1):ind(k)-0.5]; subind=[ind(k)-1.5:1/(divider-1):ind(k)-0.5]; matcomp=sum(exp(matexp(:,ones(1,divider)).*subind(ones(n,1),:)).*col(:,ones(1,divider))); p=phase((matcomp)); prodscal=abs((matcomp)); [bid,indn]=sort(prodscal,2,'descend'); peakss(k)=prodscal(indn(1)); tune(k)=subind(indn(1))/(n); phases(k)=p(indn(1)); camp(k)=matcomp((indn(1)))/(n); uvect(:,k)=exp(matexp.*subind(indn(1))); end end tunef(indbaddata)=NaN; tunef(~indbaddata)=tune; phasef(indbaddata)=NaN; phasef(~indbaddata)=phases; \ No newline at end of file
 function [hor,ver,sig] = getSAdata_EBS_SIMU() % read BPM TbT buffer counter data_counter = tango.Attribute(obj.bpm_trigger_counter).value; pause(1.0) % necessary!! or later trigger counter re-reading will be already after KE shot! % necessary!! or could read two identical buffers! % wait for trigger couter to change integralwaited = 0.0; dt =0.2; while tango.Attribute(obj.bpm_trigger_counter).value == data_counter disp('waiting for fresh data'); pause(dt); integralwaited = integralwaited + dt; if integralwaited>10 warning('Waiting too long for new data, take what is available'); break end disp(['next data ' num2str(tango.Attribute(obj.bpm_trigger_counter).value) ' last measure: ' num2str(data_counter)]); end pause(2.0); hor = obj.hor_bpm_SA; ver = obj.ver_bpm_SA; sig = ones(size(hor)); % signal not available in simulator tango.Attribute(obj.sum_bpm_SA).value; end
 function [h,v,s] = getTbTdata_EBS_SIMU(obj) % read TbT data % read BPM TbT buffer counter data_counter = obj.bpm_trigger_counter; pause(1.0) % necessary!! or later trigger counter re-reading will be already after KE shot! % necessary!! or could read two identical buffers! % wait for trigger couter to change integralwaited = 0.0; dt =0.2; while obj.bpm_trigger_counter == data_counter disp('waiting for fresh data'); pause(dt); integralwaited = integralwaited + dt; if integralwaited>10 warning('Waiting too long for new data, take what is available'); break end disp(['next data ' num2str(obj.bpm_trigger_counter) ' before Ke: ' num2str(data_counter)]); end try if (obj.noise) obj.initial_coordinates.set( [obj.injoff, 0,0,0,0,0]+randn(1,6).*obj.injectorRMSNoise); end pause(1); % read BPM Turn-by-Turn h = obj.hor_bpm_TBT; v = obj.ver_bpm_TBT; % warning('logic/scalar error && -> & !') s = ~isnan(h) & ~isnan(v) ; catch err disp(err) error('ERROR RingControl.measuretrajectory: did you set BPM TbT?') return end end \ No newline at end of file
 function [h,v,s] = getTbTdata_ESRF_SR(obj) % read TbT data % read BPM TbT buffer counter data_counter = obj.bpm_trigger_counter; pause(1.0) % necessary!! or later trigger counter re-reading will be already after KE shot! % necessary!! or could read two identical buffers! % trigger injection and data acquisition if strcmp(obj.machine,'esrf-sr') & ~simulator Ke.On(); % dvcmd(Ke(1),'DevOn'); end % wait for trigger couter to change integralwaited = 0.0; dt =0.2; while obj.bpm_trigger_counter == data_counter disp('waiting for fresh data'); pause(dt); integralwaited = integralwaited + dt; if integralwaited>10 warning('Waiting too long for new data, take what is available'); break end disp(['next data ' num2str(obj.bpm_trigger_counter) ' before Ke: ' num2str(data_counter)]); end % read BPM Turn-by-Turn h = obj.hor_bpm_TBT; v = obj.ver_bpm_TBT; sig = obj.sum_bpm_TBT; sumsignal = sig(:,obj.first_turn_index); % measured signal s = (sumsignal-obj.sum_signal_background)./... (obj.sum_signal_beam-obj.sum_signal_background); end \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!