\documentclass[12pt,a4paper]{report}
\pagestyle{headings}
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{rotating}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{color}
\usepackage{soul}
\usepackage[titletoc]{appendix}
\usepackage{placeins}
\usepackage{upgreek}
\usepackage{pdfpages}

\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{1}

\begin{document}

\includepdf[pages=1-last]{header.pdf}

\setcounter{page}{1}

\tableofcontents


\chapter{Introduction}
 
\section{Nuclear fusion}
Fusion reactions form a branch of nuclear reactions in which two nuclei join together while energy is released (usually a significant amount). It is nuclear fusion that powers the Sun, and utilizing fusion reactions in a power plant could in future bring excellent source of energy to mankind, whose success and development is highly dependent on its ability to harness energy from natural sources. Such sources would have great advantage over fossil and fission power plants, as they would use much smaller amount of much cheaper fuel, be inherently safe and neither pollute the environment by exhaust gases nor produce significant amount of nuclear waste.

The only major utilization of artificial fusion reactions took place in early 1950s when thermonuclear weapons were invented. Technology to use fusion for peaceful purposes has been developed since, but a lot of issues has been encountered and taming fusion has proven to be a challenge.

\subsection{Coulomb barrier}
\label{sec_coulombbarrier}
In order to fuse, the two nuclei need to get very close to each other. Due to positive electric charge, the nuclei strongly repel each other, and high amount of energy has to be supplied to overcome this so-called Coulomb barrier. Although it is possible to accelerate a nucleus and let it hit the other one, it is not possible to build a power plant on this principle, because most of the energy is dissipated by scattering in the target material, and only a small fraction of the particles actually fuse.
Better concept is \emph{thermonuclear} fusion. Instead of accelerating particles against a target, the fuel is heated to very high temperatures where their thermal kinetic energy allows the most energetic particles to overcome the barrier. Scattering thus does not mean losing energy from the system, it rather only redistributes energy between individual particles.


\subsection{D-T fusion reaction}
There are many fusion reactions possible, but when one considers energy of the Coulomb barrier, cross section for fusion, availability of the fuel etc., there is not many candidates left. The one that seems to be the easiest to use is D-T reaction:
\[^2_1D\,+\,^3_1T\;\rightarrow \;^4_2He\,+\,^1_0n\,+\,17.6\,MeV\]
The disadvantage is that the majority of the energy is released as kinetic energy of the neutron, which would place the device in high neutron-flux. Another issue is that one of the reactants is tritium, which is radioactive and difficult to obtain (although it should be possible to use the neutrons to breed tritium in other nuclear reactions).



\subsection{Lawson criterion}
As mentioned in section~\ref{sec_coulombbarrier}, basic principle in thermonuclear fusion is heating the fuel to very high temperatures (so high that any material is in a plasma state). In order to keep the plasma at this temperatures one has to find a way to cover energy losses. Because part of the fusion energy in D-T reaction is released as kinetic energy of the alpha particle which does not escape from the plasma (unlike the neutron), it is in principle possible to use this energy to compensate for energy losses from the plasma. This state is called \emph{ignition}, and the condition for it to happen can be matematically expressed as
\[n\tau_E\geq f(T)\]
where $n$ denotes plasma density and $\tau_E$ \emph{energy confinement time}, which describes rate at which energy is lost from the plasma. $f(T)$ is a function of temperature with a low at about 25 keV. For a given temperature the equation basically says that the quicker energy is lost from the plasma, the higher the density has to be in order to achieve ignition.



\subsection{Tokamak}
Plasma cannot be in touch with a vessel it is contained in, because a contact with anything would mean the plasma would rapidly cool. In order to achieve sustainable steady state plasma, ways were invented to avoid the contact with the walls. A plasma by definition contains charged particles, which makes it possible to control it with magnetic or electric fields. There are many different configurations that were studied, but the most successful and promising turned out to be a soviet device called \emph{tokamak}.

The main part is a toroidal vacuum vessel with large coils around. These coils form strong toroidal magnetic field in the vessel. A small amount of gas is pumped into the well evacuated chamber and another coil induces electric field in the loop of gas, rapidly heats it up and turns it into plasma. Induced electric current passes through the plasma and heats it; at the same time this current creates another magnetic field that twists lines of force of toroidal field. The resulting shape of the field stabilizes the plasma and increases particle confinement time.

The plasma is turbulent and very difficult to contain, and a lot of issues in both physics and technology has to be solved before a fusion power plant is built. In order to push the research further, a lot of diagnostic tools is needed to gain information about all processes that take place during a tokamak discharge. One of the many (that this paper mainly concerns with) is interferometric diagnostics to measure density.


\section{GOLEM tokamak}
\subsection{History}
Tokamak GOLEM is one of the oldest tokamaks ever built, and the oldest still operational. Its rich history began in early 1960s, when it was built under a codename TM-1 as a small companion of tokamak T-1 at the Kurchatov institute in the Soviet Union. In mid-1970s it was moved to Czechoslovakia, where it was operated by Czechoslovak Academy of Sciences\footnote{Succeeded by Academy of Sciences of the Czech Republic} under the name CASTOR\footnote{\textbf{C}zech \textbf{A}cademy of \textbf{S}ciences \textbf{TOR}us}. A major refurbishment took place in mid-1980s. After ASCR acquired COMPASS tokamak from UKAEA\footnote{United Kingdom Atomic Energy Authority} in 2006, CASTOR tokamak was dismantled and donated to FNSPE CTU\footnote{Faculty of Nuclear Sciences and Physical Engineering, Czech Technical University}, where it is operated under the name GOLEM and serves as an educational tool.

\subsection{Parameters}

Tokamak GOLEM is a conventional tokamak with circular cross-section limiter. Its major radius is $R=0.4\ m$ and minor radius (limiter) only $a=0.085\ m$, which makes it also the smallest operational device of its kind. There are 18 diagnostic ports in the internal liner. The magnetic field is produced by discharging a capacitor battery into 28 toroidal coils. 

\begin{table}[h]
\centering
\begin{tabular}{|l|l|}
\hline
Toroidal magnetic field &  \textless 0.8 T  \\ \hline
Plasma Current & \textless 8kA \\ \hline
Discharge Duration & 13 ms \\ \hline
Central Electron Temperature & 80 eV \\ \hline
Safety Factor at Plasma Edge & 15 \\ \hline
Working Gas Pressure & 0-100 mPa \\ \hline
Work Gas & H$_2$ (He) \\ \hline
\end{tabular}
\caption{Basic parameters of the GOLEM tokamak}
\end{table}

\begin{figure}[h]
\centering
\includegraphics[width=145mm]{golem.jpg}
\caption{GOLEM tokamak photo (2015)}
\end{figure}


\FloatBarrier
\subsection{Current status}
\label{sec_golemhistorycurrentstatus}
During its operation at FNSPE, some of the tokamak parts were exchanged for new ones. The control system was also updated and the tokamak is now controlled by computer. Some new features were lately introduced by the students (as mentioned above, the device serves as an educational tool). The tokamak is connected to the internet and all discharges and data from all available diagnostics are immediately publicly available. It is also possible to use the internet for remote control experiments.

However, not all equipment that had been in use when the tokamak was stationed at ASCR is currently operational. Such is the case of an 4mm microwave interferometer, which was never successfully reinstalled (although a partially successful attempt has been made, as will be described in section~\ref{sec_2011}). As a result, currently there is no diagnostics that could provide reliable information on plasma density.



\section{Goals of this thesis}
\begin{itemize}
\item Provide detailed information on microwave plasma density measurement, describe basic physical phenomena regarding the topic and show issues that arise and how to deal with them. 
\item Make the interferometer on GOLEM tokamak operational again, so that the important information on plasma density is available to future researchers.
\item Include the interferometer output into GOLEM diagnostic system, which has changed significantly since CASTOR times.
\item Perform independent verification of the measured density (if possible).
\end{itemize}








\chapter{Interferometric measurement of plasma density}
\chaptermark{Interferometric density measurement}
Interferometry is in general a measurement method which utilizes electromagnetic radiation interference effect. A typical example comprises of a source that emits waves at some known wavelength. The wave is split into two, one serves as a reference, the other passes through a sample. By comparing phases of the two waves one can measure difference of the optical path and index of refraction of the sample.

This chapter describes principles of several basic microwave components, gives relation between phase shift in the plasma and its density and presents so called frequency modulating interferometer.

\section{Microwave technology preliminaries}
Microwave interferometry logically relies on microwave technology knowledge. The most important parts that will be used are the microwave generator, waveguides and detection diode. Only the very basic principles of their operation will be described. For detailed description please see specialized literature~\cite{bib_zacek}\cite{bib_kvasil}\cite{bib_gardiol}.

\subsection{Gunn diode oscillator}
Gunn diode is a solid state semiconductor device. Its function is based on Gunn effect discovered by J. B. Gunn in 1963. Unlike other diodes there is no P-N junction, but only N-doped semiconductor is used. Three regions exist -- heavily doped electrodes and a thin layer of lightly doped semiconductor in between. The electronic band structure contains a third band (aside from valence and conductive bands) which the electrons can occupy -- it is located above the conductive band, so the electrons must have certain threshold energy to reach it (this is called electron transfer). The mobility in the third band is lower than in conductive band. This produces a negative differential resistance region in the I-V characteristics because after certain voltage is applied electron transfer starts to occur, electrons start to occupy the third band and their mobility (and therefore current) decreases. This first occurs at the doping level boundary at the cathode due to the inhomogenity there.

An electron in the third band creates an non-homogenity in the electric field and electrons slowed by this field tend to bunch together, creating a high intensity field domain moving toward the anode at the speed of electrons in the upper band. The local concentration of electrons thus reduces electric field in the rest of the material (a large portion of the biasing voltage appears at the domain) preventing creation of another domain, until the first domain arrives at the anode. The process then repeats. 
\newline

\begin{figure}[h]
\centering
\includegraphics[width=80mm]{gunn.jpg}
\caption{Gunn diode oscillator~\cite{bib_gardiol}}\label{fig_gunn}
\end{figure}

Frequency of oscillations depends mostly on the material thickness, but can also be changed by placing the diode biased into negative resistance region into a resonant cavity. This is how Gunn diode microwaves oscillators are constructed (see figure~\ref{fig_gunn}). The cavity dimensions can usually be adjusted by a tuning piston, allowing to change the frequency in a narrow range. Additional tuning can be achieved electrically. Commercially available generators often use a varactor diode as a voltage-controlled capacity to allow rapid changes of the oscillation frequency. Output power can be as high as 100~mW, efficiency is usually low (several percent).


\subsection{Waveguides\label{sec_waveguides}}
Although microwaves (like all electromagnetic radiation) propagate through free space, it is necessary to have some way of guiding them where they are to be used. Waveguides are a way of achieving this. A waveguide is generally a hollow pipe (not necessarily circular in cross-section) made of conductive material. The wave travelling inside is thus confined to the inside and no energy is lost by radiation. Exact solution can be obtained by solving Maxwell equations with proper boundary conditions describing the waveguide.
\newline

The conclusion from the analysis (that will not be done here) is that for a given waveguide, only frequencies above certain so called \emph{cut-off frequency} can propagate. Frequencies significantly higher than this cut-off propagate almost at c\footnote{speed of light in vacuum}, decreasing the frequency reduces group velocity and increases wavelength. As frequency approaches cut-off, group velocity approaches zero (and wavelength infinity).

The wave can propagate in multiple modes (different distribution of electric and magnetic field). The modes are classified as TE (transverse electric -- electric field component along the direction of propagation is zero), TM (transverse magnetic) and TEM (transverse electric and magnetic)\footnote{It can be shown that hollow waveguide cannot support TEM modes.}. Every mode has different cut-off frequency for a given waveguide. That means that at high frequencies more modes can be present. As frequency decreases, single modes vanish one by one until a last one remains. This mode is called \emph{dominant mode}. The dominant mode is the one used during measurements and all other modes are supressed (easiest way is to choose proper waveguide size for a given frequency).



\subsubsection{Rectangular waveguide}
Most waveguides used at GOLEM are of rectangular cross section. Let us denote the sides $a$, $b$ and assume $a>b$. The cut-off frequency for TE$_{mn}$ and TM$_{mn}$ modes is 
\begin{equation}
f_c=\frac{c}{2\pi} \sqrt{\left(\frac{m\pi}{a}\right)^2+\left(\frac{n\pi}{b}\right)^2}
\end{equation}

It can be shown however, that TM mode with either m=0 or n=0 cannot exist in rectangular waveguide. The dominant mode is therefore TE$_{10}$ and its cut-off wavelength is $2a$. Electric and magnetic field lines are shown in figure~\ref{fig_rectangularte}. The electric field is parallel to the shorter side of the waveguide with a maximum value in the middle.

\begin{figure}[h]
\centering
\includegraphics[width=60mm]{rectangularte.png}
\caption{TE$_{10}$ mode in rectangular waveguide (solid lines -- E-field, dashed lines -- H-field)~\cite{bib_fig_modes}}\label{fig_rectangularte}
\end{figure}
 
Waveguides are usually made so that $a=2b$ to allow 2:1 dominant mode bandwidth and simultaneously maximize power that can be transferred before dielectric breakdown occurs. Table of waveguide types is shown in appendix~\ref{app_waveguides}. Given that microwave generator used at GOLEM has frequency of 71~GHz it is clear that only V,E and W band waveguides can be used (U would allow TE$_{11}$ mode to propagate, F would not allow 71~GHz through at all).
\newline

Although it has been noted that no energy is lost by radiation, waveguides still attenuate the wave that passes through them. The reason is that the wave induces current in the waveguide wall which results in resistive energy losses. A detailed analysis is complicated and will not be presented here, but in simple terms -- the smaller the waveguide, the higher the attenuation (as seen in appendix~\ref{app_waveguides}). In certain applications it might therefore be necessary to use larger waveguides than calculated from desired cut-off frequency for cutting distance. Such waveguides enable higher modes to propagate so it is necessary to transition to the proper waveguide size when the signal is manipulated with to supress them (in case they appear, which does not have to happen).

\subsubsection{Circular waveguide}
The situation with circular waveguide is similar to rectangular ones. At GOLEM tokamak they are only used at one place and cannot be manipulated with, so detailed description is omitted. Dominant mode is denoted~T$_{11}$ -- see figure~\ref{fig_circularte} to see the field lines. 

\begin{figure}[h]
\centering
\includegraphics[width=40mm]{circularte.png}
\caption{TE$_{11}$ mode in circular waveguide (solid lines -- E-field, dashed lines -- H-field)~\cite{bib_fig_modes}}\label{fig_circularte}
\end{figure}

\subsection{Detection diode}
The microwave signal is detected by means of a detection diode at GOLEM tokamak. It is a point-contact diode mounted inside a waveguide so that the E-field of the wave is perpendicular to the point. The waveguide assembly the diode is in is terminated by a short that reflects the incoming wave and creates a standing wave. The diode junction is located precisely one quarter of a wavelength from this short, which places it into first standing wave maximum. The voltage across the junction is approximately proportional to microwave power (for reasonably small power). A Russian-made detection diode D-404 is shown in figure~\ref{fig_d404} for illustration.
\newline

\begin{figure}[h]
\centering
\includegraphics[width=70mm]{d404.jpg}
\caption{D-404 detection diode (waveguide dimensions are about 7.1x3.55~mm -- Ka band)}\label{fig_d404}
\end{figure}



\section{Plasma behaviour and index of refraction}
\label{sec_plasmabehaviour}
When one wants to use interferometry to measure plasma density, it is obviously essential to know how plasma reacts to electromagnetic radiation and what its index of refraction depends upon. Electromagnetic radiation in a plasma in a presence of magnetic fields propagates in different modes, depending on direction of its $\bm{k}$, $\bm{E}$ and $\bm{B}$ vectors with respect to the external magnetic field $\bm{B_0}$ direction\cite{bib_kulhanek}. Providing that $\bm{k}\cdot \bm{B_0}=0$ and $\bm{E}\parallel \bm{B_0}$, only so called \emph{O-wave} (ordinary wave) propagates.
By introducing \emph{plasma frequency}
\[\omega_p^2={\frac{ne^2}{\varepsilon_0 m}}\]
($n$ denotes plasma density, $e$ elementary positive charge, $\varepsilon_0$ vacuum permittivity and $m$ electron mass), the index of refraction for O-wave at angular frequency $\omega$ can be written as (the last approximation is valid for $\omega>>\omega_p$)\footnote{To keep things simple, validity of the approximation will be assumed throughout the rest of this paper. For average plasma density of $10^{19}\, \textrm{m}^{-3}$ (which is higher than usually observed density) the approximation results in an error of about 4~\%. That is reasonable, considering that without the approximation, following steps would get very complicated (section~\ref{sec_lineintegrateddensity}) and would require some estimation anyway.} 
\begin{equation}
N_O=\sqrt{1-\frac{{\omega _p}^2}{\omega ^2}}\approx 1-\frac{ne^2}{2\varepsilon_0m\omega^2}
\label{eqn_indexofrefraction}
\end{equation}


Two very important points can be derived from the expression:
\begin{itemize}
\item{The index of refraction is always smaller than 1 and decreases as density increases (for $\omega>>\omega_p$ approximately linearly)}
\item{O-wave only propagates when $\omega>\omega_p$}
\end{itemize}

Because plasma frequency increases with density, for every wave frequency $\omega$ there is a \emph{critical density}
\[n_c=\frac{\varepsilon_0m}{e^2}\omega^2\]
which is the highest density that allows the wave to propagate. For density higher than the critical density, plasma frequency is higher than the wave frequency, which results in imaginary index of refraction and the wave therefore cannot propagate and is reflected. This places a lower limit on the frequency of the interferometer.

\section{Relation between index of refraction and change of phase}
However, the index of refraction cannot be directly measured and this is where interferometry comes in. The diagnostic beam passes through the plasma and the index of refraction is calculated from the resulting change of phase. Let us assume that $\lambda_1=\frac{c}{f}$ denotes vacuum wavelength of the radiation, while $\lambda_2=\frac{c}{Nf}$ is the wavelength in a medium with index of refraction $N$. Providing that path length through the medium is $L$ and both waves have zero phase when entering the medium, the phases $\varphi_{1,2}$ at the end of the path can be written as
\[\varphi_{1,2}=2\pi\frac{L}{\lambda_{1,2}}\\\]
And therefore
\begin{equation}
\Delta\varphi=\varphi_2-\varphi_1=\frac{\omega L}{c}\left(N-1\right)
\label{eqn_phaseshift}
\end{equation}
As mentioned earlier, the index of refraction of the tokamak plasma is less than unity, and can be calculated from equation~\ref{eqn_indexofrefraction}. Equation~\ref{eqn_phaseshift} then gives
\begin{equation}
\Delta\varphi=-\frac{\omega L}{c}\cdot \frac{ne^2}{2\varepsilon_0 m \omega^2}=-\frac{Lne^2}{2c\varepsilon_0 m\omega}
\label{eqn_phaseshift2}
\end{equation}
The phase shift in presence of the plasma is negative, which means the optical path is shorter. If one wants to simulate plasma appearance by changing the length of the waveguide, it is necessary to \emph{shorten} the waveguide, which may seem counter-intuitive to some.



\section{Line-integrated density\label{sec_lineintegrateddensity}} 
It may seem that calculating density from equation~\ref{eqn_phaseshift2} is straightforward. However, the above derivation was based on the fact that the density distribution is uniform, which is rarely the case in practice. By looking on the right-hand side one can easily see that the correct equation for non-uniform density profile is 

\[\Delta\varphi=-\frac{e^2}{2c\varepsilon_0 m\omega}\int_0^L n(l) \, dl\]
and therefore
\begin{equation}
\underbrace{\int_0^L n(l) \, dl}_{n_i}=-\frac{2c\varepsilon_0 m\omega \Delta\varphi}{e^2}
\label{eqn_phaseshift3}
\end{equation}

The integral is obviously line integral along the wave path parametrised by its length. Without knowing the dependence $n(l)$ it is only possible to calculate the value of the integral. Therefore \textbf{the quantity that can be calculated from the measured phase shift is integral density along the path of the diagnostic wave}
\[n_i=\int n(l) \, dl \quad [m^{-2}]\]
\newline

The integral density is not relevant and it is needed to calculate more important quantities, namely average density along the path $n_L\;[m^{-3}]$ and maximal density in the plasma center $n(0)\;[m^{-3}]$. This calculation requires to know other parameters of the plasma, specifically
\begin{itemize}
\item{Length of the path in the plasma $L$ to determine $n_L$}

\item{Length of the path in the plasma and density profile along this path to determine $n(0)$}
\end{itemize}

The former can be obtained from other diagnostics (or estimated from limiter diameter), the latter requires estimation, which makes the interferometric measurement of plasma density complex.


\section{Calculating $n_L$ and $n(0)$}
As mentioned above, integral density along the path $n_i=\int n(l) \, dl$ is not very suitable, and the question arises how to use it to calculate more convenient average density along the line of sight $n_L$ and central density $n(0)$. Let us assume, that the path length $L$ has been obtained from another diagnostics and density profile $n(r)$ is estimated (except for a multiplicative constant).
\newline

Calculating $n_L$ is straightforward and needs no commentary:
\[n_L=\frac{1}{L}\cdot n_i \qquad [m^{-3}]\]
Calculating $n(0)$ is more difficult, and this issue will be dealt with separately for circular and vertically elongated plasma.


\subsection{Calculating $n(0)$ for circular plasma}
In order to calculate $n(0)$, density profile $n(r)$ has to be estimated. Let us assume parabolic density profile
\[n(r)=n(0)\left(1-\frac{r^2}{a^2}\right)\]
where $r$ is the distance from plasma center and $a$ minor radius. Now it is possible to evaluate the relation between $n(0)$ and integral density $n_i$ by integrating the above equation along the line of sight.
\[n_i=\int_{-a}^{a}n(r) \, dr=n(0)\int_{-a}^{a}\left(1-\frac{r^2}{a^2}\right) \, dr=\frac{4}{3}an(0)\]
And because $L=2a$, the expression can be rearranged as
\[n(0)=\frac{3}{2}\frac{n_i}{L}=\frac{3}{2}n_L\]


\subsection{Calculating $n(0)$ for vertically elongated plasma}
Let us assume that the plasma originally circular with minor radius $a_c$ was vertically elongated to minor radius $a_e$, and that the density profile in the outer part is unchanged, whereas in the center the density is constant, i.e.
\[
n(r)=\left\lbrace \begin{array}{l l l}n(0)\left(1-\frac{\left(r-\left(a_e-a_c\right)\right)^2}{a_c^2}\right) &\,\text{if }r\in (-a_e,-(a_e-a_c))\cup (a_e-a_c,a_e)\\ \\n(0) &\,\text{if }r\in (-(a_e-a_c),a_e-a_c)\end{array} \right.
\]
The integral density in this case is obviously higher than in the case of circular plasma, specifically it is
\[n_i=\frac{4}{3}a_cn(0)+2(a_e-a_c)\cdot n(0)=\frac{2}{3}n(0)\left(3a_e-a_c\right)\]
and therefore
\[n(0)=\frac{3n_i}{2(3a_e-a_c)}\]



\section{Specific issues for tokamak plasma\label{sec_specificissues}}
So far the method seems simple, but one has to realise that it is not possible to measure arbitrary large difference of phase. Phase differences of the form  $2k\pi,k\in\mathbb{Z}\, \mathrm{(whole\, number)}$ are equivalent, so no matter what detector is used, the actual phase difference can be different by any whole multiple of $2\pi$. Whenever the difference is greater than $2\pi$, it is not measured correctly. See Fig.~\ref{fig_fringes} as an illustration. Looking at~\ref{eqn_phaseshift2}, one might get an impression that using frequency high enough to make the phase change small can resolve the problem. However, using too high frequencies results in different issues (e.g. high sensitivity to vibrations due to shorter wavelength).



As mentioned in section~\ref{sec_plasmabehaviour}, there is also a lower limit on the frequency of the diagnostic wave. Considering plasma density $10^{19}\;m^{-3}$ (which is the order of plasma density in a tokamak), this limit is roughly 30 GHz (the frequency has to be higher in order for the approximation $\omega>>\omega_p$ to be valid). The wave therefore has to be in microwave range. At GOLEM tokamak, it is roughly 71~GHz with a path length of 0.17 m (limiter diameter). It is therefore possible to calculate what density increase results in a fringe in the data. By substituting $\Delta\varphi=-2\pi$ (phase difference is negative, as shown above) into equation~\ref{eqn_phaseshift2} and solving for $n$, one gets an average density (let us call it \emph{fringe density}) $n_f$:
\[n_f=\frac{4\pi\varepsilon_0 m \omega c}{e^2L}\approx 3.11\cdot 10^{18}\,m^{-3}\]
That means there can be several fringes observed during a shot. It is possible to follow the record and remove the discontinuities between the fringes. However, when the number of fringes is too high, this process is not possible, because whenever a part of the record is lost (e.g. due to refraction of the wave), several fringes can be missed and one loses count. It is then impossible to continue at the correct spot.


\begin{figure}
\centering
\includegraphics[width=125mm]{fringes.png}
\caption{Top - actual phase difference, bottom - measured phase difference (illustrative); the original signal is only possible to reconstruct when there are no gaps in the measured signal}\label{fig_fringes}
\end{figure}



\section{Frequency-modulating interferometer\label{sec_phasemodullatinginterferometer}}
As described above, measuring line integrated plasma density can be done by measuring phase shift of the diagnostic wave after it passes through the plasma. In order to achieve this, the wave is split before entering the plasma. One wave is used as a reference (and does not pass through the plasma), the other wave is used as the diagnostic wave. Mutual phase shift changes are result of the plasma influence.

Measuring the mutual phase shift can be performed by adding the waves together, and calculate the phase shift from the amplitude of the resulting wave. However, this amplitude depends not only on the phase shift, but also on the amplitude of the two interfering waves (which is an obvious fact). Since the amplitudes do not carry any information necessary to calculate density, a method to eliminate influence of the amplitudes is desired. One of possible solutions to this problem is to modulate the frequency of the wave. This type of interferometer is called~\emph{Wharton interferometer}\cite{bib_zacek}.

\subsection{Principle of operation\label{sec_fmiprinciple}}
Let us first assume there is no plasma in the examined volume. As in the general case, the generated wave is split into two -- one passes through the plasma, the other is used as a reference. The diagnostic wave passes through a long waveguide, so the path it travels is longer than the path of the reference wave. Let $\Delta L$ denote the path difference.

The frequency of the wave generator is periodically changed by a sawtooth voltage signal. After the two waves interfere, a series of interference maxima will be created, because changing the frequency results in change of the relative phase difference between the two waves. Let $\Delta f$ denote frequency change during modulation and $c$ speed of light in a vacuum. A simple calculation shows that with frequency change $\Delta f$ the change of the phase difference is \footnote{The square root compensates for dispersion of the waveguide (a small change during frequency sweep is neglected ($\Delta f<<f$). $f_c$ denotes waveguide cut-off frequency. }

\begin{equation}
\Delta \varphi = \Delta(\varphi_{diag}-\varphi_{ref})=\frac{2\pi \, \Delta f \, \Delta L}{c\cdot \sqrt{1-\left(\frac{f_c}{f_0}\right)^2}}
\label{eqn_phaseshift4}
\end{equation}

The change of the phase difference only depends on the extra length of the waveguide and the change of frequency -- not on the frequency itself.
\newline

The situation is demonstrated in Fig.~\ref{fig_wharton}. Chart (a) shows frequency changes of the generator and chart (b) shows voltage on detecting diode (which is proportional to amplitude of the wave after superposition). In can be seen that the amplitude periodically changes due to frequency modulation. Chart (c) shows short rectangular pulses derived from (b) by convenient electronic conversion (amplification and derivation). These pulses have constant temporal spacing which represents phase change of $2\pi$.
\newline

Introducing plasma results in additional phase shift of the diagnostic wave. That in turn shifts the interference maxima relative to modulating sawtooth. This shift can be used to calculate phase change caused by the plasma. The period of the sawtooth must be shorter than typical time of the observed processes in the plasma -- specifically, the phase shift by the plasma can never exceed $2\pi$ during one sawtooth period. 

\begin{figure}[h]
\centering
\includegraphics[width=120mm]{whartonchart.png}
\caption{Principle of frequency modulating interferometer}\label{fig_wharton}
\end{figure}


\subsection{Calculating density}
It is now necessary to calculate the temporal spacing of the pulses and its shift when plasma appears, and describe how it can be used to calculate phase shift caused by the plasma presence. Let $f_0$ denote basic wave frequency and $\Delta f$ its change during modulation (so that frequency changes from $f_0$ to $f_0+\Delta f$). Let the sawtooth frequency be denoted $f_{ST}$. The wave signal after the interference is processed and short rectangular pulses that mark its periodicity are created. Because these pulses always mark a $2\pi$ phase difference, it is possible to calculate diagnostic  wave frequency change that separates two consecutive pulses from equation~\ref{eqn_phaseshift4} (see figure~\ref{fig_wharton} for illustration). It will be referred to as $\delta f$:
\begin{equation}
\delta f=\frac{c\cdot \sqrt{1-\left(\frac{f_c}{f_0}\right)^2}}{\Delta L}
\label{eqn_deltaf}
\end{equation}

Because the frequency rise is linear, frequency $f$ in a given time $t$ during the first sawtooth period can than be written as
\[f=f_0+f_{ST}\cdot \Delta f \cdot t\]

It is then easy to calculate the temporal spacing of the pulses:
\begin{equation}
t_{pulses}=\frac{\delta f}{f_{ST}\cdot |\Delta f|}
\label{eqn_tpulses}
\end{equation}
\newline

Let us now assume that after plasma was created in the examined volume, the diagnostic wave experienced additional (negative) phase shift $\varphi_p$ and in turn the pulses have shifted by $\Delta t$ \emph{to the right} from their previous position relative to the modulating sawtooth. $\varphi_p$ can once again be easily calculated from proportionality. Because time interval $t_{pulses}$ represents $2\pi$ phase change, time interval $\Delta t$ represents\footnote{$\Delta t$ and $\varphi_p$ are signed.}
\[\varphi_p=-\frac{2\pi\Delta t}{t_{pulses}}\]
By substituting for $t_{pulses}$ from equation~\ref{eqn_tpulses} and for $\delta f$ from equation~\ref{eqn_deltaf}, the phase shift $\varphi_p$ can be expressed using originally known quantities:
\begin{equation}
\varphi_p=-\frac{2\pi f_{ST} \Delta f \Delta L}{c\cdot \sqrt{1-\left(\frac{f_c}{f_0}\right)^2}}\, \Delta t
\label{eqn_plasmaphaseshift}
\end{equation} 
In summary, by measuring temporal shift of the pulses one can easily calculate diagnostic wave phase shift caused by the plasma and use it to calculate line integrated density by substituting the result into equation~\ref{eqn_phaseshift3}.

\subsection{Phase shift sign\label{sec_phaseshiftsign}}
For the sake of clarity, $\Delta f$ was assumed to be positive in previous section (that means the sawtooth ascending ramp was assumed to be the longer one). It is however possible to use inverted sawtooth with descending ramp. This significantly changes the situation. Because the frequency is then swept in reverse direction, introducing additional negative phase shift in the diagnostic wave path (plasma) shifts the interference sine to the other side relative to the sawtooth (i.e., to the left). This has to be taken into account -- otherwise the resulting density will come with opposite sign.
\newline

Shortly put:
\begin{itemize}
\item Ascending ramp -- introducing plasma shifts detected signal to the right relative to the sawtooth
\item Descending ramp -- introducing plasma shifts detected signal to the left relative to the sawtooth
\end{itemize}

Note that equation~\ref{eqn_plasmaphaseshift} is valid in both cases. As was just explained, changing sign of $\Delta f$ results in change of sign of $\Delta t$. The product therefore maintains its sign.











\chapter{GOLEM interferometer}
As mentioned in section~\ref{sec_golemhistorycurrentstatus}, the phase-modulating interferometer was used on CASTOR tokamak at ASCR. After the tokamak has been moved to \mbox{FNSPE} CTU, the interferometer was never successfully installed (although it was operated for some time with limited success, see section~\ref{sec_2011}). This chapter provides information about how the device had operated. All parts are described, their function is tested, and necessary steps are taken when a problem is discovered.
\newline



\section{Parameters for calculations}
From the principle of frequency-modulating interferometer (described in section~\ref{sec_fmiprinciple}) it is obvious that there are several parameters that can be chosen arbitrarily. Approximate values chosen for CASTOR follow.
\newline

\begin{tabular}{l l l l}
Gunn oscillator frequency: & $f_0$ & = & 71 GHz \\
Sawtooth frequency: & $f_{ST}$ & = & 500 kHz \\
Frequency sweep: & $\Delta f$ & = & 30 MHz \\
Waveguide path difference: & $\Delta L$ & = & 10 m 
\end{tabular}
\vspace{5 mm}

What is worth noting is that for these values and the waveguide used a relation $\Delta f=\frac{c\cdot \sqrt{1-\left(\frac{f_c}{f_0}\right)^2}}{\Delta L}$ holds, which further means that $t_{pulses}=\left(f_{ST}\right) ^{-1}$ (it is actually carefully tuned so that the relation holds). The beats on the detecting diode will have the same frequency as the sawtooth generator has. This fact is very important for proper function of the interferometer.


\section{Block diagram}
The block diagram of the interferometer as it was used at CASTOR tokamak is shown in figure~\ref{fig_interferometersetup} (the thick lines are waveguides). The sawtooth generator produces sawtooth to sweep the oscillator frequency. The microwave signal is divided -- one wave passes through the plasma, the other is fed straight to the detecting diode, where it interferes with the former. The signal on the diode is extremely weak and contains noise from the sweep reset. Both issues are resolved by narrow-band selective amplifier, that inhibits all unwanted frequencies and amplifies the signal. It is then evaluated by the interferometer that measures the time shift of the signal with respect to the reference from sawtooth generator.

\begin{figure}
\centering
\includegraphics[width=120mm]{castor_scheme.png}
\caption{Interferometer setup on CASTOR tokamak}\label{fig_interferometersetup}
\end{figure}



\FloatBarrier
\section{Sawtooth generator}
The sawtooth generator was made at ASCR and it is crucial part of the device. It provides sawtooth for sweeping the oscillator output frequency and also produces short pulses that mark the sawtooth reset. The schematic is shown in figure~\ref{fig_sawtoothgenscheme}. The circuit is based on transistors, the key part is a monostable multivibrator consisting of transistors T$_2$ and T$_3$. When in stable state, T$_3$ is open and capacitor C$_4$ is rapidly charged. After it is charged, T$_3$ transistor is closed and flips the multivibrator to unstable state. C$_4$ slowly discharges through T$_4$ which maintains constant discharging current, producing a descending ramp (rather than exponential). Before the unstable period of the monostable is finished, transistor T$_3$ is forced open by lowering the emitter voltage. This charges the C$_4$ capacitor, starting the cycle over again. The fact that the sawtooth is inverted -- the rising edge is the steep one is not relevant for interferometer function (although it needs to be considered during evaluation).
\newline 

\begin{figure}
\centering
\includegraphics[width=130mm]{sawtoothgen.png}
\caption{Sawtooth generator schematic}\label{fig_sawtoothgenscheme}
\end{figure}

Transistor T$_1$ is used as a voltage buffer for the reference pulses. The rest of the circuit allows to set amplitude and DC offset of the sawtooth signal. The whole circuit (including a power supply) is in a metal box, the front panel controls allow the user to change the frequency (P$_2$) and amplitude (P$_6$) of the sawtooth. Potentiometer P$_7$ to set the DC offset is accessible through a hole in the metal casing. The power source is located inside the casing which connects directly to mains.
\newline

The correct function of the generator was tested. Both output signals can be seen in figure~\ref{fig_pila}. Analysis of the sawtooth showed that the fast rising edge duration is about 10 \% of each period (minimum to maximum). The frequency can be adjusted by changing P$_2$ value from 470 kHz to 570 kHz, by adjusting P$_6$ and P$_7$ various amplitude and DC offset combinations can be chosen. Maximum voltage range is 0.8 -- 9 V. The adjusting potentiometers were found to be in bad shape, but can still be used.
\newline

\begin{figure}
\centering
\includegraphics[width=100mm]{gen_pily.png}
\caption{Sawtooth generator output signals}\label{fig_pila}
\end{figure}


The synchronous reference pulses at the other output are asymmetrical with sharp rising edge about 60 ns long, the falling edge is about three times as long. The voltage range is --640 mV to 4.8 V and cannot be changed.
\newline

The frequency output was stable, although it was observed that when the device was manipulated with, the stability deteriorated significantly. The reason was discovered after the cover was removed -- a broken lead on a bypass capacitor from the power source resulted in unstable supply voltage. The broken lead was conductive, unless the device was tilted to unfavorable position and the wires disconnected. As soon as the problem was identified, the capacitor was replaced and the issue was fixed.

\begin{figure}
\centering
\includegraphics[width=130mm]{kondenzator.jpg}
\caption{Sawtooth generator PCB with the faulty capacitor (the red one)}
\end{figure}


\section{Selective amplifier}
The selective amplifier made at ASCR amplifies the weak signal from the detecting diode. According to the documentation, the gain is about 86~dB, the band is centered at 500~kHz and the bandwidth is 40~kHz. The selectivity of the amplifier reduces noise to a minimum and also eliminates the peak that results from the sawtooth falling edge.
\newline

The schematic is in figure~\ref{fig_selectiveampscheme}. The circuit is again made of transistors, no IC is used. It is a four stage standard transistor amplifier with common emitter. Stages 1 and 3 are tuned -- there is a parallel RLC circuit in collector, which results in the frequency selectivity. The gain can be adjusted by means of potentiometer P$_2$, which is accessible through the front panel. Same metal casing as in the case of the sawtooth generator is used. The power source is located inside the casing which connects directly to mains.

\begin{figure}
\centering
\includegraphics[width=130mm]{selectiveampscheme.png}
\caption{Selective amplifier schematic}\label{fig_selectiveampscheme}
\end{figure}


The amplifier frequency response was measured by means of a signal generator and oscilloscope. Due to its high gain it was necessary to use a voltage divider to avoid saturation. A simple resistive voltage divider consisting of 27 k$\Omega$ and 270 $\Omega$ resistors was used. The smaller resistor should provide low enough output impedance. The signal amplitude was set to 40~mVpp to ensure the amplifier is not saturated. The amplifier voltage gain (set to minimum) as a function of frequency is showed in figure~\ref{fig_zesilovac}.
\newline

\begin{figure}
\centering
\includegraphics[width=130mm]{zesilovac.png}
\caption{Selective amplifier gain (set to minimum)}\label{fig_zesilovac}
\end{figure}
\vspace{5mm}


It was concluded that the circuit is fully operational, although its parameters slightly differ from expected values. Its center frequency is 521.6~kHz and $-3$ dB bandwidth is about 23~kHz. The voltage gain can be adjusted by a potentiometer accessible through the front panel -- the center frequency gain changes from 4300 to 21500 (73--86~dB). It was observed that the amplifier limits the output signal asymmetrically, which is not desirable for maximum interferometer performance. The problem was solved by adjusting trimmer $R_{14}$ to get symmetric limiting (see figure~\ref{fig_zesilovacsaturace}).

\begin{figure}
\centering
\includegraphics[width=100mm]{zesilovacsaturace.png}
\caption{Clipped signal before (red) and after (black) adjustment}\label{fig_zesilovacsaturace}
\end{figure}


\section{Interferometer circuit}
The interferometer (phase detecting) circuit is the most important part of the device. As the previously described circuits, it too has been made at ASCR during CASTOR tokamak operation. It compares the signal from the detecting diode (after it passed through the selective amplifier) with the reference marks from the sawtooth generator. As shown in section~\ref{sec_fmiprinciple}, plasma appearance results in mutual shift of the two signals. The circuit measures the time shift.
\newline

The circuit is a bit more complex (figure~\ref{fig_interferometerscheme}). Both signals are amplified by MAA502 operational amplifiers\footnote{MAA502 at 500 kHz is pushed to its limits.} to a level high enough to be recognized by TTL logic. The signal is differentiated and formed into short rectangular pulses. These pulses are fed to 8:1 dividers. The resulting signals are used as a source for an SR flip-flop, which produces a rectangular wave. Its duty cycle is proportional to the time shift of the two input signals. The duty cycle is converted to DC voltage by a low-pass filter. The third output is used to set a zero position before the measurement. The power source is located inside the casing which connects directly to mains.

\begin{figure}
\centering
\includegraphics[width=180mm,angle=90]{interferometerscheme.png}
\caption{Interferometer circuit used at CASTOR}\label{fig_interferometerscheme}
\end{figure}

The purpose of the 8:1 dividers is to reduce fringes in the output voltage signal. If the phase shift of the two inputs increases, the fringe in output voltage will appear after the difference equals $16\pi$, not $2\pi$ (as it would without the dividers). The downside is reduced temporal resolution.
\newline


The interferometer circuit was tested and recognized as inoperative. Visual inspection of the printed circuit board showed no signs of an issue. By further analysis the suspicion fell on the second input preamplifier part. When the sawtooth generator signal was connected to the interferometer circuit, it was highly distorted (see figure~\ref{fig_distortion}), which clearly indicates a problem at the input. The issue was however not investigated further.

\begin{figure}
\centering
\includegraphics[width=80mm]{distortion.png}
\caption{Pulses from sawtooth generator before (black) and after (red) connection to interferometer input}\label{fig_distortion}
\end{figure}



\section{Microwave components}
The interferometer used on CASTOR consisted of many microwave components. Two waveguide sizes are used -- Ka band waveguides to pass the distance to and from the tokamak, E band for the generator and surrounding parts\footnote{See appendix~\ref{app_waveguides} for the band specifications.}. Despite using E band waveguides for the whole device might seem more convenient, long diagnostic line would result in unacceptably high power loss. E band waveguide is only used where the signal is actually worked with, to prevent propagation of higher waveguide modes that could appear in the wider waveguide (see section~\ref{sec_waveguides}).

The basic schematics is shown in figure~\ref{fig_microwavesscheme}. The components shown are:
\begin{enumerate}[a)]
\item Microwave generator
\item Directional coupler
\item Attenuator
\item Phase shifter
\item Magic tee with detection diode holder
\item Waveguide transitions (E-band to Ka band)
\item Ka band waveguides to the tokamak
\item Tokamak antennas
\end{enumerate}

\begin{figure}
\centering
\includegraphics[width=100mm]{microwaves_scheme.png}
\caption{Simplified schematics of microwave components layout (description in the text)\label{fig_microwavesscheme}}
\end{figure}

Because the interferometer was made from many different parts from different manufacturers, some of the parts were incompatible (due to different flanges and/or waveguide dimensions). To pass this issue, various custom-made connecting parts are used. For the sake of simplicity, these are not included in this overview.


\subsection{Microwave generator\label{sec_microwavegenerator}}
The available microwave generator was made in the Ukraine. According to documentation, its output power is 60~mW and frequency is 71~GHz. Maximum varactor voltage of 17~V makes the output frequency 360~MHz higher (with approximately linear dependence). Maximum supply voltage is 31~V at 140~mA. The generator is enclosed in black metal casing. E-band waveguide with Ukrainian-type flange is used at the output.

\begin{figure}
\centering
\includegraphics[width=100mm]{gen_photo.jpg}
\caption{Ukrainian Gunn generator and its power supply}
\end{figure}

The Gunn diode used in the generator is critically sensitive to voltage spikes and can be easily destroyed. Although the generator should have appropriate protection circuits in the casing, a special power supply with spikes protection and current limiting circuit was constructed at CASTOR and is available to use.
\newline

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{iv_vykon.png}
\caption{Ukrainian generator I-V characteristics and power output\label{fig_gunnchar}}
\end{figure}

The correct function of the generator was tested by measuring its I-V characteristics (see figure~\ref{fig_gunnchar}). Its output power was simultaneously checked by measuring current through a detecting diode placed directly in front of the output waveguide. The diode was however not calibrated, so absolute power output could not be determined. It was however concluded that the generator is operational and ready to use.



\subsection{Directional coupler}
\subsubsection{Old CASTOR coupler}
The multihole directional coupler was manufactured in Russia (USSR) and it clearly was not factory made. The flanges are Russian. No specification datasheet exists, but according to Ing.~Frantisek Zacek\footnote{CASTOR scientist and this thesis supervisor} its coupling value was about 10~dB.
\newline

The coupler was connected to the above-described generator to check its function. The output power was measured by detection diode. The straight waveguide output showed no measurable attenuation. However, the signal at the coupling output could not be measured. Because the detection diode would clearly be capable of measuring the expected value, it was concluded that {\bf{\ul{the directional coupler is faulty and has to be repaired or replaced}}}.
\newline

\subsubsection{Locating the problem}
Because the device was repaired in 2011 (see section~\ref{sec_2011} for details), the suspicion was that the repair was unsuccessful. A photo documenting the coupler being repaired was found, the coupler was desoldered again and the internal state was evaluated and compared to 2011 state. See the comparison in figure~\ref{fig_coupler}.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{coupler.jpg}
\caption{Directional coupler - desoldered\label{fig_coupler}}
\end{figure}

Although there is significantly more solder in the waveguide than it was previously, it could as well have got there during the desoldering process when the two parts slid on each other. The holes are not filled with solder (which was expected). What however immediately draws suspicion is the ferrocart\footnote{Ferrocart is a fine iron powder cast into epoxy resin in a specific ratio.} block placed in the dead end of the coupled waveguide. It is significantly shorter than it had been and its edges are sharp as if it was broken. The likely explanation is that it was damaged during the 2011 repair (maybe due to excess heat during soldering) and reinstalled as it was. The ferrocart is an essential part of the coupler that prevents reflections -- which is why it should be wedge-shaped and at least several wavelength long to gradually attenuate the incoming wave. It is very likely that it is the main source of the problem.
\newline

After checking the state of the coupler and evaluating options to repair it, the conclusion was reached. Even if the coupler was repaired (which could not be guaranteed) it would most likely be prone to another fail and could not be considered reliable. Because it is one of the main parts of the interferometer, the decision was made to not risk the repair and rather buy a brand-new directional coupler. It was therefore ordered and substituted the old part.

\subsubsection{New directional coupler}
The coupler was manufactured by Millimeter Wave Products Inc. in the USA. Its coupling value is 10~dB, flanges are standard UG-387/U with imperial thread. Connecting the coupler to the rest of the apparatus therefore required a non-standard solution. Luckily all three ports were to be connected to the UG-387/U flange with metric threads -- the easiest way to do it was to drill the metric thread off and use imperial screw to tighten the flanges together. The new part function was checked and it performed flawlessly.
\newline

Because whatever is connected to the coupler can easily induce large torque due to long leverage, a plastic block was used to provide mechanical support for the coupler. A recession deep just to conceal the waveguides was machined into the block and a small metal plate was bolted on top to lock the coupler in place. Hopefully it will help to avoid any damage to the coupler. See figure~\ref{fig_newcoupler} for illustration.
\newline

\begin{figure}
\centering
\includegraphics[width=130mm]{newcoupler.jpg}
\caption{New directional coupler with its protective support\label{fig_newcoupler}}
\end{figure}


\subsection{Attenuator and phase shifter}
These two devices were manufactured in Prague during CASTOR times. They use flanges dimensionally equivalent to UG-387/U, except with metric threads. Including the phase shifter in the reference wave path makes testing the interferometer easier and allows to offset the measured value. The attenuator is necessary to control the reference wave amplitude to prevent saturation of the selective amplifier.
\newline

Internal function of both devices is very similar. A long cut is made in the wider side of the waveguide along the direction of propagation (the wave is not disturbed because no current runs there). A circular piece of some material is then slid into the waveguide. This piece is eccentrically mounted on an axis connected to the knob, so that turning the knob slides the material in and out of the waveguide.

The material used in case of the attenuator is a conductor with precisely chosen conductivity that attenuates the passing wave. The phase shifter uses a piece of dielectric that the wave is forced to pass through, which introduces the phase shift (and also some small attenuation as a byproduct).
\newline

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{faz_att.jpg}
\caption{Attenuator and phase shifter (reference wave path)}
\end{figure}

Proper function of the attenuator was briefly checked but no calibration of the scale was done. As for the phase shifter, in the first stage it was only tested that it does not significantly attenuate the signal. The gauge scale calibration was performed later, when the interferometer was operational -- see figure~\ref{fig_phaseshifter_cejch}. The phase shift is calculated relative to zero knob position. It should however be noted that the adjusting knob shows certain hysteresis, and the chart should therefore only be used as an approximate reference.

\begin{figure}[h]
\centering
\includegraphics[width=100mm]{fazovac_cejch.png}
\caption{Phase shifter gauge scale calibration (relative to zero position)\label{fig_phaseshifter_cejch}}
\end{figure}


\subsection{Magic tee with detection diode holder}
Magic tee is a relatively simple yet crucial part of the interferometer. Its task is to let the reference and diagnostic wave interfere so that the sum power can be measured, while it simultaneously ensures isolation of both lines. The schematic is shown in figure~\ref{fig_MTscheme}. A signal sent into terminal 2 is equally divided between 1 and 3 (both output are in phase) while nothing enters terminal 4. Likewise, a signal fed to terminal 4 is divided between 1 and 3 again, but both outputs are out of phase.

\begin{figure}[h]
\centering
\includegraphics[width=70mm]{MT_scheme.png}
\caption{Magic tee schematic\label{fig_MTscheme}}
\end{figure}

At GOLEM tokamak the reference and diagnostic waves are connected to terminals 2 and 4 (so they are isolated from each other). Their sum therefore emerges at 1 and 3. One of the terminals is ended by attenuation ferrocart block, the other is connected to the detection diode.

Both components use the same flanges as the attenuator and phase shifter. The detection diode holder can be easily opened to replace the diode and has a BNC connector that serves as an output. Because it is necessary not to electrically ground the tokamak through the (conductive) waveguide, there is a piece of plastic foil between the magic tee and detection diode holder and the connecting screws have non-conductive washers.

\begin{figure}[h]
\centering
\includegraphics[width=70mm]{MT.jpg}
\caption{Magic tee and diode holder}
\end{figure}

The detection diode holder can be detached from the magic tee and used as a makeshift microwave power detector (measure current through the diode by an ammeter). In case this ever happened, care must be taken to properly take care of the insulation plastic during reassembly in order not to ground the tokamak.
\newline

As for the diodes, several are ready to use at GOLEM. They are old Russian D-407 diodes for measuring in the 4 mm band (they look like the one showed in figure~\ref{fig_d404}, except that smaller waveguide is used). In case there is a suspicion a diode is faulty, {\bf{under no circumstances attempt to check the diode with regular diode meter}}. These point-contact diodes do not endure more that 500~mV voltage. Regular diode meters use more to open P-N junction on normal silicon diodes. Proper way to check function is to measure the I-V characteristics up to 500~mV and compare the extreme current values for forward and reverse bias. The ratio should be at least 1:100.

\subsection{Waveguide transitions}
The transitions were manufactured at CASTOR and are used to connect the E-band and Ka-band waveguides. There were more transitions available. Because the available waveguides differ in size a bit depending on where they were made, it is needed to check the dimensions before using a transition to avoid a mismatch.
\newline

All transitions were visually checked and concluded in usable state.


\subsection{Ka-band waveguides}
A wide variety of Ka band waveguides was available to use. These included E and H-bent 90$^{\circ}$ bends, 180$^{\circ}$ E-bent bends, few twists and many straight waveguides of different sizes. Due to different manufacturers from different sides of the Iron Curtain, their flanges and internal dimensions differ. It is therefore necessary to use custom transitions.

Some of the waveguides were in bad shape (damaged flanges, etc.), but most of them seemed ready to use. A conveniently long diagnostic line (about 10~m) was made for testing the interferometer.

\subsection{Tokamak antennas}
The antennas are mounted on large steel vacuum flange that can be attached to GOLEM vertical ports. There are three antennas in each of the two assemblies. Only one pair will be used at a time. The antennas are mounted via vacuum-tight metal bellows and their tilt can be adjusted by three small screws. The waveguide flange is similar to UG-381/U, except it has metric threads. The waveguide immediately transitions to circular and includes a vacuum seal. As mentioned in section~\ref{sec_plasmabehaviour}, the electric field of the incoming wave must be parallel to main toroidal magnetic field -- care must be taken when the flange is connected to the tokamak (the wave electric field is parallel to the shorter side of the waveguide, see section~\ref{sec_waveguides}).
\newline

A lot of microwave power is lost when passing through the tokamak vessel. As much as 99~\% can (and probably will) be lost -- anyone looking for possible microwave power losses should bear that in mind.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{antennas.jpg}
\caption{Tokamak vacuum flange and antennas}
\end{figure}

Before the interferometer was installed, the flanges were mounted on the tokamak vessel and left there for several weeks to check it is vacuum tight. No significant leak was observed.


\section{2011 reinstallation attempt\label{sec_2011}}
An attempt to install the interferometer at GOLEM tokamak has already been made in 2011 by a group of students consisting of O. Grover, T. Odstrcil and M. Odstrcil. Although they eventually did not make the interferometer reliably operational, a lot of useful work has been done, which the group deserves a lot of credit for. Let us briefly describe it to understand some of the problems already found.

\begin{itemize}
\item They recognised that a microwave generator that had been in use before is faulty and replaced it with a backup\footnote{The one described above}.

\item The interferometer circuit was initially operational, but failed during the tests.

\item To replace the interferometer circuit, an alternative way of evaluating the phase shift was devised. The idea was to digitally sample the sawtooth and the signal at the detecting diode, and calculate their mutual phase shift by a computer script. This script was written and used for further tests.

\item The group noticed issues with the directional coupler and tried to fix them by opening, cleaning and soldering it back together for a few times. Although it helped for some period of time, the issues always reappeared. A possible reason was mechanical damage caused by inadequate protection. During one of these repairs, the ferrocart block to prevent reflections has failed.
\end{itemize}

The interferometer occasionally measured density (see e.g. shots \#11750 or \#12499 in the GOLEM shot database for illustration), but given its tendency to periodically stop working the reliability of the measured value is doubtful. It is also worth mentioning that the algorithm used to calculate density was incorrectly calibrated and average density value was coming 8.5-times higher than it should have. The topic was later abandoned due to vacuum issues that appeared at GOLEM. Many diagnostics were disconnected during looking for the leak, including the interferometer. Although it later turned out that it most likely was not the cause of the problem, it has not been reconnected to the vessel since.
\newline

To conclude, the directional coupler was most likely the key source of the problems, and should have been replaced by a new one when repairs proved ineffective. It is also worth mentioning that one of the faulty microwave parts (broken 90$^{\circ}$ bend) was most likely used during the previous installation attempt and could also have contributed to the failure.


\section{Table-top function check}
As mentioned above, several major issues with the interferometer hardware were found. Namely:

\begin{itemize}
\item Faulty 90$^{\circ}$ bend in the diagnostic line
\item Broken capacitor lead in sawtooth generator circuit
\item Directional coupler not working
\item Interferometer circuit inoperative
\end{itemize}

The first three have been resolved, as described earlier in respective sections. It is therefore possible to check whether the interferometer works. The interferometer was therefore assembled as shown in figures~\ref{fig_interferometerscheme} and~\ref{fig_microwavesscheme} with about 10~m long dispersion line. The interferometer circuit was obviously left out and the two signals were examined by an oscilloscope. The sawtooth frequency was set to 522~kHz.
\newline

\begin{figure}
\centering
\includegraphics[width=130mm]{first_test.png}
\caption{Interferometer test\label{fig_firsttest}}
\end{figure}


The result is shown in figure~\ref{fig_firsttest}. The amplified signal on the detection diode can be clearly seen (after manipulating the sawtooth amplitude and using the attenuator to avoid amplifier saturation). Before the last flanges were connected, an attempt was made to change dispersion line length by manually moving the open waveguides. The sine wave was shifting exactly as expected. It was concluded that the device is functional, except for the phase-evaluation circuit.
\newline

In order to prevent any mechanical damage to the assembled interferometer, everything was positioned on suitably large piece of plywood and the important parts were firmly attached by custom-made plastic blocks (see figure~\ref{fig_plywood}). Special thanks belong to ASCR technician Mr.~Petr M\"{u}ller who did the job.

\begin{figure}
\centering
\includegraphics[width=130mm]{plywood.jpg}
\caption{Assembled interferometer board\label{fig_plywood}}
\end{figure}

The table-top experiments were closed as successful and it was decided that the interferometer is therefore ready to be transported to GOLEM.

\section{GOLEM installation}
The interferometer was moved to GOLEM, vacuum flanges with antennas were mounted on the tokamak vessel and the plywood board with the crutial microwave parts was installed on the top shelf in far left corner of the tokamak room. The sawtooth generator, selective amplifier and Gunn oscillator power supply was positioned on the left side of the same shelf and connected to power supply switched by tokamak relays. This allows to turn the device on and off automatically, without the need to actually manipulate the switches. There was some unused space on the right side of the shelf that accommodated four-channel Tektronix DPO3014 oscilloscope to monitor or save the interferometer output. Figure~\ref{fig_shelf} shows the final setup.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{shelf.jpg}
\caption{Installed interferometer\label{fig_shelf}}
\end{figure}

\begin{figure}[h]
\centering
\includegraphics[width=100mm]{dispersion_line.jpg}
\caption{Waveguides to the tokamak\label{fig_dispersionline}}
\end{figure}

The next step was to connect the device to the tokamak by long dispersion line. The position of the top shelf is convenient, since it allows the waveguides to run horizontally along the wall, while they are supported by mounting bolts of the main electrical housing. One of the waveguides is intentionally made longer by running the distance twice (two 180$^{\circ}$ bends are used). When they reach far enough, one of the waveguides turns and runs toward the top tokamak flange. The other waveguide turns downward and runs vertically along the wall, before it turns toward the bottom flange. This solution ensures the interferometer waveguides do not occupy too much space and should not get in the way. The situation is shown in figure~\ref{fig_dispersionline}. The total length of the diagnostic line is about 12~m. 

Because the waveguides were not ordered specifically for this configuration, finding this solution required certain creativity. The whole task was complicated by differences in flanges that prevented some of the waveguides to be connected, lowering possible number of combinations. The configuration described above could eventually be reached by introducing two waveguide twists and a couple of short waveguides. They do not have any special purpose, they were only used to cut the distance because no straight waveguide had the right length.
\newline

Before the last connection was closed, the function was evaluated by moving the opened waveguides. The outcome was exactly the same as with the table-top configuration, the two signals were shifting relative to each other (as seen in figure~\ref{fig_firsttest}). The signal therefore passes through the whole line and the tokamak and still ends up strong enough for the interferometer to work. 


\section{Calibration\label{sec_calibration}}
With the interferometer in final configuration, it is now necessary to properly calibrate it. The calibration consists of several easy steps. See section~\ref{sec_phasemodullatinginterferometer} again to understand them. The trick is to maximize the amplitude at the amplifier output. Properly calibrated interferometer should produce a signal similar to that shown in figure~\ref{fig_firsttest}.

\begin{enumerate}
\item Display the sawtooth and selective amplifier output on an oscilloscope
\item Adjust the sawtooth generator frequency until the amplifier output reaches maximum amplitude

This ensures that the sawtooth has the same frequency as the center frequency of the selective amplifier. It should therefore happen at 522~kHz.
\item Set the sawtooth amplitude to minimum and gradually increase it, until the amplifier output reaches maximum amplitude. 

This step ensures that the beats on the diode have the same frequency as the sawtooth, because the modulation results in phase shift of exactly $2\pi$.
\item Adjust the attenuator in the reference line so that the amplifier is close to saturation (but not saturated)
\end{enumerate}


\underline{Important points:}
\begin{itemize}
\item If the amplifier saturates at any point, it is necessary to adjust the attenuator to prevent it before continuing the process.

\item If no attenuator adjustment saturates the amplifier output, it is possible (and desirable) to adjust amplifier gain. Should this need arise, it is also a signal to look for power losses in the system.

\item The signal at the output of the amplifier will always have about 522~kHz which will not change, it is not a sign of a malfunction. Resonant circuits in the amplifier do not allow the actual frequency of the signal on the detector get through.

\item If a different sawtooth generator is used, attention must be paid not to exceed maximum varactor voltage during adjustments.
\end{itemize}
\vspace{5mm}


Let us try to estimate sawtooth amplitude after the calibration (step 3). By combining equations~\ref{eqn_tpulses} and~\ref{eqn_deltaf} and setting $t_{pulses}=\left(f_{ST}\right)^{-1}$, the generator frequency sweep should be set to $\Delta f=\frac{c}{\Delta L}$. For a diagnostic line measuring 12~m, one gets $\Delta f$=25~MHz. Providing the Ukrainian generator described in section~\ref{sec_microwavegenerator} is used, the sawtooth amplitude should be about 1.25~V. The actual sawtooth amplitude set by above-described calibration is around 1.3~V, which means that everything adds up quite well.












\chapter{Density evaluation -- digital\label{chap_digital}}

Because the old analog interferometer circuit is out of order, another way to evaluate interferometer output has to be developed. As described in previous chapters, the task is to measure mutual phase shift of two signals -- the sine signal at the output of the selective amplifier and reference pulses from the sawtooth generator (or the sawtooth itself). Because all data at GOLEM are processed by computer, an obvious solution is to sample the two signals and evaluate their phase shift by a computer script.


\section{Fourier transform algorithm\label{sec_fourier}}
As mentioned in section~\ref{sec_2011}, such algorithm was developed in 2011. The sawtooth and sine signal are sampled and base carrier frequency is determined as maximum frequency in the spectrum, which is calculated by Fourier transform of the sine signal. Complex exponential with this frequency is obtained by inverse Fourier transform after all other frequencies are eliminated. In the next step, the signals are multiplied by this exponential and their phase is evaluated as an argument of the resulting complex number (after it is smoothed by convolution with gaussian window function). Discontinuities in the phase are removed by applying numpy.unwrap function and mutual phase shift of the signals is then calculated by subtracting both phase data series.

The algorithm is thus able to work with both ascending and descending sawtooth generator (resulting phase shift is automatically inverted if needed). The output signal is downsampled to sampling period of 15~$\mu$s.
\newline

During this algorithm testing it at first showed densities much higher than was anticipated. However, eventually a mistake in the algorithm was discovered (minor plasma radius needed to calculate average density was incorrectly set). After setting the correct value, the measured density was believable. This correction took place just before shot number \#18893.



\section{New algorithm development}
Because the algorithm just described sometimes gave incorrect results (wrong removing of fringes, etc.), a decision was made to develop completely different algorithm based on completely different grounds, hoping that it will prove more reliable. The single steps of the algorithm will be described in details in following sections.

It was decided to sample the sawtooth instead of the reference pulses. Data acquired during shot \#18685 are shown in figure~\ref{fig_18685} for illustration. The sampling rate was 25~MS/s. Amplitude variations on the sine signal can be seen, because the sample shown is taken during plasma discharge. The phase shift of the two signals is however almost constant because the sample shown is too short (simply put, plasma density usually does not change this fast). The overall shot length at GOLEM is on the order of 10~ms, meaning that several thousands sawtooth periods elapse during plasma existence.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{18685.png}
\caption{Shot \#18685 -- raw data sample (25 MS/s)\label{fig_18685}}
\end{figure}

\section{Additional requirements and basic algorithm principle}
There are several requirements that the finished algorithm should be able to fullfil. 
\begin{itemize}
\item Any 2$\pi$ fringes in the output density profile have to be removed

As mentioned earlier, mean plasma density increase of about $3\cdot 10^{18}$ m$^{-3}$ results in phase shift of $2\pi$. Because the expected density at GOLEM is higher, shifts of more than $2\pi$ are anticipated (not to mention possible non-zero initial phase shift). The algorithm therefore has to be able to add or subtract correct whole-number multiple of 2$\pi$ where appropriate to get continuous density data.

\item Stability when the signal is momentarily lost

It is possible that during some shots the microwave signal will be briefly lost. The algorithm should be able to recognize that it happened and reconstruct as much data as possible. This is closely related to previously mentioned fringe issues. When the signal is lost when the phase shift transitions across zero, problems with fringe counting may occur.

\item Ability to work with different sawtooth generator (ascending ramp)

Because the old CASTOR generator may stop working at some point, the algorithm should be able to process a signal from different function generators. It therefore should not assume descending ramp or any other waveform parameter.
\end{itemize}
\vspace{5mm}

The algorithm should therefore process the data in several steps:
\begin{enumerate}
\item Input data preparation
\item Finding reference marks on both signals
\item Comparing the two series of reference marks to get mutual phase shift
\item Removing fringes in output data and dealing with empty spaces
\item Smoothing the output data to remove noise
\end{enumerate}

\section{Input data preparation}
Input data are loaded as three equally sized arrays (one for time, one for each signal). Before actual calculation begins, input data are slightly adjusted. As seen in figure~\ref{fig_18685}, the oscilloscope set to higher sampling rate rounds off time values, meaning that several samples have the same value. The time scale is therefore linearly resampled so that the values are equidistant, while the number of samples and the first and the last value are unchanged. This step, while not absolutely necessary, makes the calculations more precise.
\newline

In the second step the mean of both data series is calculated and subtracted from them, which is effectively equivalent to AC oscilloscope coupling. Next, at the beginning of the algorithm, variable OldGen is manually set to either $-$1 or 1. This variable specifies whether the sawtooth generator produces ascending or descending ramp (respectively). After removing its offset, the sawtooth signal is multiplied by OldGen. This ensures that the resulting sawtooth is always descending and the algorithm can assume it from this moment on. Figure~\ref{fig_18685prepared} shows data after initial adjustments.

\begin{figure}
\centering
\includegraphics[width=130mm]{18685_prepared.png}
\caption{Data after time and offset adjustment\label{fig_18685prepared}}
\end{figure}


\section{Finding reference marks}
After the input data have been prepared, both series are run through one element after another and reference marks are created. This is by far the most time-consuming step of the algorithm -- after both sets of reference marks are created, the amount of data that has to be processed significantly decreases.

\subsubsection{Sine signal}
A simple zero crossing detection is used to find marks for the sine signal. In order to avoid false triggers by noise, two additional conditions are added. The reference mark is created when:
\begin{itemize}
\item Previous value was negative, current value is non-negative
\item A value closest to 500~ns ago is negative
\item Last identified mark was at least 1500~ns ago
\end{itemize}

When all three conditions are met, the reference mark is created by linearly interpolating previous and current value and finding intersection with zero. As simple as this solution may sound, it proved sufficiently reliable.

\subsubsection{Sawtooth signal}
The conditions are almost the same as in the case of sine signal, except that positive to negative crossing is detected (sawtooth is descending) and the lookback period from the second condition is 700~ns. Two point linear interpolation however does not suffice to provide reliable reference mark. Instead, all data points closer than 700~ns to the detected crossing are linearly fitted, and the resulting line zero intersection is used to get the reference mark.
\newline

Fitting is done by least squares method. Fitting N data points $[x_i,y_i]$ by linear function $y=ax+b$ is equal to minimizing function
\begin{equation*}
d(a,b)=\sum_{i=1}^N \left(ax_i+b-y_i\right)^2
\end{equation*}

By calculating partial derivatives and setting them to zero one obtains system of two linear equations. Solving the system yields expressions for a,b (all summations are from 1 to N):
\begin{align*}
&a=\frac{N\sum x_iy_i-\sum x_i\sum y_i}{N\sum x_i^2-\left(\sum x_i\right)^2} \\
\\
&b=\frac{\sum y_i-a\sum x_i}{N}
\end{align*}

Both sets of reference marks are shown in figure~\ref{fig_18685fitted}, as well as one of the sawtooth fitting line. It is worth mentioning that by setting the lookback period to fixed values the algorithm assumes that the signal frequency is not far from 500~kHz. However, because the frequency is given by selective amplifier and thus effectively fixed, it is not a relevant disadvantage. After this step is complete, it is straightforward to calculate the sawtooth generator frequency from the number of found reference marks.

\begin{figure}
\centering
\includegraphics[width=130mm]{18685_fitted.png}
\caption{Finding reference marks for both signals\label{fig_18685fitted}}
\end{figure}


\section{Calculating phase shift}
Because both signals are already processed and the reference marks series are created, much less data has to be processed during this step. The procedure is very simple. Signal reference marks are processed one by one and the closest following mark of the sawtooth is found. Because the frequency is already calculated, the time difference can be converted to phase shift. The calculated value is only accepted if it is less than 2$\pi$ (to prevent miscalculations in case a point is missing for whatever reason).
\newline

The output of the algorithm at this point is shown in figure~\ref{fig_18685phaseshift}. As expected, there is a fringe in the output data due to high average density. Notice that the initial phase shift is non-zero, which makes the fringe to appear even sooner than the fringe density is reached. Although it is possible to use the phase shifter to make the initial phase shift as low as possible, the setting is not precise and reliable. Reaching fringe density therefore is not necessary to see a fringe -- it will actually appear sooner, depending on initial phase shift of the two signals.

\begin{figure}
\centering
\includegraphics[width=130mm]{18685_phaseshift.png}
\caption{Calculated phase shift during the \#18685 shot (before and after removing fringes, the latter connected with lines)\label{fig_18685phaseshift}}
\end{figure}

\section{Removing fringes}
Fringes in the data calculated data must now be removed. At the same time it is checked whether the data are fine and not damaged by a signal loss or failures during previous steps of the algorithm (namely reference marks finding). In order to do this, two sensitivity defining variables are introduced:

\begin{itemize}
\item time\textunderscore lim -- two consecutive data points can only be at most time\textunderscore lim seconds apart

\item lim -- the phase difference between two consecutive data points can be at most lim radians
\end{itemize}

The calculated data are walked through point after another and whenever a discontinuity is found, a multiple of 2$\pi$ is added to all following points until a discontinuity in the other direction. Failure to meet either of the conditions above is consider as a signal to stop.

The algorithm therefore either processes all data or stops somewhere in the middle. If the latter happens, the algorithm makes an attempt to reconstruct the phase shift from the end backwards and work its way as close to the problem encountered during the forward run. This results in two possible outcomes. Either the whole phase development is reconstructed, or another problem is encountered and some part of the data is not reached from either side. Should the second possibility happen, the affected part of the data is simply removed so that incorrect reconstruction is not risked. The result of fringe removal on the \#18685 shot data is shown in figure~\ref{fig_18685phaseshift}.
\newline

What remains a subject for experiment is optimal setting of the two sensitivity variables. The combination lim=$\frac{\pi}{2}$, time\textunderscore lim=10E-6 showed satisfactory results (and were introduced in the final version) but there is a possibility to find a better combination. These values set the algorithm between two extremes -- either the algorithm reconstructs everything with a higher probability of failure, or almost no mistakes are made at the cost of often giving the reconstruction up prematurely (resulting in a gap during the shot).
\newline

\begin{figure}
\centering
\includegraphics[width=130mm]{19017.png}
\caption{Influence of different setting of lim variable (time\textunderscore lim=10E-6) for shot \#19017 (signal problem)\label{fig_19017}}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=130mm]{19017_signal.png}
\caption{Sine signal issue during shot \#19017 with reference marks created earlier\label{fig_19017signal}}
\end{figure}

Influence of different setting of these variables is illustrated in figure~\ref{fig_19017} on shot \#19017 during which there was a problem with sine signal -- as seen in figure~\ref{fig_19017signal}. Too high lim value makes the algorithm fail. Lowering lim variable enables the algorithm to recognize and eliminate the problem. On the other hand, lowering it too much results in too early give up.


\section{Smoothing the output\label{sec_smoothingoutput}}
Now when the phase shift was evaluated and discontinuities removed, all that remains is to smooth the output so it is not too noisy. This is achieved by simple fourth-order Butterworth digital low-pass filter. Its cutoff frequency determines level of smoothing. Optimal setting proved to be between 10 and 20~kHz. Middle value of 15~kHz has been chosen for final version and can be altered at the beginning of the code.
\newline

The very last thing that needs to be done is to remove initial offset and convert the phase shift to average density in m$^{-3}$. This is achieved by multiplying the value by $\frac{3.11\cdot 10^{18}}{2\cdot \pi}$ (see section~\ref{sec_specificissues} for details). Next, all values are multiplied by OldGen variable (plus or minus one). The phase shift changes sign providing an ascending ramp is used to sweep the generator, so it is necessary to compensate (the issue was described in section~\ref{sec_phaseshiftsign}). The signal is eventually downsampled to sampling period around 10~$\mu$s so that disc space is saved. Figure~\ref{fig_18685final} shows final output for 10 and 20~kHz low-pass filter cutoff frequencies, as well as the raw output (with offset removed).

\begin{figure}[h]
\centering
\includegraphics[width=125mm]{18685_final.png}
\caption{Low-pass filter cutoff frequency influence\label{fig_18685final}}
\end{figure}


\section{Comparison of both algorithms}
Figure~\ref{fig_18685algcomparison} shows data acquired during shot \#18685 after they have been processed by both algorithm (the Fourier transform algorithm and the new algorithm described in previous sections). The algorithms give almost identical results\footnote{The incorrect calibration of the Fourier transform algorithm mentioned in section~\ref{sec_fourier} was compensated.}. It is a strong sign that both methods work correctly. It was decided to let them work simultaneously so that their reliability can later be assessed. This will be shown in chapter~\ref{chap_evaluation}.

\begin{figure}[h]
\centering
\includegraphics[width=125mm]{18685_algcomparison.png}
\caption{Shot \#18685 density reconstructed by both algorithms\label{fig_18685algcomparison}}
\end{figure}









\chapter{Density evaluation -- analog\label{chap_analog}}
While the digital density evaluation described in previous chapter works well, there is a disadvantage with this method. It is necessary to sample two channels at once and in order for the algorithms to work reliably, they have to be sampled at sampling rate of 1~MS/s as a minimum. Although this can be quite easily achieved, fast sampling data acquisition systems are very valuable at GOLEM and effort should be put into using as little as needed in order to save equipment for other use. A closely related issue is higher demand for hard drive space to save data from the two channels (they could in principle be deleted after density is calculated, but it is better to keep raw measured data). Another disadvantage is that the algorithms need some time to finish (this is a minor disadvantage though, since both algorithms are very fast and do not waste much time).

A decision was made to get rid of these issues by designing an electronic circuit to evaluate phase shift. This way there is no need to sample the two signals and save them. Instead, only one channel at arbitrarily low sampling rate could be used to sample density data. 
\newline

This chapter describes how the analog circuit works and follows with detailed description of its elements.

\section{Basic principle and schematics}
Block scheme of the circuit is shown in figure~\ref{fig_phasedetectorblockscheme}. Sine signal from the selective amplifier is further amplified to level high enough to be recognized by logic circuits. The reference pulses from the sawtooth generator should have sufficient voltage already. Both signals are then fed to 8:1 divider, which produces two square waves of the same frequency. These are further converted to short inverted pulses, that further enter SR latch. One signal switches its output high, the other resets to low. A rectangular signal therefore emerges at the SR latch output, while its duty cycle is proportional to the mutual phase shift of the two signals. This pulse-width modulated signal is converted to DC voltage by a simple low-pass filter.
\newline

\begin{figure}
\centering
\includegraphics[width=130mm]{phasedetectorblockscheme.png}
\caption{New phase detector circuit block scheme\label{fig_phasedetectorblockscheme}}
\end{figure}


The purpose of the 8:1 dividers is to get rid of fringes in the output voltage. As already stated, plasma density is high enough to result in phase shift of more than 2$\pi$. Dividing the frequency by eight reduces the fringe count by the same factor. In case the initial voltage at the output is not too high, no fringe will occur during plasma discharge. A simple zeroing circuit is therefore introduced that monitors the output and ensures that the average value is close to zero by resetting one of the dividers.
\newline

The full schematic is seen in figure~\ref{fig_myinterfscheme} (including component list). It will be broken down into several blocks to be described separately in following sections. The circuit operates from symmetric dual supply $\pm$6~V.

\begin{sidewaysfigure}
\centering
\includegraphics[width=215mm]{myinterfscheme.png}

\vspace{7mm}

\begin{tabular}{|ll|ll|ll|}
\hline
R$_1$ & 10k & R$_{16}$ & 22k & C$_9$ & 4.7~$\upmu$F \\ \hline
R$_2$ & 820 & R$_{17}$ & 1M & C$_{10}$,C$_{11}$ & 4n7 \\ \hline
R$_3$ & 68k & R$_{18}$ & 330 & C$_{12}$ & 22~$\upmu$F \\ \hline
R$_4$ & 3k3 & R$_{19}$,R$_{20}$ & 6k8 & P$_1$ & 2k5 \\ \hline
R$_5$ & 1k & R$_{21}$ & 68k & P$_2$,P$_3$ & 100k  \\ \hline
R$_6$,R$_7$ & 27k & C$_1$ & 2n2 & T$_1$ & BC547  \\ \hline
R$_8$ & 1k & C$_2$,C$_3$,C$_4$ & 100n & ZD$1$,ZD$_2$ & 5V6 \\ \hline
R$_9$,R$_{10}$ & 68k & C$_5$ & 2n2 & inverters & 4049 \\ \hline
R$_{11}$ & 22k & C$_6$,C$_7$ & 330p & & \\ \hline
R$_{12}$,R$_{13}$,R$_{14}$,R$_{15}$, & 100k & C$_8$ & 22~$\upmu$F & & \\ \hline
\end{tabular}

\vspace{7mm}
\caption{New phase detector -- full schematic\label{fig_myinterfscheme}}
\end{sidewaysfigure}

\section{Input signal amplifier}
The sine signal at the output of the selective amplifier has at best 2~Vpp, while the value can get considerably lower during plasma discharge (values as low as 50~mVpp have been observed). This is clearly not enough to work with logic circuits and the signal must be amplified. Operational amplifier LM318 was chosen for the task because of its considerably high slew rate capabilities (signal frequency is around 500~kHz and required output amplitude is several volts, which means a slew rate at least around 20~V/$\mu$s is necessary). It is wired as an inverting amplifier. A feed-forward compensation circuit (from the datasheet) is used to maximize bandwidth and slew rate. Because the operational amplifier has strong tendency to oscillate, both power supply terminals are bypassed by 100~nF capacitors. The variable resistor P$_1$ can be used to compensate offset input voltage, but it is not needed in this application.
\newline

To make the circuit as sensitive to small signals as possible, the output of the amplifier is AC-coupled to variable DC from 0--6~V voltage divider formed by P$_2$. This introduces DC offset that can set the output signal close to logic circuit trip value. For CMOS4520 divider supplied from $6~V$ power source this value is around 4~V. The easiest way to adjust the trimmer is to connect very small input signal (\~10~mVpp), set the trimmer to minimum and connect an oscilloscope probe to 4520 output (pin~5). By slowly increasing the DC offset the signal appears at one point and disappears at another. Optimal DC offset is in the middle between the two values. To ensure the voltage stays in permitted limits for 4520, a 5V6 Zener diode is used as a limiter.
\newline

The reference pulses from the sawtooth generator do not need to be amplified and after passing through a 5V6 Zener limiter are fed directly to logical circuits.


\section{8:1 dividers and pulse shaping}
In this stage, both signals need to be divided by 8 (reason above) and converted to short pulses. CMOS4520 dual binary counter is used for the division, resulting in square waveforms at the output. The circuit has two separate ENABLE inputs that allow to inhibit either of the dividers. The sine signal counter is always active, the reference pulses counter ENABLE pin is controlled by zeroing circuit that will be described later.
\newline

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{signal.png}
\caption{Input sine signal, division by 8 and the resulting short pulses\label{fig_signal}}
\end{figure}

Two inverters (CMOS circuit 4049) along with two NAND-gates (74HC00) are used to turn the signals into short pulses by utilizing the inverter propagation delay. Both square waveforms are treated the same way -- they are inverted by an inverter and both original and inverted signals are fed to one NAND-gate inputs. The output should therefore always be high, however, because the inverted signal has certain delay with respect to the original, both inputs are simultaneously high for a brief period of time, producing inverted pulses. To increase this period, capacitors C$_6$ and C$_7$ are tied to the inverters' outputs to make the propagation delay longer. The process for the sine signal is shown in figure~\ref{fig_signal} (amplified signal before division not shown).


\section{SR latch}
Now when both signals are converted to short inverted pulses, they can be finally combined to evaluate phase shift. This is done by a simple SR latch formed by two NAND gates (the other two gates in 74HC00 used in previous stage). One signal sets the SR latch high, the other resets -- resulting in rectangular waveform at the same frequency as the pulses had (original frequency divided by 8, around 65~kHz). \emph{The duty cycle of this waveform is therefore proportional to mutual phase shift of the two signals} (shown in figure~\ref{fig_pwm}).
\newline

The two outputs are connected to a two pole switch that enables to switch them for the next circuitry. The reason is simple. The device should work with both ascending and descending ramp generator. However, using one or the other means that the phase shift changes sign -- the issue was described in section~\ref{sec_phaseshiftsign} and was already encountered in section~\ref{sec_smoothingoutput} during digital evaluation. Switching the signals when needed fixes the problem.


\section{Output filter\label{sec_outputfilter}}
The PWM (pulse-width modulated) signal now has to be converted to analog DC value. A very naive passive low-pass filter (formed by R$_{19}$,R$_{20}$,C$_{10}$ and C$_{11}$) is used. Its cut-off frequency was established by experiment, optimal performance was achieved by 4.7~nF capacitors and 6.8k resistors. Like in the digital case, the value is a trade-off between not removing the 66~kHz ripple completely and not getting correct results when density changes quickly. See figure~\ref{fig_pwm} for illustration -- both the sine signal and reference signal is shown after it was divided by 8 as well as the PWM output of the SR latch and its low-pass filtered value.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{pwm.png}
\caption{Both signals after division, resulting PWM signal and its mean produced by low-pass filter\label{fig_pwm}}
\end{figure}

Eventually the signal passes through a passive high-pass filter with very low cut-off frequency (about 0.1~Hz) to remove any DC offset so that the output is exactly zero at the beginning of the shot.
\newline

It is worth mentioning that using several passive filters in succession attenuates the signal. This too can be seen in figure~\ref{fig_pwm}. A 10~\% duty cycle of the PWM signal with an amplitude of 6~V does not produce $0.1\cdot 6$~V$=0.6$~V at the output, but only about $0.5$~V. The consecutive high-pass filter will too have influence. This is important for calibrating the device and it will be dealt with later.

\subsubsection{Possible improvement}
In case the filter output proves unsatisfactory, it is possible to improve it by either building better filler (e.g. a Sallen-Key) or use some IC low-pass filter (e.g. LTC1569). The latter solution might even make it possible to have variable cut-off frequency. In case someone decided to try it, it is possible to sample the PWM signal before it is filtered and simulate different filters digitally before actually making them.

\section{Zero-setting circuit}
\subsection*{Principle}
As mentioned above, after both signals are divided by 8 there is no guarantee of their mutual phase shift. This poses a problem because in case the initial phase shift is close to 2$\pi$, a fringe would appear during the shot (getting rid of fringes was the reason to introduce dividers in the first place). It is therefore needed to ensure that the initial phase shift of the two signals is small and the initial PWM duty cycle therefore close to 0~\% (and the initial output value in turn close to zero volts). Although it is not possible to control the phase shift of the input signals (which is to be measured), it is possible to ensure that the \emph{divided} waveforms' phase shift is small (i.e., less than $\frac{1}{8}\cdot 2\pi$ -- the first eighth of the interval corresponds to the unknown phase shift of the original high frequency signals).
\newline

While it is in principle possible to send a trigger pulse before plasma discharge to reset both dividers, this approach presents several issues. Most importantly, it is not possible to synchronize the trigger pulse with continuously coming pulses at the input and the two can overlap, rendering the resetting unreliable due to race condition. Secondly, adding another trigger line is potential source of malfunction (the cables are often manipulated with at GOLEM tokamak). To eliminate both issue, a feedback method that ensures fully automatic reset was therefore implemented.

Its basic principle is simple. The circuit is connected to the second (negated) output of the SR latch and monitors the mean value. In case this mean value is too low (and the first, measuring output therefore too high), the reference wave 8:1 divider is temporarily turned off by its ENABLE input. This means the circuit effectively misses a number of pulses. When the divider is enabled again, the phase shift of the divided signals changes. This process repeats until the negated SR latch output is high enough (the threshold can be adjusted).

\subsection*{Description}
The signal at the SR latch output passes through a low-pass filter formed by R$_9$ and C$_8$ and is compared by LM393 comparator with the threshold value set by voltage divider $P_3$.  Because the LM393 is not rail-to-rail device, the signal is first divided by R$_{10}$ so that it never exceeds 3~V (the comparator would not work had the input got too close to positive supply rail). In case the output is lower than the threshold, transistor T$_1$ closes (R$_{11}$ is a pull-up resistor, the LM393 has open-collector output). Closing transistor T$_1$ enables a relaxation oscillator formed by the other comparator in LM393 that starts to produce rectangular waveform at about 0.17~Hz (6~second period). This waveform is connected to the ENABLE input of 4520 divider for reference signal (it is first inverted by a spare 4049 inverter to ensure that when the oscillator is off, the divider is enabled).\footnote{More precisely, the frequency and duty cycle depend on setting of the switch that interchanges SR outputs. The time when the divider is enabled is however always 3~s.}  

This means that when the output value is undesirable, the oscillator is running and the divider is periodically switched on and off. A number of reference pulses is thus missed and when the divider is enabled again, one of eight possible phase shifts is reached. In case it is still not satisfactory, the cycle repeats until it is. At that point T$_1$ opens, the oscillator is disabled and the divider stays enabled. The device is thus ready for plasma discharge.

\subsection*{Timing and adjustment}
Although the basic principle of the zero-setting circuit is simple there is a possible pitfall. The circuit must not be allowed to try to reset the output during the plasma discharge. This would make the device worthless. To ensure that, it is necessary to properly set the cut-off frequency of the low-pass filter at the SR latch output, so that it is low enough that the circuit cannot react to fast changes. On the other hand, the circuit must settle during one half of the resetting relaxation oscillator period, so that the moment when satisfactory phase shift was achieved is properly recognized.
\newline

While resetting during discharge cannot be avoided in~100~\% cases, it is desirable to set the low-pass filter frequency so low that it just settles (let us say to 98~\%) to correct value during one half of the resetting oscillator period (i.e. during 3~s). Because this time is much longer than the 66~kHz PWM period, ripple can be ignored and only step response of the filter can be studied.

The filter is formed by R$_9$,R$_{10}$ and C$_8$. Let us first calculate how the additional resistor influences the response (assuming both resistors have the same value). The problem we are facing is then as follows:

\begin{figure}[h]
\centering
\includegraphics[width=40mm]{lowpass.png}
\end{figure}

Let us now assume that at t=0 voltage U appeared at the input. Current through the series resistor equals the sum of currents through the other resistor and the capacitor:
\[\frac{U-u(t)}{R}=\frac{u(t)}{R}+C\frac{\textrm{d}u}{\textrm{d}t}(t)\]
This is a simple differential equation with a solution (assuming initial condition $u(0)=0$)
\[u(t)=\frac{U}{2}\left(1-e^{-\frac{t}{\frac{RC}{2}}}\right)\]

The requirement was settling to 98~\% in 3~s. Simple calculation then shows that $RC\approx 1.53$ s. Values of 68~kOhm and 4.7~$\upmu$F were chosen (RC then equals 1.496).

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{zerosetting.png}
\caption{Automatic zero-setting process (description in the text)\label{fig_zerosetting}}
\end{figure}

The whole action of the zero-setting circuit can be seen in figure~\ref{fig_zerosetting}. The green line shows the resetting relaxation oscillator pulses after they have been inverted (high value -- divider is enabled). The other two channels show both outputs of the SR latch after low-pass filtering. The violet line is the measurement output. As can be seen, it reacts almost immediately to any changes (the slow moves are given by the high-pass filter stage). This is the output that needs to be set close to zero. The blue line is the other SR output after filtering. It is a negation of the first output, except the low-pass filter has lower cut-off frequency. That is why the reaction is much slower (preventing resetting during plasma discharge). The value however settles before the divider is switched off again, so that the process can be stopped when the threshold is crossed. When that happens, the divider is therefore left enabled. The violet output line is then close to zero, which was the goal in the first place. Note that when the divider is disabled, the blue output goes to maximum, which means that the threshold is always reached during the disabled stage. When it happens, the comparator reacts and enables the divider again (that is why the green waveform is not symmetric)\footnote{Had the outputs been interchanged by the switch, the blue line would go to zero when the divider is enabled and the green waveform would be symmetric.}.
\newline

Last thing that needs to be addressed is setting the threshold for resetting. The PWM duty cycle ranges from 0 to 100~\%, which equals a phase shift of $16\pi$ of the input high frequency signals. To make sure that the resetting circuit will always have a stable state regardless of the phase shift of the input signals, the threshold PWM must be at least 12.5~\%. Setting it precisely is not possible, so some safety margin must be added. A value of 20~\% is reasonable. That setting means that the resetting circuit will not necessarily settle at the lowest possible value, but that is insignificant.

Setting the threshold can be easily done as follows:
\begin{itemize}
\item Connect an oscilloscope probe to the density measuring output, but before the output filter (output of the SR latch)
\item Turn the P$_3$ trimmer to set the threshold so that any value is accepted
\item By short disconnection of one of the inputs get a PWM duty cycle close to 20~\% (each reconnection makes a change of a multiple of 12.5~\%)
\item Use the phase shifter in the reference path to set exactly 20~\% duty cycle
\item Slowly turn the trimmer until the circuit trips and starts resetting the counter
\end{itemize}

It is important to work with the PWM signal directly and not with the filtered one (the filters attenuate the signal, so calculations would be more difficult).
\newline

In the unlikely case that the resetting starts to occur during plasma discharge (density suddenly jumps to maximum and stays there until end of the shot), it is possible to get rid of the issue by rotating the phase shifter in the reference wave path a little bit in any direction\footnote{Due to variable attenuation of the phase shifter, it is then necessary to do the last step from the procedure described in section~\ref{sec_calibration} to compensate with the attenuator.}.

\section{Calibration}
In case the output value would represent directly the change of the PWM signal, calculating phase shift would be an easy task (6~V would represent a phase shift of $16\pi$ and therefore 8 times the fringe density (see section~\ref{sec_specificissues})). However, due to attenuation of the output filters this process would give too small value. A multiplicative constant to get correct value needs to be found.
\newline

Because the digital evaluation algorithms are already available, the easiest way to do it is to compare the result from the analog circuit to the one obtained digitally. Shot \#19513 was used for comparison because of a convenient plateau in the first half of the shot -- see figure~\ref{fig_19513}. The chart shows density reconstructed by the Fourier transform algorithm described in section~\ref{sec_fourier} and density obtained from the analog circuit multiplied by $5.15\cdot 10^{18}$. The value was chosen so that both series overlap at around 9.5~ms, when the density has been constant for a while.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{19513.png}
\caption{Calibration of the phase detector by comparing to Fourier transform algorithm\label{fig_19513}}
\end{figure}

After comparing the Fourier transform data and electronic circuit output multiplied by the constant just found for several other shots, it was concluded that the calibration for the circuit is

\vspace{7mm}

\[
\boxed{
1\,\textrm{V}\sim 5.15\cdot 10^{18}\,\textrm{m}^{-3}
}
\]









\chapter{Backup solutions}
Although the interferometer is now in operational state with several density evaluation methods at disposal, it still depends on the old sawtooth generator and more importantly, the selective amplifier from ASCR. The sawtooth generator can be substituted by commercially available instrument (though it is an expensive solution, given what the circuit does), but the selective amplifier malfunction would render the device inoperative until it is fixed. A decision was therefore made to try to make two more circuits to substitute the old devices. Both were constructed and mounted into one instrument box along with the phase detecting circuit described in previous chapter.

A brief description of backup microwave generator from QuinStar company is also given in this chapter.


\section{Backup sawtooth generator}
\subsection*{METEX MXG-9810}
A test was first made to sweep the frequency with METEX MXG-9810 function generator available at GOLEM. This generator allows to generate triangle wave with adjustable symmetry and can be set to produce a sawtooth waveform sharp enough for the interferometer. It is necessary to always monitor the waveform on an oscilloscope and not to exceed maximum varactor voltage. The amplitude knob can be pulled out to get very small signal amplitudes. See shot \#19427 in GOLEM shot database as an example.
\newline

The MXG-9810 generator can be easily used as a substitute of the old generator. However, using this expensive function generator for this one task could be considered as wasting valuable resources.


\subsection*{New sawtooth generator circuit}
A new sawtooth generator circuit was made to substitute the old one. It is not just its copy, totally different circuit has been developed instead. It is based on popular 555 integrated circuit (the CMOS version is able to comfortably work at 500~kHz). The schematic is shown in figure~\ref{fig_mysawtoothgenscheme}. Transistor $T_1$ is wired as constant current source for capacitor C$_3$, which therefore charges linearly (the speed and therefore frequency of oscillation is given by R$_1$ and trimmer P$_1$). When the voltage reaches two thirds of supply voltage, the internal comparator in the 555 circuit switches and rapidly discharges the capacitor. At the same time, output of the 555 briefly falls to zero (this is used as reference pulses output). When the capacitor discharges, 555 output switches to power supply voltage again and the cycle starts over.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{mysawtoothgenscheme.png}

\vspace{5mm}

\begin{tabular}{|ll|ll|ll|}
\hline
R$_1$ & 820 & C$_1$ & 1~$\upmu$F & P$_1$ & 250 \\ \hline
R$_2$ & 10k & C$_2$ & 100n & P$_2$ & 500 \\ \hline
R$_3$ & 22k & C$_3$ & 680p & P$_3$ &100  \\ \hline
R$_4$,R$_5$ & 1k & C$_4$ & 470p & T$_1$ & BC327\\ \hline
R$_6$ & 5 & C$_5$,C$_6$ & 100n & & \\ \hline
\end{tabular}
\caption{New sawtooth generator circuit schematic\label{fig_mysawtoothgenscheme}}
\end{figure}


The sawtooth at the capacitor is buffered by unity-gain non-inverting operational amplifier. Because of relatively high frequencies involved (and high requirements on the op amp slew rate), AD847 amplifier was used. It is supplied from symmetric power supply $\pm$6~V. The output is tied to ground through trimmers P$_2$,P$_3$ and resistor R$_6$. These serve as a voltage divider to set amplitude at the output. One trimmer serves as coarse adjustment, the other as fine. The range of the fine adjustment trimmer is dependent on the coarse trimmer position -- that however does not matter.

Both ICs power supply is bypassed by capacitors C$_1$, C$_5$ and C$_6$.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{mysawtooth.png}
\caption{New sawtooth generator circuit outputs \label{fig_mysawtooth}}
\end{figure}

Output of the circuit can be seen in figure~\ref{fig_mysawtooth} (compare to the old sawtooth generator output -- figure~\ref{fig_pila}). There are several differences between the old and new generator:
\begin{itemize}
\item The sawtooth is inverted with respect to the old generator

This poses no problem, the phase detecting circuit and both phase evaluation algorithms are able to work with both types of sawtooth.

\item The reference pulses are also inverted and their maximum voltage is 6~V.

The phase detector circuit described in previous chapter reacts to these reference pulses the same way as it reacts to the old generator.

\item The sawtooth DC offset cannot be adjusted

The varactor diode in the microwave generator does not require a DC offset.

\item Precise amplitude adjustment is more comfortable due to the fine adjustment trimmer.
\end{itemize}

The generator was tested and it was concluded that it can fully substitute the old generator. See shot \#19421 in GOLEM shot database as an example -- notice that both phase detecting algorithms were running and the new algorithm produced inverted results. The reason is that the OldGen variable was not reset and the algorithm therefore assumed that descending ramp was used for frequency sweeping.


\section{Backup selective amplifier}
The backup selective amplifier was constructed according to the schematics of the old amplifier (figure~\ref{fig_selectiveampscheme}), which should result in an exact copy. Things were not this simple however, because the RLC circuits in collectors used tunable inductance coils, that were difficult to obtain. The design therefore had to be slightly altered and a fixed coil with a variable capacitor was used instead. Resonance frequency can be easily calculated from a well known formula $f=\frac{1}{2\pi\sqrt{LC}}$. By checking available component values it was decided to use $L=330\, \upmu \textrm{H}$ and variable capacitance trimmer 0-100~pF parallel to a fixed value 220~pF capacitor. This should allow to tune the resonance frequency from 490 to 590~kHz. An additional 27p parallel capacitor was later added to the first resonance circuit (the range was a bit different than calculated, most likely due to component tolerances). Both circuits were tuned to about 510~kHz. The amplifier worked fine, but probably because of different parameters of the altered parts its gain was too high. One last change had to be made -- P$_2$ trimmer value was increased to 10k. The amplifier gain can then be adjusted in a wide range.
\newline

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{amplifiercomparison.png}
\caption{New amplifier frequency response compared to the old one\label{fig_amplifiercomparison}}
\end{figure}

Comparing its parameters to the old amplifier showed satisfactory results (see figure~\ref{fig_amplifiercomparison}). The center frequency is a bit different, which is irrelevant. What is more important is that the band width is significantly wider than with the old amplifier. After testing the circuit in situ the amplifier worked and the circuit was therefore not worked on further. In case the wide bandwidth of the amplifier will ever pose problems, the value of the 100k resistor in the RLC circuits might need to be increased (the issue is likely caused by different parameters of the new components). Another problem is the asymmetrical shape of the curve -- because there is no reason for the asymmetry, it can as well be caused by error\footnote{e.g. inadvertent adjustment of input signal amplitude} during measurement (it could not have been repeated due to lack of time).



\section{Power supply}
The new sawtooth generator, selective amplifier and phase detecting circuit operate from $\pm$6~V supply (the amplifier uses only positive rail). A single power supply can therefore be used for all three of them. A standard symmetric power supply was made using 7806 and 7906 voltage regulators. The schematic is shown in figure~\ref{fig_mypowersupply}.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{mypowersupply.png}
\caption{Symmetric power supply $\pm$6 V\label{fig_mypowersupply}}
\end{figure}

The circuit is supplied from 230~V/50~Hz mains line, which implies necessity to transform the voltage down and rectify it. Because the voltage drop of 78xx series regulators is about 2~V and one diode junction with a voltage drop around 0.7~V is used in the bridge rectifier, the absolute minimum for the transformer secondary peak voltage is 6+2+0.7~V=8.7~V, which is around 6.2~V~RMS. Nearest higher value available was 2x7.5~V. A plastic-cast 2x2.25~VA transformer made by Hahn company was chosen. Both secondary windings are fused by 315~mA T-type (slow) fuses, according to manufacturer's recommendation. The voltage is rectified by integrated bridge rectifier G and bypassed by two 2200~$\upmu$F capacitors (C$_1$,C$_2$) to remove AC ripple before they are fed to the voltage regulator inputs. Ceramic capacitors of 100~nF (C$_3$,$C_4$) at both the input and output are used for the 7806 regulator. Both regulator are additionally bypassed by electrolytic capacitor with 10~$\upmu$F capacity\footnote{The 78xx and 79xx regulators only work reliably when proper bypass capacitors are used and at least~5~mA of current is drawn from the output. This should be kept in mind in case someone would need to repair the power source. Especially the 79xx is very sensitive to correct operating conditions. Consult the datasheet before working with them.}.


\section{Instrument box construction\label{sec_box}}
A printed circuit board (PCB) has beed designed to accommodate the power supply, new sawtooth generator, copy of the old selective amplifier and phase detecting circuit. The PCB was designed by hand on a piece of checkered paper and it will not be presented here. The etching was done in an old-fashioned style (permanent maker and iron chloride). The schematics of the three circuits have already been shown in figures~\ref{fig_mypowersupply} (the power supply), \ref{fig_mysawtoothgenscheme} (the new sawtooth generator), \ref{fig_selectiveampscheme} (selective amplifier) and \ref{fig_myinterfscheme} (phase detecting circuit).

The PCB was mounted into appropriately sized (200x66x150 mm) black metal box by four M3 screws that protrude from the bottom of the box and also hold rubber supporting pads. Two 4~mm high plastic washers are used on each screw as spacers to prevent the bottom of the PCB to touch the casing. Each circuit has a separate on/off switch and a LED indicator. The adjusting trimmers were placed at the very edge of the PCB so that they are accessible through a small hole in the casing (they are plastic, there is no short-circuit hazard). Adding the necessary 7~BNC connectors, a total of 18~holes was drilled through the front panel. Another rectangular hole had to be made at the back for main power supply connector. The earth lead of the connector is connected to the case by the nearest of the four PCB holding screws.
\newline

The PCB layout will not be presented here -- it was printed and inserted into the box for future repairs.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{box.jpg}
\caption{The PCB mounted inside the box\label{fig_box}}
\end{figure}

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{frontpanel.jpg}
\caption{Front panel of the finished device\label{fig_frontpanel}}
\end{figure}

The connectors can only be soldered to the PCB after it is mounted in the box (the switches can be connected before and then be put in the holes from behind). The LED indicators were connected last to the mounted switches. This is inconvenient for repairs and probably should have been done differently (although there is no assumption that the box should need to be often opened). The whole box has a metal cover that is fixed by four small screws from the sides.

Small paper labels were eventually sticked on the front panel to label the connectors and controls. See figure~\ref{fig_frontpanel} for the finished device.


\section{QuinStar microwave generator}
The interferometer currently uses the old Ukrainian microwave generator. However, another varactor-tuned Gunn microwave generator is ready at GOLEM tokamak as a backup (see figure~\ref{fig_quinstar}), should the first device fail. The generator was made by QuinStar Technology, Inc. in the USA and is supplied with separate voltage/current stabilizer that accepts 15~V at the input. See appendix~\ref{app_generators} for factory datasheet. The generator has standard UG-387/U flange with imperial threads, which makes it easy to connect to the new directional coupler (necessary screws are too ready at GOLEM). The plywood board is designed to be compatible with the new generator, the swap should be an easy task.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{quinstar.jpg}
\caption{QuinStar made generator and its power supply\label{fig_quinstar}}
\end{figure}

Before installing the generator make sure that all connections are secure and there is no risk of any sparking. Should the leads require resoldering, do not attempt to use transformer soldering iron to prevent damage to the unit.
\newline





\chapter{Evaluation and conclusion\label{chap_evaluation}}

\section{Comparison of both digital algorithms}
Two algorithm to digitally evaluate sampled sawtooth and signal from the amplifier are ready to use at GOLEM (see chapter~\ref{chap_digital}). One is based on Fourier transformation, the other is new and works as a zero-crossing detector. Both were in service for several hundred shots (\#19000--\#19500) and can be therefore compared.

\subsubsection{Density results}
Providing that there is no microwave problem and the signal is good, both algorithms produce almost identical results, as already shown in figure~\ref{fig_18685algcomparison}. This is very important and assuring observation.

\subsubsection{Response to signal issues}
In case the signal slightly deteriorates or disappears during the shot, each of the algorithms fails occasionally. The number of such fails is similar with both algorithms. Because they work differently, they seldom fail on the same shot. The assumption that the new algorithm will be significantly better at removing fringes was false -- although sometimes it indeed is better, at other times it fails while Fourier transform algorithm does not. See figure~\ref{fig_algcomparison} for illustration. During shot \#19270 the new algorithm correctly recognized signal issues and terminated where was appropriate, while the Fourier transform based algorithm produces a bad result. However, during \#19274 the new algorithm gave up, even though there was enough data to get to correct result -- which the other algorithm did. The new algorithm less frequently gives incorrect results -- at the cost that it sometimes stops calculating prematurely. Several shots from the same session can serve as an illustration. It must be noted that signal quality was not good during the session and question arise whether data gathered under such conditions can be reliable at all (regardless of what the algorithms do).

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{algcomparison.png}
\caption{Comparing performance of both algorithms\label{fig_algcomparison}}
\end{figure}

\subsubsection{System resources and adjustments}
Several criteria can be established:
\begin{itemize}
\item Computing time

Both algorithm are comparable, although the Fourier transform based algorithm is a bit faster. The difference is not too big though, both algorithm terminate in a few seconds.

\item Sampling rate requirements

The Fourier transform based algorithm can be operated at sampling rates around 1~MS/s, the new algorithm fails sooner -- but still works at 2~MS/s. Again not an order of magnitude difference, but the old algorithm is a bit ahead.

\item Necessary adjustments

While the old algorithm is completely automatic, the new algorithm must be specifically told whether ascending or descending sawtooth generator is used. Not a big issue, but still a point for the old one.
\end{itemize}


\subsubsection{Conclusion}
Both algorithms are comparable and it does not matter which one will be chosen as the main one. The Fourier based algorithm works at smaller sampling rates, is a bit faster and is automatic, without the need to ever adjust anything. The advantage of the new algorithm is its tendency not to give incorrect results when the signal is bad -- but it sometimes leads to giving up too early. No definitive conclusion can be made.


\section{Analog density evaluation}
\begin{figure}[h]
\centering
\includegraphics[width=130mm]{19524.png}
\caption{Shot \#19524 -- analog vs. digital evaluation\label{fig_19524}}
\end{figure}

Let us now analyse the analog phase detecting circuit results (see chapter~\ref{chap_analog}). See figure~\ref{fig_19524} for comparison of analog circuit output and Fourier transform digital algorithm. The disadvantages of the analog circuit are:
\begin{itemize}
\item Signal from the analog circuit is noisy (to be fair, the digital algorithm has already smoothed its result).

\item The analog output does not react fast enough to show fast changes in density.

\item In case there is a signal issue, there will be a fringe -- there is no way to repair it (as the algorithms try to do)
\end{itemize}

The first two issues could be improved by designing better band-pass filter at the output. The output filter (see section~\ref{sec_outputfilter}) is very simple and its performance limited. Proper active higher order filter would likely do much better job.

That being said, using the analog circuit also has obvious advantages: two fast channels on an oscilloscope (or other data acquisition system) that the digital algorithm would need are free for different use. The interferometer only needs one channel with arbitrarily low sampling rate. Another advantage is that with analog evaluation, the results are immediately ready and one does not have to wait until the algorithm processes the data.
\newline

To conclude, the analog circuit (if it proves reliable enough) should provide density data precise enough for most of the work. In case that fast density changes need to be studied, the digital algorithm should be used to increase temporal resolution.

\section{New sawtooth generator and selective amplifier}
Although there was not much time to perform thorough testing, all three circuits that were installed in the black box (see section~\ref{sec_box}) were tested in situ and concluded operational. It is now therefore possible to use only circuits in the black box and leave the old ones as a backup in case there is a problem. Plasma density measurement does not depend on what circuits are used (providing the interferometer is properly adjusted (section~\ref{sec_calibration}). Figure~\ref{fig_final} shows the final state of the interferometer shelf with the new circuit in operation (the old circuits can be seen unplugged on the second shelf). It will now be tested and providing no issues appear, the shelves will be a bit reorganized to remove clutter, custom short connecting wires will be used to prevent mains AC noise to enter the system, etc.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{final.jpg}
\caption{Final state of the interferometer shelf\label{fig_final}}
\end{figure}

\section{Repeated signal issues\label{sec_signalissues}}
During the first several hundred shots, a strange phenomenon was occasionally observed -- declining signal quality with no apparent reason. The issue can be demonstrated on shots \#19098 -- \#19107. As one lists through the shots, it is obvious that signal quality progressively deteriorates. First the new algorithm produces blank spaces in the middle of the shot, from shot \#19105 the issue affects even the older (Fourier transform) algorithm. See density data from both algorithms from shot \#19106 in figure~\ref{fig_19105} to see typical manifestation of the problem.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{19105.png}
\caption{Shot \#19105 -- analog vs. digital evaluation\label{fig_19105}}
\end{figure}

The cause of the problem has not been found yet. When it appears, only turning the device off for some time helps (or so it seems). The issue can appear both at the beginning of the session or later, no dependence on any outer parameter was found.

A suspicious part of the device are the BNC connectors on the microwave generator, that are mounted so that regular BNC cable can not fully lock on to them (they protrude too little from the panel). In case one of the connections is loose, problems similar to the one just described could appear (the theory however does not explain why it should disappear overnight with no action taken). One way or another, it is essential to replace the BNC cable with one that is compatible (the generator might also be damaged by the loose contact).


\section{Independent verification\label{sec_verification}}
Although it would be beneficial to compare the results with some independent method of obtaining plasma density, this could not have been done. At the time there was no diagnostics that would provide any information on density available at GOLEM. Two attempts were made to do at least partial estimate.

\subsubsection{Ideal gas state equation}
Assuming that all gas in the vessel is hydrogen that is completely ionized during plasma discharge and neglecting background vacuum pressure, the average density in the vessel should be

\[\frac{N}{V}=\frac{p}{kT}\]

Assuming room temperature and pressure of 10~mPa, one gets
\[\frac{N}{V}\approx 2.5\cdot 10^{18}\,\textrm{m}^{-3}\]

This density is of the same order of magnitude as the one measured by the interferometer (see previously shown shots). Everything is not quite right though, as one can observe when the pressure is changed. The measured density appears to be independent of initial gas pressure.

An important fact that has to be mentioned in order to explain this behaviour is that currently there are major issues with background pressure at GOLEM. In case the working gas partial pressure is set to 10~mPa, the background pressure before gas injection should be at least an order of magnitude lower (i.e., under 1~mPa). However, the tokamak in the current status can reach at best around 8~mPa of background pressure. Injecting additional gas to partial pressure of 10~mPa means the total pressure in the vessel will be 18~mPa. Nothing can be assumed about the residual gas, so the assumptions above cannot hold. Until the background pressure is better, this method will not provide reliable plasma density estimate.


\subsubsection{Comparison to Greenwald density}
Greenwald density is an empirically obtained limit density in a tokamak~\cite{bib_wesson}. When it is exceeded, a disruption occurs. It can be calculated as ($I_{MA}$ stands for plasma current in megaamps, $a$ is minor plasma radius):
\[n_{GW}=\frac{I_{MA}}{\pi a^2}\cdot 10^{20}\, \textrm{m}^{-3}\]

The measured density should therefore not exceed this limit (and when it does, the plasma should soon disappear). It is only an order of magnitude comparison though, because the formula might not hold precisely in case of GOLEM and its current background vacuum limits. The Greenwald density is calculated in Advanced Analysis for every GOLEM shot.

\begin{figure}[h]
\centering
\includegraphics[width=130mm]{greenwald.png}
\caption{Shot \#19332 -- approaching the Greenwald limit\label{fig_greenwald}}
\end{figure}

Figure~\ref{fig_greenwald} shows data from shot \#19332, during which the Greenwald limit was closely approached. Notice plasma current and U$_{loop}$ behaviour at the time. While the state cannot really be called a disruption, it appears that some process eventually leading to plasma disappearance was indeed triggered at the time average density was reaching the Greenwald limit.

This is by no means a proof of correct function of the interferometer. The Greenwald limit is only empirical formula whose precision on this device (in its current status) cannot be guaranteed. That being said, so far it was never observed that the measured density crossed the Greenwald limit\footnote{In some shots before 18890 in appears otherwise -- but this is due to incorrect interferometer calibration, as mentioned in section~\ref{sec_fourier}.}. So although the overall reliability of this method can be questioned, the numbers add up well.

In order to investigate further, more shots would have to be taken (ideally specifically aimed at trying to exceed the Greenwald limit). In order to do this, better initial vacuum condition must be reached.

\section{Summary}
Let us now briefly summarize what has been done during the work.
\begin{itemize}
\item The interferometer was made fully operational

\item Two digital algorithm are available to evaluate density (after the sawtooth and sine signal are digitally sampled)

\item Analog electronic circuit was developed to substitute the algorithms (to save the acquisition systems for other use)

\item Another sawtooth generator and selective amplifier were made so that the device does not have to rely on the old circuits

\item All three circuits were mounted into a single box

\item Basic tests were conducted to check proper function of the device (although lack of time and technical difficulties prevented more detailed studies)

\item Everything was documented so that all necessary information is ready for future researchers
\end{itemize}

With the interferometer now in operation, the vital information on plasma density is finally available at GOLEM. That opens many opportunities for further educational and research tasks on the tokamak. Many more experiments can now be conducted and the tokamak will thus continue to prove that being old does not mean to be useless.


\section{Ideas for the future}
There is a lot of things that could (or should) be done in future to improve the interferometer operation. Namely:

\begin{itemize}
\item The signal deterioration issue described in section~\ref{sec_signalissues} must be resolved. Otherwise the device cannot be fully trusted.

\item It is necessary to check proper function of the device and make a conclusion about its reliability over at least several hundred shots.

\item When the background pressure issue is resolved, it would be interesting to repeat the verification experiments described in section~\ref{sec_verification}. This will be relatively simple yet interesting task that even a beginner student could do.

\item In case the analog circuit signal quality will prove unsatisfactory, the output filter can be improved. (section~\ref{sec_outputfilter}).

\item The average density is calculated by assuming plasma position in the middle of the vessel. A correction might be necessary to account for plasma displacement. This might make the results more precise. Some work in this field was already done by T. and M. Odstrcil.
\end{itemize}





\begin{appendices}
\chapter{Generator technical lists\label{app_generators}}

\begin{figure}[h]
\centering
\includegraphics[scale=0.45]{appendices/americangen.pdf}
\caption{QuinStar generator technical list}
\end{figure}


\begin{figure}[h]
\centering
\includegraphics[scale=0.6]{appendices/russiangen.jpg}
\caption{Russian generator technical list}
\end{figure}




\chapter{Waveguides and flanges\label{app_waveguides}}
Taken from \cite{bib_quinstar}.
\begin{figure}[h]
\centering
\includegraphics[scale=0.7]{appendices/rectangular.png}
\end{figure}

\begin{figure}[h]
\centering
\includegraphics[scale=0.45]{appendices/flanges.png}
\end{figure}


\end{appendices}






\begin{thebibliography}{99}
\bibitem{bib_zacek}{ZACEK, F., MUSIL, J. \emph{Mikrovlnne mereni komplexni permitivity ve volnem prostoru}. 1. vyd. Praha: Academia, 1980, 229 s.}

\bibitem{bib_wesson}{WESSON, John. \emph{Tokamaks}. 3rd ed. Oxford: Clarendon Press, 2004, xii, 749 s. ISBN 0-19-850922-7.}

\bibitem{bib_hutchinson}{HUTCHINSON, I. \emph{Principles of plasma diagnostics}. 2nd ed. Cambridge: Cambridge University Press, 2002, xvii, 440 s. ISBN 0-521-67574-x.}

\bibitem{bib_vlcek}{VLCEK, J. \emph{Moderni elektronika}. 1.~vyd. Praha: nakladem autora, 2003, 237 s.}

\bibitem{bib_kulhanek}{KULHANEK, Petr. Uvod do teorie plazmatu. Vyd. 1. Praha: AGA, 2011, 375 s. ISBN 978-80-904582-2-2.}

\bibitem{bib_kvasil}{KVASIL, Bohumil. \emph{Theoreticke zaklady techniky centimetrovych vln}. 1.~vyd. Praha: SNTL, 1957, 303 s.}

\bibitem{bib_gardiol}{GARDIOL, F. \emph{Introduction to microwaves}. Artech House. 1984.}

\bibitem{bib_gunn}{The Gunn Effect [online]. Johannes Kepler Universitat, Linz [cited 1.5.2015]. Available from: http://www.nhn.ou.edu/~johnson/Education/Juniorlab/Microwave/Gunn\%20Effect.pdf}


\bibitem{bib_art}{HOROWITZ, Paul a Winfield HILL. \emph{The art of electronics}. 2nd~ed. Cambridge: Cambridge University Press, c1989, xxiii, 1125 s. ISBN 9780521370950.}

\bibitem{bib_mccracken}{McCRACKEN, G., STOTT, P. \emph{Fuze - energie vesmiru.} Mlada Fronta, a.s., First edition, Prague, 2006. ISBN 80-204-1453-3}

\bibitem{bib_wharton}{HEALD, M., WHARTON C.B. \emph{Plasma Diagnostics with Microwaves}. Wiley. New York. 1965.}

\bibitem{bib_555}{555 Timer [online]. Doctronics Educational Publishing [cited 1.5.2015]. W. D. Phillips. Available from: http://www.doctronics.co.uk/555.htm}

\bibitem{bib_poe}{SIMPSON, C. \emph{Principles of Electronics}. Prentice-Hall. 2002. ISBN 0-9686860-0-1.}

\bibitem{bib_golem}{GOLEM @ FJFI.CVUT [online]. FJFI CVUT. [cit. 1.5.2015]. Available from: http:///golem.fjfi.cvut.cz/}

\bibitem{bib_castor}{Tokamak CASTOR and its history [online]. UFP AV CR. [cit. 1.5.2015]. Available from: http://www.ipp.cas.cz/Tokamak/index?m=castor}

\bibitem{bib_fig_modes}{The field patterns of some common waveguide modes [online]. In: \emph{Wikipedia, The Free Encyclopedia}. Wikimedia Foundation UFP AV CR. [cit. 1.5.2015]. Available from: http://en.wikipedia.org/wiki/Waveguide\_filter.}

\bibitem{bib_quinstar}{Technical reference manual [online].  QuinStar Technology, Inc. [cit. 1.5.2015]. Available from: http://quinstar.com/files/2011/10/references.pdf.}

\end{thebibliography}


\end{document}




% - prehodit odstrcily?
% - elektroschemata