Home > mml > calcphase.m

calcphase

PURPOSE ^

CALCPHASE - Calculate the betatron oscillation phase at the BPM using turn-by-turn data

SYNOPSIS ^

function [phix,phiy]=calcphase(nux,nuy,fadx,fady)

DESCRIPTION ^

CALCPHASE - Calculate the betatron oscillation phase at the BPM using turn-by-turn data
   [phix,phiy]=calcphase(nux,nuy,fadx,fady)

  This function calculates the betatron oscillation phase at the BPMs
  using FAD data (turn by turn orbit measurement).

  return values:
  phix, phiy    horizontal and vertical betatron oscillation phase at every BPM

  input values:
  nux, nuy    horizontal and vertical tunes (as calculated by findfreq)
  fadx        horizontal FAD data (number of BPMs and number of turns is variable)
  fady        vertical FAD data

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [phix,phiy]=calcphase(nux,nuy,fadx,fady)
0002 %CALCPHASE - Calculate the betatron oscillation phase at the BPM using turn-by-turn data
0003 %   [phix,phiy]=calcphase(nux,nuy,fadx,fady)
0004 %
0005 %  This function calculates the betatron oscillation phase at the BPMs
0006 %  using FAD data (turn by turn orbit measurement).
0007 %
0008 %  return values:
0009 %  phix, phiy    horizontal and vertical betatron oscillation phase at every BPM
0010 %
0011 %  input values:
0012 %  nux, nuy    horizontal and vertical tunes (as calculated by findfreq)
0013 %  fadx        horizontal FAD data (number of BPMs and number of turns is variable)
0014 %  fady        vertical FAD data
0015 
0016 %  Christoph Steier, July 1999
0017 
0018 tmpx = sum(nux./abs(nux-mean(nux)))/sum(ones(size(nux))./abs(nux-mean(nux)));
0019 
0020 tmpy = sum(nuy./abs(nuy-mean(nuy)))/sum(ones(size(nuy))./abs(nuy-mean(nuy)));
0021 
0022 qx = 0.0; tmpsumx = 0.0; qy = 0.0; tmpsumy = 0.0;
0023 
0024 for n = 1:length(tmpx)
0025     if (abs(nux(n)-tmpx)<std(nux))
0026         qx = qx + nux(n)/abs(nux(n)-tmpx);
0027         tmpsumx = tmpsumx + 1/abs(nux(n)-tmpx);
0028     end
0029     if (abs(nuy(n)-tmpy)<std(nuy))
0030         qy = qy + nuy(n)/abs(nuy(n)-tmpy);
0031         tmpsumy = tmpsumy + 1/abs(nuy(n)-tmpy);
0032     end
0033 end
0034 
0035 qx = qx/tmpsumx;
0036 qy = qy/tmpsumy;
0037 
0038 fprintf('\n\nBPM #\tnu_x\t\tnu_y\n');
0039 
0040 for n=1:length(nux)
0041     fprintf('%2d:\t%8.6g\t%8.6g\n',n,nux(n),nuy(n));
0042 end
0043 
0044 outstring = sprintf('\nfractional horizontal tune (default=%g) ',qx);
0045 
0046 inx = input(outstring);
0047 
0048 if ~isempty(inx)
0049     qx = inx;
0050 end
0051 
0052 outstring = sprintf('\nfractional vertical tune (default=%g) ',qy);
0053 
0054 iny = input(outstring);
0055 
0056 if ~isempty(iny)
0057     qy = iny;
0058 end
0059 
0060 sfx=size(fadx);
0061 sfy=size(fady);
0062 
0063 mfadx = fadx-ones(sfx(1),1)*mean(fadx);
0064 mfady = fady-ones(sfy(1),1)*mean(fady);
0065 
0066 sfadx = sum(mfadx .* (ones(sfx(2),1)*sin(2*pi*qx*[0:(sfx(1)-1)]))');
0067 cfadx = sum(mfadx .* (ones(sfx(2),1)*cos(2*pi*qx*[0:(sfx(1)-1)]))');
0068 sfady = sum(mfady .* (ones(sfy(2),1)*sin(2*pi*qy*[0:(sfy(1)-1)]))');
0069 cfady =    sum(mfady .* (ones(sfy(2),1)*cos(2*pi*qy*[0:(sfy(1)-1)]))');
0070 
0071 phix = atan2(cfadx,sfadx)/(2*pi);
0072 for n = 1:length(phix)
0073     if (phix(n) < 0.0)
0074         phix(n) = phix(n)+1.0;
0075     end
0076 end
0077 
0078 phiy = atan2(cfady,sfady)/(2*pi);
0079 for n = 1:length(phiy)
0080     if (phiy(n) < 0.0)
0081         phiy(n) = phiy(n)+1.0;
0082     end
0083 end
0084 
0085 for n = 2:length(phix)
0086     while (phix(n) < (phix(n-1)-0.2))
0087         phix(n) = phix(n)+1.0;
0088     end
0089 end
0090 
0091 for n = 2:length(phiy)
0092     while (phiy(n) < (phiy(n-1)-0.2))
0093         phiy(n) = phiy(n)+1.0;
0094     end
0095 end

Generated on Fri 01-Aug-2008 10:57:33 by m2html © 2003