1 | function nus = getnus |
---|
2 | % Function getnus computes synchroton tune from XBPM |
---|
3 | % |
---|
4 | % OUTPUTS |
---|
5 | % 1. nus in Hz |
---|
6 | % |
---|
7 | % |
---|
8 | % Note: LOCUM bandwidth is 2.5 kHz, |
---|
9 | % So it is not possible to measure the nominal synchrotron tune |
---|
10 | % |
---|
11 | % See Also measmcf |
---|
12 | |
---|
13 | %% |
---|
14 | |
---|
15 | DisplayFlag = 1; |
---|
16 | XBPMFlag = 1; |
---|
17 | |
---|
18 | if XBPMFlag |
---|
19 | % Try with first XBPM of PX1 BL |
---|
20 | deviceName = 'TDL-I10-C/DG/DAQ.1'; |
---|
21 | |
---|
22 | |
---|
23 | rep = tango_read_attributes2(deviceName, {'channel0', 'channel1', 'channel2', 'channel3'}); |
---|
24 | |
---|
25 | % Build up X signal |
---|
26 | Xsignal = 1.4*((rep(1).value+rep(4).value)-(rep(2).value+rep(3).value))./ ... |
---|
27 | (rep(1).value+rep(2).value + rep(3).value+rep(4).value); |
---|
28 | |
---|
29 | %mean(Xsignal) |
---|
30 | |
---|
31 | XFFT = abs(fft(Xsignal)); |
---|
32 | |
---|
33 | % Build Z signal |
---|
34 | Zsignal = 1.385*((rep(1).value+rep(2).value)-(rep(3).value+rep(4).value))./ ... |
---|
35 | (rep(1).value+rep(2).value + rep(3).value+rep(4).value); |
---|
36 | |
---|
37 | %mean(Zsignal) |
---|
38 | |
---|
39 | ZFFT = abs(fft(Zsignal)); |
---|
40 | |
---|
41 | % Sampling rate is 10 kHz |
---|
42 | xval = (0:length(ZFFT)-1); % |
---|
43 | |
---|
44 | if DisplayFlag |
---|
45 | figure(44) |
---|
46 | clf |
---|
47 | subplot(2,1,1) |
---|
48 | plot(Xsignal) |
---|
49 | ylabel('H value') |
---|
50 | subplot(2,1,2) |
---|
51 | semilogy(xval, XFFT) |
---|
52 | ylabel('Amplitude (a.u.)') |
---|
53 | xlabel('Frequency Hz'); |
---|
54 | ylim([0 max(XFFT(10:end))]) |
---|
55 | xlim([0 length(Xsignal)/2-1]) |
---|
56 | end |
---|
57 | |
---|
58 | % look for synchrotron tune |
---|
59 | % should be maximum amplitude (discarding low frequency data) |
---|
60 | |
---|
61 | skip = 100; |
---|
62 | [val, idx] = max(XFFT(skip:end-7500)); idx = idx + skip-1; |
---|
63 | hold on; |
---|
64 | nus = xval(idx); |
---|
65 | plot(xval(idx), XFFT(idx), '*r'); |
---|
66 | |
---|
67 | fprintf('Max frequency is: %f Hz \n', nus); |
---|
68 | title(sprintf('Synchrotron tune: %5.2f Hz',nus)) |
---|
69 | |
---|
70 | else |
---|
71 | % Try with first BPMtest |
---|
72 | deviceName = 'ANS-C09/DG/BPMTEST.1'; |
---|
73 | |
---|
74 | |
---|
75 | rep = tango_read_attributes2(deviceName, {'XPosDD', 'ZPosDD'}) |
---|
76 | |
---|
77 | % Build up X signal |
---|
78 | Xsignal = rep(1).value; |
---|
79 | |
---|
80 | %mean(Xsignal) |
---|
81 | |
---|
82 | XFFT = abs(fft(Xsignal)); |
---|
83 | |
---|
84 | % Build Z signal |
---|
85 | Zsignal = rep(2).value; |
---|
86 | |
---|
87 | %mean(Zsignal) |
---|
88 | |
---|
89 | ZFFT = abs(fft(Zsignal)); |
---|
90 | |
---|
91 | % Sampling rate is 10 kHz |
---|
92 | xval = (0:length(ZFFT)-1); % |
---|
93 | |
---|
94 | if DisplayFlag |
---|
95 | figure(44) |
---|
96 | clf |
---|
97 | subplot(2,1,1) |
---|
98 | plot(Xsignal) |
---|
99 | ylabel('H value') |
---|
100 | subplot(2,1,2) |
---|
101 | semilogy(xval, XFFT) |
---|
102 | ylabel('Amplitude (a.u.)') |
---|
103 | xlabel('Frequency Hz'); |
---|
104 | ylim([0 max(XFFT(10:end))]) |
---|
105 | xlim([0 length(Xsignal)/2-1]) |
---|
106 | end |
---|
107 | |
---|
108 | % look for synchrotron tune |
---|
109 | % should be maximum amplitude (discarding low frequency data) |
---|
110 | |
---|
111 | [val, idx] = max(XFFT(1000:end)); idx = idx + 999; |
---|
112 | hold on; |
---|
113 | nus = xval(idx); |
---|
114 | plot(xval(idx), XFFT(idx), '*r'); |
---|
115 | |
---|
116 | fprintf('Max frequency is: %f Hz \n', nus); |
---|
117 | end |
---|