A real-time detection algorithm for sawtooth crashes in nuclear fusion plasmas Imke D. Maassen van den Brink (0502234) DCT 2009.076

Master’s thesis

Coaches: ir. G. Witvoet1 dr. ir. N.J. Doelman2

Supervisor: prof. dr. ir. M. Steinbuch1

Committee: Supervisor and coaches (see above) prof. dr. N. Lopes Cardozo1,3 dr. E. Westerhof3

1Technische Universiteit Eindhoven Department Mechanical Engineering Dynamics and Control Technology Group

2TNO Science and Industry Department of Instrument Modeling and Control Delft, The Netherlands

3FOM Institute for Plasma Physics Rijnhuizen Department of Fusion Physics Nieuwegein, The Netherlands

Eindhoven, August, 2009 2 Contents

1 Introduction 5

2 Introduction to nuclear fusion and tokamaks 7 2.1 Nuclear Fusion ...... 7 2.2 Tokamaks ...... 9 2.2.1 Magnetic field and flux ...... 10 2.2.2 Operating principle during a discharge ...... 11 2.3 Tokamak instabilities ...... 11 2.3.1 MHD instabilities ...... 11 2.3.2 Neoclassical tearing modes and magnetic islands ...... 12 2.3.3 Sawtooth oscillation ...... 12 2.4 Actuators and sensors ...... 13 2.4.1 Neutral Beam Injection ...... 14 2.4.2 Ohmic heating ...... 14 2.4.3 RF heating ...... 15 2.4.4 Electron Cyclotron Emission diagnostic ...... 16 2.5 Research objective ...... 17 2.5.1 Control of the sawtooth period ...... 17 2.5.2 TEXTOR ...... 17 2.5.3 Detection algorithm for sawtooth crashes ...... 18

3 Analysis methods of the sawtooth oscillation 19 3.1 Time domain analysis ...... 20 3.1.1 Difference filter ...... 20 3.1.2 Averaging filter + difference filter ...... 20 3.1.3 Standard deviation + difference filter ...... 21 3.2 Fourier transforms ...... 21 3.2.1 ...... 22 3.2.2 Continuous Fourier Transform ...... 24 3.2.3 Discrete-time Fourier Transform ...... 25 3.2.4 Discrete Fourier Transform ...... 26 3.2.5 Short-time Fourier Transform ...... 27 3.3 Wavelet analysis ...... 27 3.3.1 Continuous Wavelet Transform ...... 28 3.3.2 Discrete Wavelet Transform ...... 29 3.4 Cohen’s class of time- distributions ...... 33 3.4.1 The energy distribution function ...... 33 3.4.2 Mathematical definition ...... 34 3.4.3 Discrete distributions of Cohen’s class ...... 34 3.4.4 Wigner-Ville Distribution ...... 36 3.4.5 Choi-Williams Distribution ...... 36 3.5 Application of the analysis methods on the sawtooth oscillation ...... 37

3 4 CONTENTS

3.5.1 Representation ...... 37 3.5.2 Clarity ...... 38 3.5.3 Computational complexity ...... 41 3.5.4 Concluding remarks ...... 44

4 Time domain sawtooth recognition algorithm 45 4.1 Noise filtering ...... 46 4.1.1 Frequency analysis of the sawtooth signal ...... 46 4.1.2 Filter design ...... 49 4.1.3 3rd order Butterworth filter ...... 55 4.1.4 Implementation structures ...... 55 4.2 Data processing method ...... 57 4.2.1 Statistical dispersion ...... 57 4.2.2 1st order difference filter ...... 60 4.3 Normalization ...... 62 4.3.1 Buffering the signals ...... 63 4.3.2 Noise level determination ...... 63 4.3.3 Normalizing the signal ...... 64 4.4 Determination crash times ...... 64 4.4.1 Combining channels ...... 64 4.4.2 Comparing with thresholds ...... 65 4.4.3 Hold subsequent exceeding times ...... 65 4.4.4 Determination exact crash-times ...... 66 4.5 Period ...... 66 4.6 Inversion radius ...... 67 4.7 Algorithm analysis ...... 68 4.7.1 Computational complexity ...... 68 4.7.2 Clarity ...... 70

5 Results 71 5.1 Operating regime ...... 71 5.2 Shot 107915 ...... 71 5.3 Shot 110051 ...... 74 5.4 Shot 110178 ...... 76 5.5 Shot 110185 ...... 78 5.6 Concluding remarks ...... 78

6 Conclusion 79

A Appendix I 81 A.1 Euler’s formula ...... 81 A.2 Interpretation negative ...... 81 A.3 Power spectrum ...... 82 A.4 ...... 82 A.5 Computational complexities ...... 83 A.5.1 Time domain processing methods ...... 84 A.5.2 FFT algorithms ...... 84 A.5.3 STFT algorithms ...... 84 A.5.4 DWT algorithms ...... 85 A.5.5 Analytical signal computation methods ...... 85 CONTENTS 5

B Appendix II 87 B.1 algorithm ...... 87 B.2 filt...... 89 B.3 normal ...... 90 B.4 crashdet ...... 90 B.5 merg ...... 91 B.6 crashtime ...... 92 B.7 invrad ...... 93 B.8 periode ...... 94 References ...... 95 6 CONTENTS Abstract

A new promising energy resource for the future is energy based on nuclear fusion in a tokamak reactor. Nuclear fusion in tokamaks suffer from a number of plasma instabilities, which significantly influence the efficiency of the nuclear reactions. One instability that occurs close to the center of the plasma is the sawtooth instability, named after the sawtooth shaped profile of the temperature and density at a fixed location in the plasma. The sawtooth instability involves both desired and undesired effects on the plasma and, therefore, a controller should be designed to control the sawtooth period real-time with an optimal trade-off be- tween these effects. The input of the controller is the present sawtooth period. Therefore, a reliable algorithm should be designed to determine accurately the sawtooth period for signals with a wide range of sawtooth periods, crash sizes and sawtooth shapes. Inaccurate determination of the period results in a distorted input and corresponding false output of the controller. Consequently, the output power can trigger other instabilities and eventually abruptly end the discharge with considerable con- sequences.

Several signal analysis methods are investigated, such as Fourier transforms, Wavelet transforms and distribution functions of Cohen’s class, according to their representation, the accuracy, clearness and reliability of the outcome of the analyzed signal, and according to the computational complexity of the methods in implementation algorithms. A time domain algorithm seems to be a logical first step for the sawtooth recognition problem, which is designed and tested on TEXTOR data.

The designed algorithm consists of a Butterworth low-pass filter to attenuate the high-frequent noise, a first order difference filter to emphasize the statistical dispersion in the crash samples, a normalization function for normalizing the different noise levels of the different ECE channels and finally, another first order difference filter to obtain the final real-time period. The location of the inverse radius is also determined by the algorithm. The performance of the algorithm with respect to the clarity is very good, with an accuracy and relia- bility of the obtained results between 98.67% and 100% for sawtooth signals with varying noise levels, sawtooth periods, crash lengths and sawtooth shapes. The computational complexity of the designed time domain algorithm is significantly lower than the complexity of the time-frequency domain signal analysis methods discussed earlier. The performance and computational complexity give promising results for real-time implementation on TEXTOR.

1 2 CONTENTS Preface

This report describes the results of my graduation project at the Dynamics and Control Technology Group of the Technische Universiteit Eindhoven. The project is carried out in collaboration with TNO Science and Industry Delft and FOM Institute for Plasma Physics Rijnhuizen Nieuwegein. During my assignment I received a lot of help and support by many people. Hereby, I would like to show my gratitude.

Firstly, I would like to thank my coaches Gert Witvoet from the TU/e and Niek Doelman from TNO for their support, input and critical comments during my research. I appreciate that very much.

Secondly, I would like to show my gratitude to Maarten Steinbuch, Pieter Nuij and Niek Lopes Cardozo from the TU/e, Egbert Westerhof and Marco de Baar from the FOM institute and again Gert Witvoet and Niek Doelman for giving me the opportunity to participate in the exciting research community of nuclear fusion, and for the interesting discussions and pleasant moments during the fusion meetings and excursions to Germany and England.

Finally, I would like to thank my dear parents Ab en Marlies and my brothers Sander and Marnix, for their permanent great support, comfort, confidence and understanding during my whole studying period, and my dear friends Marieke and Jeroen, for offering me frequently a place to stay and making me feel at home in Delft.

3 4 CONTENTS Chapter 1

Introduction

Motivation Today’s energy generation is mainly based on fossil fuel resources like oil, gas and coal. A major drawback of fossil fuels is the pollution of the environment by the CO2-emission attended with en- ergy generation of fossil fuels. Furthermore these conventional energy sources become exhausted and therefore, along the years, new sustainable energy resources are employed, like solar and wind energy. These sustainable energy sources can replace part of the present fossil fuel sources, but the yield will not be sufficiently enough to intercept the growing energy demand by the fast growing world popula- tion and increased energy use per capita. A promising sustainable energy resource for comprehensive energy generation is energy based on nuclear fusion in a donut-shaped reactor, known as a tokamak. There are about 50 tokamaks worldwide, but until now, none of them can function as an energy supplying reactor. In Cadarache, France the new tokamak ITER is built, with as main purpose to enhance understanding of the underlying physics of nuclear fusion in a tokamak and to perform ex- periments with developed technologies for heating, confinement and diagnostic purposes. Eventually ITER should generate energy, but first some problems concerning tokamak and plasma instabilities should be solved.

An important instability occurring in the plasma during discharge is the sawtooth instability. This instability occurs at a certain distance from the center of the plasma, the so-called (q = 1) surface, where the magnetic field line winds exactly one time the long way around the torus during one wind- ing the short way around the torus. The sawtooth instability results in a sawtooth shaped profile of the temperature and density in the center of the plasma. The sawtooth instability has both positive and negative effects on the stability of the plasma. The temperature of the center of the plasma is lim- ited, due to the very fast transport of energy and particles from the center to the outside of the plasma. Furthermore, the sudden drop in temperature, the crash, triggers undesired other instabilities, known as neoclassical tearing modes, and can abruptly end the discharge with considerable consequences. A favorable effect of the sawtooth instability is the removal of helium ash from the center by the fast transport of particles, preventing dilution of the plasma.

Objective The positive and negative effects of the sawtooth crash can be controlled by controlling the period of the sawtooth, and the corresponding size of the crash. By directly injecting a current with power P inside or outside the (q = 1) surface in the plasma, the sawtooth period can be controlled, as a result of the increased or decreased magnetic shear. The input of the controller is the present sawtooth period and therefore, first an algorithm should be designed to accurately determine the sawtooth period over a wide range of sawtooth periods, crash sizes and sawtooth shapes. False detection results in a distorted output of the controller, and consequently the negative effects of the sawtooth can be triggered, which

5 6 CHAPTER 1. INTRODUCTION can result in an unstable plasma or even a sudden end of discharge. The period of the sawtooth can be obtained by detecting a certain repeating feature of the sawtooth oscillation such as the sawtooth crash. Therefore, in this master thesis an algorithm is designed to accurately determine the sawtooth period of sawtooth signals from the TEXTOR tokamak in Jülich, Germany, by means of a sawtooth crash detection algorithm.

Outline First the concepts of nuclear fusion, tokamaks, plasma instabilities in a tokamak and some of the actuators and sensors in a tokamak are described in Chapter 2. The last section describes extensively the objective of this master thesis. Preceding the actual design of a sawtooth recognition algorithm, different signal analysis methods are reviewed in Chapter 3, such as the time domain analysis, Fast-Fourier Transforms, Wavelet Trans- forms and distribution functions from Cohen’s class. In the last subsection, the different analysis techniques are investigated for application in real-time algorithms for the detection of crashes in saw- tooth oscillations. The methods are classified according to some predefined desired properties of a real-time recognition algorithm. Finally, in Chapter 4 a time domain sawtooth recognition algorithm is designed for real-time imple- mentation on TEXTOR. The results of the applied algorithm to different shots are reported in Chapter 5. Chapter 2

Introduction to nuclear fusion and tokamaks

The growing world population and increased energy use per capita results in a growing energy de- mand. Today’s energy generation is based mainly on fossil fuels, like oil, gas and coal. These fossil fuel resources will run out eventually. Another drawback of fossil fuels is the CO2 emission attended with the energy generation of fossil fuels. Therefore, a switch to sustainable energy resources is needed. A promising sustainable energy resource is energy based on nuclear fusion. In this chapter, first the concepts of nuclear fusion and tokamaks is described in Section 2.1 and Section 2.2 respectively, fol- lowed by the principal plasma instabilities in a tokamak in Section 2.3. Section 2.4 gives an overview of some of the actuators and sensors in a tokamak used for heating the plasma and measuring heat respectively. The last section describes extensively the objective of this master thesis.

2.1 Nuclear Fusion

In nuclear fusion the nuclei of two light atoms fuse together, creating a heavier nucleus and lots of energy. The (kinetic) energy released is a result of the reduction in total mass, due to the nuclear rearrangement [32]. This relation between mass and energy was proposed in 1905 by Albert Einstein and is defined as:

E = mc2. (2.1)

Here, c represents the speed of light in a vacuum. Nuclear fusion can be obtained by several methods, by which thermonuclear fusion is the most promising. In thermonuclear fusion the fuel is heated to an exceptionally high temperature, resulting in sufficiently high velocities to overcome the mutual repulsion of both nuclei, due to their positive charges. The most promising fusion reaction is the fusion of the elements deuterium and tritium, since the reaction between these two hydrogen isotopes shows the highest cross-section [32]. The cross-section of a reaction is a measure of the probability of a fusion reaction as a function of the relative velocity of the two reactant nuclei. The D-T fusion process results in the formation of a helium nucleus and an energetic neutron, see Figure 2.1.

Nuclear fusion has some major benefits with regard to nuclear fission and other energy resources. First of all, there is an overflow of fuel for nuclear fusion. Deuterium can be extracted from seawater and lithium can be found in many rocks, but also seawater contains an estimated 230 billion tons of lithium [24]. This in contrast to the exhausting fossil fuel sources, like oil, gas and coal. Although the uranium reserves for fission can last for thousands of years with reprocessing and recycling, the

7 8 CHAPTER 2. INTRODUCTION TO NUCLEAR FUSION AND TOKAMAKS

Figure 2.1: Graphical representation of the deuterium-tritium fusion reaction.

retraction of highly radioactive uranium metal from its ore is a risky event, where extensive measures must be employed to avoid radioactive exposure due to contaminated air or water. Furthermore, in nuclear fusion the primary sources of radioactivity are the materials of the reactor made radioactive by neutron collisions. This radioactivity can be kept low-level and requires less then a century to neutralize by a smart choice of these materials. The fission by-products can remain radio- activated for thousands of years and therefore demand special storage and handling. Also, the fusion process poses no risk of a nuclear accident, since the process can be shut down at anytime by stopping the source supply, while the fission process continues as a consequence of the chain reactions in which the heavy atoms are split. The environmentally friendly helium reactant is another major advantage of nuclear fusion considering the environmental issues of air pollution and greenhouse gases, produced by conventional energy sources such as oil and gas.

A well-known example of nuclear fusion is the burning sun. in the sun the large executed gravitational forces can confine plasma and make nuclear fusion possible. Nuclear fusion can only take place if some conditions concerning the temperature and density of the fusion mix are met. A reactor can only be productive if the amount of energy obtained by nuclear fusion is larger than the amount of energy invested to heat the plasma. The energy production depends on the confinement time and the ion density, which influence the number of effective collisions between particles. In 1957 J.D. Lawson stated that the product of confinement time and ion density should satisfy a minimum condition to obtain a net yield of energy by nuclear fusion. For deuterium-tritium fusion Lawson’s criterion is defined as:

20 −3 nτE 10 [m s]. (2.2) ≥

Here, n represents the ion density and τE the energy confinement time. In inertia bombs this condi- tion is met by imploding and heating a large part of the surface of a pellet of fusion fuel by a rapid pulse of energy. This method known as inertial confinement causes the plasma to reach a high pressure and temperature simultaneously. The high pressure results in an increased density. Another confinement principle used in reactors is magnetic confinement. The temperature required for nuclear fusion to occur in a reactor based on magnetic confinement lies around 100 million de- grees, which can be obtained by applying the heating methods discussed in Section 2.4. At these temperatures the nuclei of two hydrogen isotopes fuse together in an ionized plasma consisting of negative charged electrons and positive ions. At magnetic confinement the electric conductivity of the plasma is used to confine the plasma by applying electromagnetic fields which exert a confining force on the charged moving particles, see Figure 2.2. This force, known as the Lorentz force balances the very steep pressure gradient resulting from the temperature difference of the plasma between the core of the reactor and near the wall. Furthermore, the magnetic field also limits the charged particles from moving in the direction perpendicular to the field. Magnetic confinement is the confinement method used in the existing nuclear fusion devices discussed in the next section. 2.2. TOKAMAKS 9

Figure 2.2: Graphical representation of the magnetic confinement principle.

2.2 Tokamaks

The most widely used nuclear fusion reactor that uses magnetic confinement to achieve nuclear fusion is the donut-shaped tokamak, depicted in Figure 2.4. The advantage of the tokamak is found in the increased stability provided by its large toroidal magnetic field [32].

Figure 2.3: Schematic representation of JET.

There are about 50 tokamaks worldwide, from which the Joint European Tokamak (JET) in England is the largest with a major radius of almost 3 meters. All of the existing tokamaks are research machines and neither one of the reactors can function as an energy supplying reactor. The best results with respect to energy generation by nuclear fusion have been achieved on JET, which obtained a fusion 10 CHAPTER 2. INTRODUCTION TO NUCLEAR FUSION AND TOKAMAKS power of 16.1 MW during a discharge of 1.5 seconds. The success of nuclear fusion in a reactor can be described by the ratio Q between the thermonuclear power produced and the heating and current drive power supplied. This ratio is called the fusion gain or the fusion performance index. At the aforementioned JET discharge a ratio of Q = 0.62 was reached.

Eventually, the goal is to let energy generated by nuclear fusion become responsible for a substantial part of the worldwide energy demand. Therefore, the research at tokamaks and nuclear energy has to continue. The next step is the construction and operation of the International Thermonuclear Ex- perimental Reactor (ITER). ITER is a collaboration between several countries worldwide. The main goal of ITER is to enhance understanding of the underlying physics of nuclear fusion in a tokamak, to perform experiments with developed technologies for heating, confinement and diagnostic purposes and eventually, to obtain a self-burning plasma with a Q-ratio of Q = 5.

Tokamaks are magnetic confinement devices, which means that the plasma is confined within a fixed volume by magnetic fields. The principle of magnetic confinement is explained in the next subsection. Subsection 2.2.2 describes the operating principle of a tokamak during a single plasma pulse.

2.2.1 Magnetic field and flux A tokamak consists of toroidal field coils to confine the plasma within the torus, and poloidal field coils to confine, shape, heat and drive current through the plasma. Figure 2.4 shows a schematic representation of a tokamak with the coils.

Figure 2.4: Schematic representation of a tokamak.

Currents flowing in the toroidal field coils produce the toroidal magnetic field B directed in the φ coordinate. A current passing through a primary poloidal coil around the torus induces a toroidal electric field, which drives a toroidal current through the plasma. The plasma current produces the poloidal field Bθ, which is any magnetic field orthogonal to φ. The resulting helical magnetic field lines lie on nested toroidal flux surfaces with constant magnetic flux. The magnetic flux ψ through a surface A can be defined as the product of this magnetic field B and the surface perpendicular to the field:

ψ = BA. (2.3) 2.3. TOKAMAK INSTABILITIES 11

The constant flux contours also represent constant pressure and safety factor q1. The safety factor q can be defined at each point in the poloidal field as the number of times a magnetic field line winds the long way around the torus, indicated by the toroidal mode number n, divided by the number of times it winds the short way around, indicated by poloidal mode number m. The safety factor at a certain position in the plasma corresponds to the ratio between the toroidal magnetic field and the poloidal magnetic field:

n B q = = φ . (2.4) m Bθ The next subsection describes the operating principle of a tokamak during a single discharge.

2.2.2 Operating principle during a discharge In this subsection the operating principle of a tokamak is described during a single plasma pulse or discharge. At the beginning of the discharge the toroidal magnetic field is produced by the toroidal field coils to confine the soon created plasma. Next, deuterium gas is injected into the interior of the torus and a maximum current is applied in the center poloidal field coils. At the beginning of the discharge the current in the center poloidal field coils is driven down very quickly to produce a large electric field in the torus. As a result, the free accelerated electrons collide with the neutral gas atoms, causing these atoms to break up and to produce a plasma consisting of charged particles. In the next step, the plasma is heated by a heating method known as ohmic heating. This method uses of the free charged particles and a current in the plasma, driven by the transformer action of the transformer and the conducting plasma. Then additional deuterium gas is injected into the torus to increase the density and pressure, and additional heating methods are applied to further increase the temperature. This is necessary to satisfy the Lawson criteria and obtain nuclear fusion in the tokamak.

The plasma in a tokamak can be treated as a complex system, which is stable when perturbations satisfy certain equations and conditions. Perturbations like current and pressure gradients, combined with adverse magnetic field curvature do not always satisfy these conditions and can result in instabil- ities. The next section describes a number of these instabilities.

2.3 Tokamak instabilities

In this section some of the instabilities resulting from current and pressure gradients in the plasma are reviewed. In Subsection 2.3.1 the principle of magnetohydrodynamics is explained, after which the neoclassical tearing mode instabilities and magnetic islands are described in Subsection 2.3.2. Subsection 2.3.3 describes the events occuring in the plasma during the important sawtooth instability.

2.3.1 MHD instabilities The plasma instabilities in a tokamak can be divided into macroscopic instabilities and microscopic instabilities, where the macroscopic instabilities can be described by magnetohydrodynamics and the microscopic instabilities can not. In plasma physics, magnetohydrodynamics (MHD) is the branch that describes the basic behavior of the plasma, in terms of the interaction among currents, magnetic fields, and forces exerted on and by the plasma. A special class of MHD is the ideal MHD, which is sufficiently accurate to use as a first approximation in almost every magnetic analysis done in tokamak plasma physics, like studies of plasma magnetic instabilities and estimation of the plasma shape and position for control. In ideal MHD it is assumed that plasma has zero electrical resistance and consequently, the plasma is perfectly conducting. Since this assumption is not always justified, the MHD instabilities can be divided in

1This statement holds under the assumption of ideal MHD, which is explained in Subsection 2.3.1 12 CHAPTER 2. INTRODUCTION TO NUCLEAR FUSION AND TOKAMAKS ideal modes and resistive modes. The ideal modes occur even if this assumption of zero electrical resistance was true, for example the kink instability. The resistive modes are the instabilities which are dependent on the resistivity of the plasma. An example of a resistive mode is the neoclassical tearing mode (NTM), which is further discussed in the next subsection.

2.3.2 Neoclassical tearing modes and magnetic islands The neoclassical tearing instabilities are examples of MHD instabilities. NTM’s in a tokamak are caused either by an external resonant magnetic perturbation field, or by the radial gradients of the toroidal current density, resulting from the axisymmetric current density rearranged to an energet- ically favorable non-axisymmetric distribution. The tearing instabilities identify themselves by torn 3 2 and rejoined magnetic field lines at rational q values, such as (q = 2 ) and (q = 1 ). At these q values, the constant flux surfaces are resonant and due to short-circuiting, these flux surfaces can become constant flux volumes, known as magnetic islands. The short-circuiting of flux surfaces with different temperature profiles causes a flattening in the temperature and density profile of the islands. As a result, the self-generated toroidal bootstrap current, driven by the temperature and density gradient, reduces and further destabilizes the mode. Disruptions like NTM’s and the magnetic islands can re- sult in a sudden drop of total temperature and internal energy in the plasma. This can lead to a rapid termination of the discharge in a disruption, at which the entire energy is abruptly released at the tokamak’s wall structures. The seed islands for NTM’s can be provided by an instability at the (q = 1) surface known as the sawtooth instability. This instability is discussed in the next subsection.

2.3.3 Sawtooth oscillation A relaxation oscillation can be detected by several diagnostics in the center of the plasma in a toka- mak. The oscillation appears as a sawtooth of the temperature and density profile, see Figure 2.5. In the center, a sawtooth oscillation with a gradual rise followed by a rapid drop on a much faster timescale can be observed. In the outer region, the opposite phenomenon occurs: a gradual decrease in temperature and density followed by a steep jump. Still a lot of research is devoted to the saw- tooth oscillation, but the essentials of this instability can be described by the Kadomtsev model, which includes the magnetic rearrangement by fast reconnection of the magnetic field lines [32].

7 132.5 GHz 135.5 GHz 138.5 GHz 141.5 GHz 6 144.5 GHz

5

4 Temperature [A.U.]

3

2 2 2.05 2.1 2.15 Time [s]

Figure 2.5: Sawtooth signals at the center and outer regions.

The sawtooth instability develops in the plasma core at high plasma current, when the safety factor q is less than 1 [27]. The sawtooth instability can be divided into different stages corresponding to the 2.4. ACTUATORS AND SENSORS 13 shape of the sawtooth. The temperature and density increases in the center of the plasma during the ramp of the sawtooth oscillation, causing the pressure and bootstrap current to raise. As a re- sult of the raising pressure and current, the magnetic shear grows and at the rational surface (q = 1), which is highly sensitive to perturbations, reconnection of flux surfaces can occur. The resulting mag- netic island forms the start of the steep fall in the sawtooth oscillation and during this sawtooth crash, the magnetic island grows rapidly as a consequence of the reduced bootstrap current. The original hotter center of the plasma gets pushed outward, where the particles redistribute in poloidal direction. At the end of the crash, the center is taken over by the magnetic axis of the island and the sawtooth cycle is restarted.

The sawtooth instability does not only result in a limited peaking of the plasma core temperature and density, it has also been shown to trigger the neoclassical tearing modes [30] discussed in Subsection 2.3.2. The onset of NTM’s can lead to the end of the discharge and can cause severe tokamak damage. A favorable effect of the sawtooth oscillation is the disposal of impurities like helium ash in the center of the plasma by redistributing the particles. This prevents dilution of the plasma, which could lead to heavy oscillations of fusion power and plasma temperature and finally to termination of the discharge [15].

Thus, the sawtooth instability by itself is not a direct threat for maintaining nuclear fusion in a toka- mak, but especially the generally accompanying onset of NTM’s has been a crucial reason to conduct research on the understanding and control of sawtooth instability. Several experiments on JET showed that there is a direct relation between sawteeth and the onset of NTM’s [4]. Therefore, by controlling the sawtooth period NTM’s can be avoided. Sawtooth control also enables the control of the density of helium ash in the plasma center, which is desired to prevent dilution of the plasma.

2.4 Actuators and sensors

As already mentioned before, the temperature of the plasma in the vessel should be around 100 mil- lion degrees to make nuclear fusion possible. The three most widely used methods used for heating and driving current in the plasma, like ohmic heating, radio-frequency heating and current drive and neutral beam injection, are discussed in this section. Furthermore, a diagnostic tool for the measure- ment of the temperature in the plasma is reviewed.

Figure 2.6: Schematic representation of the three methods used for heating. 14 CHAPTER 2. INTRODUCTION TO NUCLEAR FUSION AND TOKAMAKS

2.4.1 Neutral Beam Injection One of the most reliable and commonly applied methods for plasma heating is Neutral Beam Injection (NBI). A neutral beam is created by passing hydrogen ions through a series of high-voltage grids, in order to accelerate them to high energies, after which an electron is added to the ion again in a neutralizer. The part of the beam that did not neutralize is separated by a magnetic field, while the remaining neutral hydrogen or deuterium atoms are injected into the plasma. Because of the high speed at which they enter the plasma, the neutral particles collide with the plasma particles and then become ionized. The resulting ions and electrons are now part of the plasma, while the neutralized plasma particles leave the plasma or get ionized again at subsequent collisions. Energy transfer between particles is much more efficient with approximately equal mass of the con- cerned particles, like ion to ion energy transfer, but nevertheless, most of the energy of the neutral atoms is at first transferred to the electrons in the plasma, because these electrons have a higher veloc- ity, and therefore, a higher probability of collision with the neutral beam particles. As a result of these collisions, the neutral particles are slowed down and subsequent collisions are more likely to occur with the equal mass ions. The energy transfer from the neutral beam to the plasma particles by the initial and subsequent collisions causes a rise of temperature in the plasma.

The neutral beam can be injected perpendicular or more tangential to the magnetic field with a rela- tively large deposition width compared to for example ECRH. At perpendicular injection the resulting ions are subject to losses arising from a ripple in the magnetic field [32]. This ripple is a result of the non-axisymmetric shape of the tokamak which is due to the finite number of toroidal field coils. Furthermore, in smaller tokamaks the neutral beam is not completely absorbed in the plasma and can cause severe damage to the inner wall. A more tangential injection of the beam intercepts these prob- lems. Further, NBI can also produce significant current drive when the beam is injected tangential to the plasma current, because the high-energy beam ions collide primarily with the plasma electrons. However, tangential injection is more difficult to realize, since the achievable injection angle is re- stricted by the configuration of the toroidal field coils of the tokamak.

Plasma heating by exclusively using NBI is not sufficient to obtain nuclear fusion in a tokamak. An- other important method of heating plasma is ohmic heating, which is described in the next subsection.

2.4.2 Ohmic heating Ohmic heating is generated by the toroidal plasma current, due to the finite conductivity of the plasma. The conductivity of the plasma is formulated by the electrical resistivity, which is according to Ohm’s Law defined by:

E η = . (2.5) j

mev Inserting the formulae for the electrical field, E = , and for the current density, j = neev, results τce in the following definition for the electrical resistivity [32]:

me η = 2 . (2.6) nee τc

Here, me, ne and e represent the electron mass, density and charge respectively. The time for mo- mentum loss by the electrons τc is roughly estimated by putting τc = τe, with τe the electron collision time, which is the characteristic time for the collisional relaxation process:

2 1/2 3/2 ε0me Te τe = 3(2π)3/2 4 (2.7) nee lnΛ. 2.4. ACTUATORS AND SENSORS 15

r Here, ε0 represents the inverse aspect ratio R and Te the electron temperature. Inserting this equation in (2.6) for τc gives:

e2lnΛ η = . (2.8) 3/2 2 −1/2 3/2 3(2π) ε0me Te From (2.8) it follows that the electrical resistivity is proportional to T by:

− 3 η T 2 (2.9) ∼ In other words, the resistivity of the plasma decreases with increasing temperature. The rate of ohmic heating can be defined as the power dissipated into heat per unit volume, and calculated by the elec- trical resistivity η times the current density j squared:

2 PΩ = ηj . (2.10)

From (2.9) and (2.10) it follows that the heating effect produced by the flow of current through the plasma is significantly reduced with higher temperatures. Consequently, additional heating is required to make the ignition of the fusion process possible.

2.4.3 RF heating One of the main methods used for heating to ignition temperatures is the resonant absorption of radio frequency electromagnetic , also known as RF heating.

Electromagnetic waves are a self-propagating oscillating wave of electric and magnetic fields with prop- agation in the E B direction. The electromagnetic wave is transversal, i.e. orthogonal to the electric and magnetic field,× and polarisable, i.e. the orientation of the fields is arbitrary with respect to the propagation. The distance between two adjacent troughs or crests of a wave is called the wavelength λ and the frequency of a wave f is its rate of oscillation, from which the wave velocity v can be defined by:

v = fλ (2.11)

As waves cross boundaries between different media, their speeds and wavelengths change but their frequencies remain constant. The electromagnetic spectrum classifies electromagnetic radiation with increasing wavelength, or decreasing frequency, in gamma rays, X-rays, ultraviolet, visible spectrum, infrared, microwaves and radio waves (FM, AM, long radio waves).

RF heating is the process in which the radiation of microwaves and radio waves are resonantly ab- sorbed by the particles in the plasma. This energy transfer can only occur if the frequency of the electromagnetic waves correspond to the frequency of the motion of the electrons or ions. The move- ment of an electron in a magnetized plasma is explained next.

An electron in a static and uniform magnetic field, for example generated by the toroidal field coils, will gyrate around the magnetic field lines due to the Lorentz force. The angular frequency of this cyclotron motion is known as the electron gyrofrequency or electron cyclotron frequency ωe, and can be defined as the number of rotations per second at which the electrons rotate around the field lines [32]:

eB ωe = . (2.12) me 16 CHAPTER 2. INTRODUCTION TO NUCLEAR FUSION AND TOKAMAKS

The symbol e represents the elementary charge and m is the electron mass at low of the cyclotron frequency. The total magnetic field strength B is mainly driven by the toroidal field. The inhomogeneous character of the toroidal magnetic field in a tokamak Bθ is essentially inversely pro- portional to the major radius R, see (2.13), where R0 and B0 represent the major radius and toroidal field at the center respectively.

B0R0 1 Bθ(R) = Bθ (2.13) R → ∼ R Therefore, due to the non-uniformity of the magnetic field in the plasma and the dependency of the electron cyclotron frequency on the magnetic field, the variety of electron cyclotron frequencies, typi- cally about a few hundreds of GHz, allows many different radio frequency heating schemes [32].

The preceding heating method at which an ionized plasma is heated by superimposing a high-frequency electromagnetic field at the electron cyclotron resonance frequency, is known as Electron Cyclotron Resonance Heating (ECRH). The ECRH installation typically consists of a gyrotron for the radiation of the electromagnetic waves with variable frequencies and phase on different power levels into the plasma. Since the wavelength of the high-frequent electron cyclotron frequency is relatively small, the location of the power deposition attended with ECRH can accurately be controlled within a deposition width of about a centimeter. Another useful property of ECRH is that the heating power can be rapidly modulated and is deposited directly into the electrons. These properties make electron cyclotron heat- ing a very valuable research tool for energy transport studies. In addition to heating, electron cyclotron waves can be used to drive current by accelerating electrons only those electrons circulating in a par- ticular toroidal direction [32].

Ion Cyclotron Resonance Heating (ICRH) is identical to ECRH, except that the ions are accelerated by resonant absorption of microwaves. Ions have a bigger mass and therefore, the ion cyclotron frequency is lower and about hundreds of MHz. Consequently, the wavelength is longer, which prevents the use of ICRH very locally. Because of the lower frequency, its easier to obtain high-power sources. Generally, helium is added to the plasma and heated instead of heating the hydrogen directly, because this is more efficient.

2.4.4 Electron Cyclotron Emission diagnostic The gyrating movement of the electrons leads to the emission of electromagnetic radiation. The rela- tions given in (2.12) and (2.13) form the basis of the Electron Cyclotron Emission (ECE) temperature measurements. The location of the origin of the emitted radiation is determined from the measured harmonics of the specific cyclotron resonance angular frequency:

neB0R0 ωe = , (2.14) meR where n is the number and me and e the electron mass and charge respectively. Hence, for fixed harmonic number, each unique major radius R corresponds to a unique cyclotron resonance frequency ωe. For optically thick plasmas there is a direct relation between the measured intensity of the emission In(ωe) and the local electron temperature Te(R) at location R [32]. A plasma is said to be optically thick when it behaves like a blackbody source and the emitted radiation is substantially re-absorbed by the plasma. The optical depth depends on the electron density and temperature, and decreases with increasing harmonic number. Therefore, for ECE measurements especially the first two harmonics of the cyclotron resonance angular frequency are observed to be able to determine Te(R). The measured intensity of the emission is related to the local electron temperature at a unique major radius, and resulting unique cyclotron resonance frequency, by:

2 ωe Te(R) In(ω) = . (2.15) 8π3c2 2.5. RESEARCH OBJECTIVE 17

The intensity of the radiation depends, among others, on the angle between the direction of emission and the confining magnetic field.

2.5 Research objective

The main focus of this master project lies at the relatively small tokamak TEXTOR, which is located in Jülich, Germany. Experiments executed on TEXTOR include significant research with different mate- rials for the plasma facing surfaces. Sawtooth oscillations are also critically observed and investigated at TEXTOR. In Subsection 2.5.1 the aim of controlling the sawtooth period is explained, followed by the control approach on TEXTOR in Subsection 2.5.2. Finally, the objective of this thesis is described in Subsection 2.5.3.

2.5.1 Control of the sawtooth period As already mentioned in Subsection 2.3.3, the sawtooth instability has both positive and negative ef- fects on the stability of the plasma. The temperature of the center of the plasma is limited, due to the very fast transport of energy and particles from the center to the outside of the plasma. Though, this fast transport of particles also removes the helium ash from the center, preventing dilution of the plasma. Another important negative effect of the sawtooth instability is that the crash triggers the undesired NTM’s, which can abruptly end the discharge with considerable consequences.

The sawtooth period and the crash size are obviously closely related to the period of occurrence of the aforementioned effects. Therefore, by controlling the period of the sawtooth, and the corresponding size of the crash, the positive and negative effects can also be controlled.

Real time sawtooth period adaption using ECCD has already been proven to work in different toka- maks, like TCV and ASDEX [30]. ECCD can easily and quickly change the EC beam injection angle and therefore the localization of the beam deposition by adjusting the angle of the launcher mirror [29]. By directly injecting a current with power P inside or outside the (q=1) surface in the plasma, the sawtooth period can be controlled, as a result of the increased or decreased magnetic shear.

2.5.2 TEXTOR The gyrotron at TEXTOR has a maximum power of approximately 800kW, for a frequency pulse of a few seconds and a frequency of 140GHz. The ECCD installation also possesses an ECE receiver to measures the electron temperature in the plasma. This is done by measuring the second harmonic of the cyclotron frequency n = 2 at six measuring channels with the frequencies: 132.5, 135.5, 138.5, 141.5, 144.5, and 147.5GHz. The channels can be positioned accurately by changing the mechanically steerable mirror at the end of the transmission. Figure 2.7 shows a graphical representation of this reconstruction of the ECCD installation and a cross-section of the plasma in TEXTOR. 18 CHAPTER 2. INTRODUCTION TO NUCLEAR FUSION AND TOKAMAKS

Figure 2.7: Schematic representation of the ECCD installation and the six measuring channels [13].

2.5.3 Detection algorithm for sawtooth crashes The period of the sawtooth can be obtained by detecting a certain repeating feature of the sawtooth oscillation such as the sawtooth crash. An algorithm should be designed which reliably detects these crashes over a wide range of sawtooth periods, crash sizes and sawtooth shapes. False detection will result in a wrong output of the controller, and consequently the negative effects of the sawtooth can be triggered, which can result in an unstable plasma or even a sudden end of discharge. The accuracy of the algorithm can be defined as the percentage of correctly detected crashes with respect to the total number of crashes within a certain time range. The reliability of the obtained results depends on the presence of any misleading ambiguous outputs of the algorithm.

In this master thesis an algorithm is designed to accurately determine the sawtooth period of sawtooth signals from TEXTOR. This is done by means of a sawtooth crash detection algorithm. Chapter 3

Analysis methods of the sawtooth oscillation

A signal can be analyzed in different domains, at which each domain representation gives information about signal characteristics corresponding to that analysis technique. For example, the time domain representation gives insight on the periodic behavior of the signal, while the frequency transformation of the signal shows its frequency content. The most common technique to transform a signal from the time domain to the frequency domain is the Fourier Transform, named after the founder Joseph Fourier (1768 - 1830). Frequency domain analysis has a serious drawback. Due to the transformation to the frequency domain, time information is lost. When looking at a Fourier transform of a signal, it is impossible to tell when a particular event took place. The Short-time Fourier Transform is a time-frequency analysis method, which gives more insight in the frequency content of the signal at different time units, but it is still very restricted because of the constant time and frequency resolution. Wavelet Transform, however, is a multi-resolution analysis technique in the time-frequency domain and is therefore more suitable for non-stationary signals. The Short-time Fourier Transform and the Wavelet Transform are examples of linear time-frequency representations, where the signal is represented by a linear combination of different (basis) functions. Signals can also be represented quadratically in the time-frequency domain by use of the Cohen’s Class Distribution functions, which is also discussed here. Which analysis method is applicable and the most suited for a signal completely depends on the signal and the characteristics of the signal to be investigated. In the last subsection, the different analysis techniques are investigated for real-time application, especially crash detection, on the sawtooth oscil- lation occurring in fusion experiments.

19 20 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

3.1 Time domain analysis

By looking at the sawtooth signal in the time domain it is clear that the spread of the samples at the crash is higher than at the ramp part, see Figure 3.1.

Figure 3.1: Graphical representation of the spread of the samples at the ramp and crash part of a sawtooth signal.

Therefore, a useful method to determine the period of the sawtooth is by the comparison of the mea- sure of statistical dispersion with a threshold, and in that way identification of the moment of crash and the corresponding period. Several statistical operations use the statistical dispersion are examined, such as the difference be- tween subsequent samples and the average and standard deviation of a data set of the signal. In the comparison of the statistical operations, the accuracy of the crash moments corresponding to the ap- plication of each of the operations is important, besides the ability to distinct a significant difference between crash and ramp samples.

3.1.1 Difference filter The simplest method to investigate the statistical dispersion of a sampled time signal x[n] is by apply- ing a discrete difference filter. The difference filter (3.1) subtracts two data samples from each other, where the input samples can be successive samples, or multiples of an integer number a.

yD[n] = x[n] x[(n a)] for n = 1, 2, ..., . (3.1) − − ∞

A high output yD[n] indicates a large difference between subsequent samples, which will be the case at the crash part of the sawtooth signal. The variable a defines the order of the filter. High values for a result in an inaccurate estimation of the moment of crash, indicated by the time resolution:

a + 1 δtD = . (3.2) fs

Here, fs represents the sampling frequency.

3.1.2 Averaging filter + difference filter Another method to emphasize the large statistical dispersion in the crash part of the sawtooth oscilla- tion, compared to the ramp part, is by applying an averaging filter followed by a difference filter. The averaging filter determines the mean µ[b] of a data set b with B samples[23]:

bB 1 X µ[b] = x[n] for n = 1, 2, ..., . (3.3) B ∞ n=(b−1)B+1 3.2. FOURIER TRANSFORMS 21

A difference filter (3.4) determines the difference between successive averages yAD[b] at outputs b, which is related to the sample number by: n = bB for b = 2, 3, ....

yAD[b] = µ[b] µ[b a] for b = 2, 3, ..., . (3.4) − − ∞ The time resolution of the average of a data set with B samples is given by:

B δtA = . (3.5) fs The time resolution of an averaging filter in combination with a difference filter equals the sum of both time resolutions:

B + a + 1 δtAD = . (3.6) fs

3.1.3 Standard deviation + difference filter The most common measure of dispersion is the standard deviation σ[b], which can be defined for a discrete random variable x[n] as the root-mean-square (RMS) deviation of its values from the mean.

v u bB u 1 X σ[b] = t (x[n] µ[b])2 for n = 1, 2, ..., . (3.7) B − ∞ n=(b−1)B+1

A low standard deviation indicates that the data points are on average close to the mean of the regarded data set, while high standard deviation indicates a spread of the data over a large range of values. The difference between the standard deviation of subsequent data sets can be determined by:

ySD[b] = σ[b] σ[b a] for b = 2, 3, ..., . (3.8) − − ∞ The time resolution of an algorithm, which calculates the standard deviation of a signal and then applies a difference filter, is equal to the time resolution of the averaging filter in combination with the difference filter:

B(a + 1) δtSD = δtAD = . (3.9) fs Time domain algorithms based on the statistical dispersion methods described here give insight on the occurrence of events in signals. This is especially meaningful for non-stationary signals. In the next section the frequency domain representations of the Fourier Transforms are discussed, including the time-frequency domain analyzing Short-time Fourier Transform.

3.2 Fourier transforms

Fourier analysis provides insight into the periodicities in data by representing the signal using a lin- ear combination of sinusoidal components with different frequencies. Each arbitrary function can be represented as the sum of sine and cosine functions 1, in which the amplitude and phase of each sinusoidal component in the sum determines the relative contribution of that frequency component

1This statement holds for all signals as long as the Dirichlet conditions hold. 22 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION to the entire signal.

There are four categories of Fourier analysis techniques to transform a signal from the time domain to the frequency domain. Each of them can be applied to a different kind of signal, which can be either continuous or discrete, and the signal can be either periodic or aperiodic. The combination of these two features generates the four Fourier Transforms described in Table 3.2.

Transformation Time domain Frequency domain Fourier Series Continuous, periodic (T ) Discrete, aperiodic Continuous Fourier Transform Continuous, aperiodic Continuous, aperiodic Discrete-time Fourier Transform Discrete, aperiodic Continuous, periodic (fs) Discrete Fourier Transform Discrete, periodic (N) Discrete, periodic (N)

Table 3.1: Overview of the 4 Fourier Transforms.

All of these Fourier transforms use sinusoids to analyze the frequency content of the signal. The sine and cosine waves extend from minus infinity to infinity and as a result all the signals, including the finite length sampled signals, are treated like infinity long signals. How this is done depends on the type of Fourier analysis and will be explained later on.

3.2.1 Fourier Series Pure periodic-continuous signals, like sine waves or any other that repeats itself in a regular pattern from minus infinity to infinity with period T , can be transformed to the frequency domain by determining the correlation between the analyzed signals and the sine and cosine waves with a certain frequency: ∞ a0 X m m x(t) = + [am cos(2π t) + bm sin(2π t)]. (3.10) 2 T T m=1

The (correlation) coefficients an and bn are defined as: T T Z 2 m am = x(t) cos(2π t)dt for m = 0, 1, 2, ... (3.11) 2 T T − 2 T T Z 2 m bm = x(t) sin(2π t)dt for m = 1, 2, ... (3.12) 2 T T − 2 The equations above are only valid for real variable t. A more concise formula can be obtained by using Euler’s formula, see Appendix A.1, to transform the real function (3.10) into a complex function with complex exponentials:

∞ X j2π m t x(t) = cme T , (3.13) m=−∞ with: T Z 2 1 −j2π m t cm = x(t)e T dt. (3.14) T T − 2

The modified function is now a function of the Fourier coefficients cm, which are related to am en bm via:

am = cm + c−m for m = 0, 1, 2, ... (3.15)

bm = j(cm c−m) for m = 1, 2, ... (3.16) − 3.2. FOURIER TRANSFORMS 23

In signal processing, the formal notations for these time and frequency dependent functions, used for the transformation of periodic-continuous signals to the frequency domain, is for the Fourier Series (FS):

T Z 2 1 −j2π m t XFS[m] = xFS(t)e T dt, (3.17) T T − 2 and for the inverse Fourier Series: ∞ X j2π m t xFS(t) = XFS[m]e T , (3.18) m=−∞

m where the frequency component fm can be defined as: fm = T . The coefficients XFS(m) can be obtained by integrating the function after multiplication with different frequency (co)sine waves. For example, multiplication by the unit vector e−j2πfmt, counteracts only the rotation of the signal com- ponent with negative frequency fm, such that it integrates to a finite value; the amplitude of the con- cerning frequency. The other frequencies are not affected by the exponential e−j2πfmt and integrating these rotating vectors over periodic time T results in amplitudes of zero. The physical interpretation of the negative frequency is explained in Appendix A.2. The periodicity in the time domain results in 1 2 a discrete frequency domain with: fm = 0, T , T , .... This can be explained by the fact that the sine waves should fit exactly in the time period±T and± therefore, should be multiples of the of the signal. Figure 3.2 shows a periodic-continuous signal in the time-domain. Signals in the frequency domain are usually represented in a power spectrum, see Appendix A.3.

Fourier Series 2

1.5

1

0.5

0 |x| [−] −0.5

−1

−1.5

−2 0 0.5 1 1.5 2 2.5 3 Time [s]

Figure 3.2: Periodic-continuous signal

As already mentioned before, the (co)sine waves extend from minus infinity to infinity, while the an- alyzed signal can be a finite length signal. Fitting the infinite long sinusoids on a finite signal is not possible. Fourier Series handles this problem by interpreting the finite signal as a single period of an infinite long periodic signal. In other words, the left end of the signal is considered as it were connected to the right end of the signal. If the transition between both ends is smooth, the periodic- ity of the original signal will continue and the FS results in a solid frequency domain representation of the signal. However, if the connection between both ends is not smooth, undesirable effects will occur, which can give a distorted image of the frequency content of the signal. For example, with a rough transition between sequencing periods, the Fourier Series of a simple waveform like cos(2πft) results in non-zero values at frequencies other than f. This phenomenon is also known as leakage. Another example with a rough transition between subsequent periods is when the signal recognizes 24 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION the periodic pattern of the extended signal and as a result, the corresponding frequency will have an incorrect large amplitude.

Leakage can also occur if the frequency spectrum of a signal, obtained by using Fourier Series, is modified before transforming it back to the time domain. For example, frequencies can be deleted by applying filter techniques. Frequencies can also be changed in amplitude or phase. These operations can create a continuous frequency spectrum. This results in sines which do not exactly fit in the period T and hence, the time domain signal is too long to fit in one period. The part of the signal that does not fit in the period spills over to the adjacent periods, or in other words, this extensive part of the signal leaks to the next period. The modified signal in the frequency domain leads to an incorrect time domain signal.

3.2.2 Continuous Fourier Transform

Aperiodic-continuous signals are signals which extend from minus to plus infinity without repeating in a periodic pattern, see figure 3.3 for a time domain representation.

Continuous Fourier Transform 2

1.5

1

0.5

0 |x| [−] −0.5

−1

−1.5

−2 0 0.5 1 1.5 2 2.5 3 Time [s]

Figure 3.3: Aperiodic-continuous signal

The frequency spectrum of these signals x(t) can be obtained by applying the so called Continuous Fourier Transform (CFT):

Z ∞ −j2πft XCFT (f) = xCFT (t)e dt. (3.19) −∞

The inverse transformation can be obtained by applying the inverse CFT, defined as:

Z ∞ j2πft xCFT (t) = XCFT (f)e df. (3.20) −∞

Finite length aperiodic continuous signals should be infinite to be able to perform an Fourier Trans- form of the signal. Therefore, the finite signal is treated by the CFT like an infinite long signal, with zeros added from minus infinity to the time the signal starts and from the end time of the signal till infinity. The aperiodic behavior of the signal, results in a continuous power spectrum instead of the leakage-sensitive discrete power spectrum of the FS. 3.2. FOURIER TRANSFORMS 25

3.2.3 Discrete-time Fourier Transform In digital data processing continuous time functions are sampled at discrete equally spaced points in time. These data samples can be divided in aperiodic and periodic signals, like the continuous sig- nals discussed before. In this subsection the Fourier transformation of aperiodic-discrete signals is reviewed, using the Discrete-time Fourier Transform. See Figure 3.4 for a time domain representation of this signal category.

Discrete−Time Fourier Transform 2

1.5

1

0.5

0 |x| [−] −0.5

−1

−1.5

−2 0 0.5 1 1.5 2 2.5 3 Time [s]

Figure 3.4: Aperiodic-discrete signal

Aperiodic-discrete signals are non-repeating signals, which are only defined at discrete time moments t = nTs, corresponding to sample number n, with a time interval between sequencing samples of Ts, and a sampling frequency fs = 1/Ts. The corresponding frequency domain equivalent of such a signal can be determined by the Discrete-time Fourier Transform (DTFT):

∞ X −jnθ XDTFT (θ) = xDTFT [n]e . (3.21) n=−∞

The inverse Discrete-time Fourier Transform can be defined as: Z π 1 jnθ xDTFT [n] = XDTFT (θ)e dθ. (3.22) 2π −π

Here, θ represent the normalized frequencies, which are actual frequencies as multiples of the sample rate:

θ = 2πf/fs. (3.23)

When the Fourier Transform of a discrete signal is determined, the upper limit of the frequency spec- trum is half the sampling frequency fs. Above this frequency, also known as the Nyquist frequency fN , a phenomenon known as ’aliasing’ occurs, where the higher frequencies are incorrectly identified as lower frequencies, see Appendix A.4. As a result,the frequency spectrum becomes periodic above the Nyquist frequency, with infinite repetition of the spectrum captured between minus and plus fN .

Although the analyzed signal here is a discrete-time signal, it is still impossible to calculate the DTFT in a computer algorithm, because of the infinite number of sinusoids required to transform an aperi- odic signal. 26 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

3.2.4 Discrete Fourier Transform Periodic-discrete signals can be transformed to the frequency domain, using the Discrete Fourier Transform (DFT). The DFT is a discrete version of the Fourier Series and therefore, also the DFT views the analyzed discrete signal as to be a single period of an infinity long periodic signal, see Figure 3.5. Also, the same undesirable effects occur as a result of this periodicity. The Discrete Fourier Transform and its inverse can be defined as:

N−1 X −j2π m n XDFT [m] = xDFT [n]e N m = 0,...,N 1, (3.24) n=0 −

N−1 1 X j2πm n x [n] = X [m]e N n = 0,...,N 1. (3.25) DFT N DFT m=0 −

Here, n represents the sample number and N the total number of samples. The frequency spectrum of the DFT is, like the DTFT spectrum, periodic because of the sampled input signal. The periodic nature of both the time and frequency domain of the DFT, results in a finite number of Fourier coef- ficients at the frequencies: 0, fm, 2fm, ..., FN , where fm represents the fundamental frequency ± ± ± and FN the Nyquist frequency. The computational complexity is significantly reduced with this finite range of coefficients and this makes the Discrete Fourier Transform numerically attractive above the other Fourier forms.

Discrete Fourier Transform 2

1.5

1

0.5

0 |x| [−] −0.5

−1

−1.5

−2 0 0.5 1 1.5 2 2.5 3 Time [s]

Figure 3.5: Periodic-discrete signal.

Fast Fourier Transform Computing the Fourier coefficients at all integer multiples of the fundamental frequency, between zero and the Nyquist frequency, is still an unnecessary time-consuming job, since a lot of the computed amplitudes at higher frequencies are redundant. The Fast Fourier Transform (FFT) only calculates the coefficients at N intervals with: N = 2k for k = 0, 1, 2, ..., and is therefore much more efficient.

The major drawback of all of the Fourier Transforms discussed so far is the loss of time information, when transforming a signal to the frequency domain. This is not a substantial problem for stationary periodic signals, but most signals to be analyzed contain numerous non-stationary features and conse- quently, these signals should be analyzed in both time and frequency domain. In the next subsection a time-frequency domain analysis technique using Fourier transforms is presented. 3.3. WAVELET ANALYSIS 27

3.2.5 Short-time Fourier Transform Analysis of a signal in both time and frequency domain is possible by applying the Fourier Transform to a small time interval, called a window, and shifting this window along the time axis of the signal. This time-frequency analysis technique with ’windowing’ is called the Short-Time Fourier Transform (STFT) and is widely used for analysis of non-stationary signals. The time-frequency transformed sig- nal is naturally represented in a spectrogram, which is the square of the magnitude of the STFT.

Equation (3.26) represents the discrete Short-time Fourier Transform [19].

l−1 X −j2π m n XSTFT [n, m] = xSTFT [k]w[k n]e N m = 0, 1,...,N 1. (3.26) − − k=0 The discrete STFT is derived by computing the DFT, or more generally the FFT, of the signal, multi- plied by a symmetric window function w[k n], with a window length of l samples, being zero except for (l 1)/2 n +(l 1)/2, and the− center of the window positioned at sample number n. The− choice− of the≤ window≤ length− depends strongly on the objective of the time-frequency analysis of the signal, since the time and frequency resolutions are both dependent on the window length l. The frequency resolution of the STFT is defined as:

lfs δfSTFT = . (3.27) 2 The time resolution of the STFT can be defined as half the duration of the window:

l 1 δtSTFT = − . (3.28) 2fs It is not possible to have both a good time and frequency resolution, because a small window results in a good time resolution but also in a bad frequency resolution. Applying a larger window results in a deteriorating time resolution but an increased frequency resolution. This junction between the time and frequency resolution is known as the Heisenberg inequality [14], illustrated in Figure 3.6, and it states that the product of the time resolution and the frequency resolution is constant. The STFT applies a window with constant window length and therefore, this window length should be properly chosen, compromising between a good time and a good frequency resolution. Frequently used win- dow functions are for example the Hamming and Hann window [19].

The Short-time Fourier analysis of a signal with several non-stationary features, like drifts, trends and the beginning or end of an event, is not satisfying because of the constant window width for all frequencies. In the next section an analysis technique known as the Wavelet Analysis is described, which uses a small window and a corresponding fine time resolution for the analysis of the higher frequencies, and a larger window to be able to identify the lower frequencies with a coarser time resolution.

3.3 Wavelet analysis

In 1982 the geophysicist J. Morlet introduced the Wavelet Transform as a method for the time-frequency analysis of a signal. The Wavelet Transform allows multi-resolution analysis, by analyzing the differ- ent frequencies with varying window width. Figure 3.6 shows this multi-resolution plane, which still corresponds to the Heisenberg inequality. Using multi-resolution analysis, lower frequencies can be analyzed with a high frequency resolution, while the higher frequencies can be clearly identified at small time intervals. 28 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION Frequency Frequency

Time Time (a) Short-time Fourier Transform (b) Wavelet Transform

Figure 3.6: The fixed time-frequency resolution plane of the STFT and the variable time-frequency resolution of the WT, both with constant product. ∆f∆t

In Subsection 3.3.1 the Continuous Wavelet Transform is defined and Subsection 3.3.2 introduces the discretized version of this transform.

3.3.1 Continuous Wavelet Transform The Continuous Wavelet Transform (CWT) is like the STFT a linear time-frequent transformation technique, where the CWT uses so-called wavelets instead of sinusoids as analyzing functions, to transform the signal from the time domain to the time-frequency domain.

Mathematical description Equation (3.29) defines the Continuous Wavelet Transform of a signal x(t):

Z ∞ ∗ XCWT (τ, s) = x(t)ψτ,s(t)dt, (3.29) −∞ where:

1 t τ  ψτ,s(t) = ψ − , (3.30) p s s | | represents the wavelets and ∗ means operation of complex conjugate. The wavelet basis functions ψτ,s(t) are dilated and translated versions of a source function, called the mother wavelet ψ. The dila- tion or contraction of the mother wavelet is indicated by scale s and the translation along the signal by the translation parameter τ. The coefficients XCWT (τ, s) outline the correlation between the analyzed signal and the scale and translation.

In wavelet analysis, the time-frequency transformed signal is represented in a time-scale plane, known as the scalogram, where each scale represents a certain frequency band centered around a central frequency fc. This seems natural, since wavelets are waves composed of a range of frequencies with a central frequency, instead of the single frequency sinusoids, attended with the STFT. The relationship between the scale, the central frequency and the frequency band depends on the mother wavelet. For example, for the well-known Moirlet wavelets this relationship can be given by:

f f = c . (3.31) s 3.3. WAVELET ANALYSIS 29

Choosing the scale of the wavelet not only allocates the central frequency, but also the window width, this in contrast to the fixed pre-allocated window width of the Short-time Fourier Transform. A large scale corresponds to a global view of the signal with a large window and consequently, a fine frequency resolution, which is necessary for the analysis of the lower frequencies. A small scale results in a fine time resolution and a high central frequency. For the Morlet Wavelet the time resolution of the scalo- gram is related to the scale and frequency by [4]:

f ∆ δt (f) = s∆ = c . (3.32) DWT f

Here, ∆ 2 represents the effective half length of the complex Morlet wavelet.

Choice of wavelets Since the beginning of the wavelet theory, a number of wavelet families have been invented, like the Haar Wavelet, the Morlet wavelets and the extensive Daubechies wavelets. Not every function can function as a wavelet. There are two important restrictions which a wavelet must satisfy.

The first restriction is the admissibility condition, which states that the integral of the squared Fourier Transform of a wavelet ψ(f), must satisfy the following condition:

Z ∞ ψˆ(f) 2 | | df < , (3.33) f ∞ −∞ | | where ψˆ is the Fourier transform of ψ(t). Equation (3.33) implies that the Fourier transform of ψ(t) vanishes at zero frequency:

ψˆ(f) 2 = 0. (3.34) | | f=0 Two properties of wavelets can be obtained from (3.34): the spectrum of the wavelet should correspond to those of a band-pass filter and the wavelet must be oscillatory. A function is said to be oscillatory when the average output of the function equals zero, which results from the zero amplitude at zero frequency:

Z ∞ ψ(t)dt (3.35) −∞ The oscillatory behavior is a direct result from restrictions on the scaling function.

The second restriction on a wavelet function is known as the regularity condition. Information about the regularity condition and the concept of vanishing moments can be found in [25]. It is not discussed here.

3.3.2 Discrete Wavelet Transform The CWT calculates the coefficients at all possible scales and translation parameters, by continuously shifting the continuously scalable wavelet function over a signal. Obviously, this is an unnecessary time-consuming job, because of the calculation of all the redundant wavelet coefficients. Fortunately,

2 The effective half length of ψ(τ) can be obtained from the bandwidth parameter Fb, by requiring that 2 e(−∆ /Fb) = 10−3[4]. 30 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION there are more efficient methods to transform a signal to the time-frequency domain using wavelets.

Discretization of the CWT; the Wavelet Series The CWT is usually calculated by taking discrete wavelets, which are wavelets with discretized values for the scale s and the translation τ. When discrete wavelets are used to transform a continuous signal, the result will be a series of wavelet coefficients, and it is referred to as the Wavelet Series decomposi- tion.

Taking each integer number for the scale parameter is unnecessary for the identification of the lower frequencies, and therefore, the scale parameter s is usually discretized on a logarithmic grid (3.36), to significantly reduce the computational time, while still being able to clearly identify the lower frequen- cies. For the logarithmic rule, naturally s0 = 2 is taken, which results in dyadic grids; a very natural choice for computers. The sampling rate can be decreased at lower frequencies, thus at higher scales, as long as the Shannon or Nyquist Sampling Theorem is met. 3 Consequently, after discretization of the scale axis, see (3.36), the time axis is discretizised with respect to s, by reducing the sampling rate at every following scale level by a factor two, see (3.37)

j s = s0 for j = 1, 2,..., (3.36)

j τ = ks0τ0 for k = 1, 2,.... (3.37)

The signal is said to be downsampled by a factor two at each following level j, where at each level half of the data is discarded and the sampling frequency is cut in half. Inserting the discretized parameters in (3.30), the equation for discrete wavelets is obtained:

j 1 t kτ0s0 ψj,k(t) = ψ( − j ) for j, k = 0, 1, 2, ... (3.38) q j s0 s0

The main disadvantage of transforming a signal with discrete wavelets, is that the logarithmic grid of the scale and time axis cancel the shift invariance of the transform. In other words: the wavelet trans- form of a time-shifted version of a signal is not simply the shifted version of the wavelet transform of the original signal. Furthermore, although reducing the number of wavelet coefficients reduces the computational time significantly, it also increases the sensitivity to noise of the transform.

Scaling function Translating the wavelets along the time axis covers the whole time domain signal. The frequency spec- trum of the signal should also be completely covered and this is done by the dilation of the wavelets, so by the different scales. From the admissibility condition (3.33) it followed that wavelet functions have a bandpass like frequency spectrum, where each scale corresponds to a certain frequency range of the passband. For a dyadic grid of the scale and time axis, the spectrum of a wavelet shifts by a factor two and the bandwidth shrinks by a factor two, with a duplication of the scale, see Figure 3.7. This means that even with the use of discrete wavelets, still an infinite number of wavelets is needed to cover the whole frequency spectrum of a continuous signal.

By introducing a so-called scaling function, this problem of covering the spectrum all the way down to zero frequency with wavelet spectra can be solved. The scaling function is very similar to the wavelet function, but with a low-pass filter frequency spectrum, which covers the spectra from zero frequency

3This theorem claims that the sampling frequency of a signal should at least be higher then twice the highest frequency in the signal (the Nyquist frequency), otherwise these higher frequencies can incorrectly be interpreted as lower frequencies, also known as aliasing. 3.3. WAVELET ANALYSIS 31

Ψ4 Ψ3 Ψ2 Ψ 1 Amplitude

Frequency

Figure 3.7: Overlapping wavelet spectra for a dyadic grid of the scale and time axis.

up to the central frequency, corresponding to a certain scale s. The width of the spectrum of the scaling function is directly related to j, the power of the highest analyzed scale. For the reconstruction of the signal the number of analyzed scales is not important, since the low-pass scaling function is part of the reconstruction. Not all of the wavelet families are associated with such an additional scaling function. For example, the wavelet function of the Morlet wavelets has an explicit expression and the scaling functions do not exist[2]. Consequently, analysis with the Morlet wavelets is limited to the CWT. The oscillatory shape of wavelets results from the scaling function, and therefore, Morlet wavelets are not oscillatory. Although these wavelets do not meet the admissability condition stated in Section 3.3.1, Morlet wavelet are nevertheless considered to be real wavelets.

The wavelet transformation method described above, with use of discrete wavelets and a scaling func- tion, can be used for both continuous and discrete time signals, but for the discrete signals naturally the Discrete Wavelet Transform (DWT) is applied. This analyzing method makes use of filters banks and as a result, computing the DWT is faster than the CWT.

Filter banks The DWT uses filter banks for the analysis and synthesis of signals in the time-frequency domain. A filter bank consists of low- and highpass filters, which separate a signal into frequency bands, just like the discretized wavelet. The discrete filters are distributed among an analysis and a synthesis bank, see Figure 3.8.

In the analysis bank the original signal is filtered by a low- and high-pass filter, which results in two signals with the same amount of samples as the original signal but with only half the frequency con- tent. The low-pass filter corresponds to the aforementioned scaling function and the high-pass filter to a wavelet with a certain scale. After cutting the sample rate in half, by downsampling the output of the filters by two, the coefficients attended with the analyzed frequency bands are obtained. The wavelet coefficients, acquired from the high-pass filtered signal, contain valuable detailed information about the amplitudes of the frequency band, corresponding to the scale of the wavelet. This information is also known as the ’details’, while the coefficients of the low-pass filtered signal contain the ’approxi- mation’. The approximation, with the low-frequent part of the signal, is analyzed again by applying a new pair of low- and high-pass filters, downsampling this filtered signal by two and determining the coefficients. The obtained coefficients now contain detailed information about the subsequent scale 32 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

(a) Analysis bank

(b) Synthesis bank

Figure 3.8: Filter bank

level and the remaining lower frequencies in the approximation. Looking at the whole spectrum of the signal, the spectra of the individual high-pass filters correspond to the band-pass filters spectra from Figure 3.7, because at each step only half of the remaining signal is considered. The collection of high-pass filters and a low-pass filter, or, equivalently, a series of wavelets and the scaling function, can be considered as the analysis bank.

In the synthesis bank the signals are upsampled again, by adding zeros between the samples of the original signal. The upsampled signals are reconstructed by the filters in the synthesis bank, and added to achieve the original signal again. Perfect reconstruction of the original signal is only possible if the filters in the synthesis bank are accurately chosen with respect to the filters in the analysis bank.

Perfect reconstruction The filters in the analysis and synthesis bank should satisfy two important conditions for perfect re- construction of the original signal. The first condition prevents the occurrence of aliasing, associated with the down- and upsampling operations on the filtered signal. This alias cancelation condition is defined as:

L0(z)L0( z) + L1(z)L1( z) = 0. (3.39) − −

In other words, the amplified aliasing term from the analyzing low-pass filter H0( z), by the synthesis − filter L0(z), should cancel out the alias L1(z)H1( z), from the high-pass filtered part of the signal. The aliasing terms are a direct result from the reduced− sampling rate by downsampling the signal. The second condition for perfect reconstruction is:

−l L0(z)H0(z) + L1(z)H1(z) = 2z . (3.40)

This condition is also an immediate consequence from the sampling operators. It states that the over- all delay of the filter bank with these sampling operators, is twice the delay of the same filter bank without the sampling operators, in case of perfect reconstruction with an inevitable l-step delay. 3.4. COHEN’S CLASS OF TIME-FREQUENCY DISTRIBUTIONS 33

There are several methods for the design of perfect reconstruction filter banks, such as the spectral factorization, the lattice structure method and the time-domain method, see [25]. The design of the filters will not be discussed here.

In this section the continuous and discrete form of the wavelet analysis were presented. A major benefit of the wavelet transform compared to the STFT is the multi-resolution analysis, by which lower frequencies can be analyzed with a high frequency resolution and higher frequencies with a coarse time resolution. Hereby, the product of the time and frequency resolutions remain constant, due to the requirement of satisfying the Heisenberg inequality. The time-frequency analysis technique described in the next section does not have to satisfy this requirement and therefore, this technique allows perfect time and frequency resolution simultaneously.

3.4 Cohen’s class of time-frequency distributions

The time-frequency representations discussed so far, are examples of linear time-frequency represen- tations. Another class of time-frequency presentations are the energy time-frequency distributions, which are quadratic transforms of the signal, along the two variables time and frequency. In this sec- tion energy distributions are presented, known as the time-frequency distributions of Cohen’s class.

3.4.1 The energy distribution function The purpose of the energy distributions is to distribute the energy of the signal over the two variables time and frequency. According to Parseval’s theorem the energy of a signal can be defined as the integral of the squared modulus of either the signal or its Fourier transform:

Z ∞ Z ∞ 2 2 Ex = x(t) dt = X(f) df. (3.41) −∞ | | −∞ | | Where x(t) 2 and X(f) 2 can be interpreted as energy densities in respectively time and in frequency domain.| Since| we are| interested| in a combined time-frequency representation, it is natural to join both energy densities into one time-frequency energy density ρx(t, f), defined as:

Z ∞ Z ∞ Ex = ρx(t, f) dt df. (3.42) −∞ −∞

An energy density distribution ρx(t, f) should satisfy some conditions to be applicable as a time- frequency energy distribution. In the first place, the distribution should be a quadratic representation in t, as the energy is a quadratic function of the signal. Furthermore, integrating the time-frequency energy density along one variable should result in the energy density corresponding to the other vari- able. This can be phrased as the following two marginal properties:

Z ∞ 2 ρx(t, f) dt = X(f) , (3.43) −∞ | |

Z ∞ 2 ρx(t, f) df = x(t) . (3.44) −∞ | | Another valuable property is the covariance principle. This principle states that a signal preserves time and frequency shifts and is said to be covariant by translation in time and in frequency:

y(t) = x(t t0) Ey(t, f) = Ex(t t0, f), (3.45) − ⇒ − j2πf0t y(t) = x(t)e Ey(t, f) = Ex(t, f f0). (3.46) ⇒ − 34 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

This covariance principle is characteristic for the energy time-frequency distributions described in this section, known as the Cohen’s class time-frequency distributions (TFD’s).

3.4.2 Mathematical definition The formal equation of (3.41) for determining a continuous time-frequency distribution from Cohen’s Class is:

Z ∞ Z ∞ j2π(µt−τf) Cx(t, f) = Ax(τ, µ)Φ(τ, µ)e dµdτ. (3.47) −∞ −∞

Besides the absolute variables time and frequency, two new relative variables τ and µ are introduced in (3.47), which represent, the time lag (i.e. time delay) and Doppler shift4 respectively. Furthermore, Ax(τ, µ) represents the ambiguity function, which is a measure of the correlation of the signal x(t) with its translated time-frequency component. The ambiguity function Ax(τ, µ) can be determined by taking the Fourier transform of the autocorrelation function, see (3.48). The autocorrelation function is the cross-correlation function of a signal with itself.

Z ∞ ∗ −j2πµt Ax(τ, µ) = x(t + τ/2)x (t τ/2)e dt. (3.48) −∞ −

An important property of the Cohen’s Class distribution functions is that the autocorrelation functions are not limited by the Heisenberg’s uncertainty relationship and therefore allows perfect temporal and spectral resolutions simultaneously [16]. Furthermore, a two-dimensional kernel function is introduced, indicated by Φ(µ, τ). Kernel functions are functions of two variable that define an integral transform to transform an equation from one domain to another domain. An integral transform is a particular kind of mathematical operator. Ex- amples of integral transforms and kernel functions are the Fourier transforms with the exponential functions, or wavelet transforms with wavelet functions. The exponential term in Equation (3.47) is the principal a kernel function, which is necessary to transform the time-domain signals to the time- frequency domain. The kernel function Φ(µ, τ) plays an important role by masking out undesired interference terms involved with the computation of the autocorrelation function of a multi compo- nent signal. The interfering cross terms are caused by the inherent bilinear structure of the Cohen’s Class Distribution Functions, according to the quadratic superposition principle:

Cx+y(t, f) = Cx(t, f) + Cy(t, f) + 2 Cx,y(t, f) . (3.49) <{ } Many different combinations of auto-terms and cross-terms may occur, which may prevent a straight- forward interpretation of the energy distribution. However, the cross-terms also contribute to forming the distribution and the accompanying desirable properties of energy functions. Increasing the role of the kernel function reduces the high temporal and frequency resolutions. Therefore, the kernel func- tion should be properly chosen. In Subsections 3.4.4 and 3.4.5, two different distribution functions from Cohen’s Class are discussed, distinguished by their kernel function.

3.4.3 Discrete distributions of Cohen’s class The continuous versions of the distributions of Cohen’s class discussed so far can not be implemented on digital computers and therefore, some discrete definitions of (3.47) are defined for the discrete-time

4The Doppler shift is the change in frequency of a wave for an observer moving relative to the source of the waves. 3.4. COHEN’S CLASS OF TIME-FREQUENCY DISTRIBUTIONS 35

TFD’s. The most used definition is the traditional symmetric definition, introduced by Claasen and Mecklenbräucker[9]:

∞ 2 X C (n, θ) = A (τ, µ)Φ(τ, µ)ej(ξµ−2τθ). (3.50) x π x 2 τ,µ=−∞

The corresponding discretized ambiguity function can be defined as:

Z π ∗ −jξn Ax(τ, µ) = x(n + µ + τ)x (n + µ τ)e dξ. (3.51) ξ=−π −

The parameter τ is discrete, while µ is still continuous. In [9] it was shown that discretizing the mπ 5 continuous normalized frequency θ into θ = N , and then rewriting (3.50) in terms of a discrete Fourier Transform, results in an efficient equation, for which FFT algorithms are available [10].

A serious drawback of definition (3.50) is the increased probability of aliasing; the distribution func- tion Cx(n, θ) is periodic in θ with a period of π, while the frequency spectrum of x(n) has a period of 2π. The signal has to be twice Nyquist sampled, to avoid aliasing and the loss of some of the useful properties of the continuous distribution functions mentioned in Subsection 3.4.1.

By regarding the complex analytical signal, the aliasing problem can be solved, by eliminating the negative frequencies. The absence of negative frequencies prevents the occurrence of the cross- terms[16]. The most common method of generating an analytical signal is to use the frequency do- main definition[1]: compute the FFT, zero the negative frequency components, and then compute the inverse FFT[6]. This method is reliable for infinite length signals, but for real-time application the signal has to be windowed before applying the frequency domain definition. Next, the WVD of the analytical signal can be determined. This process has to be repeated for each WVD plot, since there is no simple method of overlapping the individual segments of the analytical signal. A computationally more efficient method to generate the analytical signal is to use the time domain definition[1]. This definition involves the calculation of the imaginary part of the signal by the Hilbert transform, which results in an elimination of the negative frequencies. The Hilbert transform can be implemented as an computational efficient FIR filter.

More efficient definitions for the computation of the discrete distribution functions are introduced in the last couple of decennia, from which the function introduced by Wu and Morris in 1994 seems to be the most effective. This discrete form of the distribution function can be given as follows [33]:

N−1 1 X j2π( nµ−kτ ) Cx(n, k) = Ax(τ, µ)Φ(τ, µ)e N , (3.52) 2N 1 − τ,µ=−(N−1) for (N 1) n, k (N 1), and the discrete form of the ambiguity function is defined as: − − ≤ ≤ −

N−1 X ∗ −j2π µn Ax(τ, µ) = x(n)x (n τ)e N , (3.53) n=0 − for (N 1) τ, µ (N 1). By using these definitions for the discrete distribution functions, and by zero− padding− ≤ the≤ signal− to double the number of samples in the frequency domain, the aliasing problem can be effectively eliminated for most distribution functions [33].

5This can directly be derived from 3.23 and the ratio: f = m fs 2N 36 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

3.4.4 Wigner-Ville Distribution The most common Cohen’s Class Distribution Function is the Wigner-Ville Distribution (WVD), which was first introduced in the context of quantum mechanics in 1932 by E. Wigner and in 1948 by J. Ville in signal analysis [16]. The WVD has a kernel function equal to Φ(µ, τ) = 1. This means that the quadratic representation of the Wigner-Ville Distribution Function allows a perfect time and frequency resolution simultaneously. Therefore, the WVD is a reliable function for transforming a monocomponent signal to the time-frequency domain, but less solid for multicomponent signals due to the interfering cross-terms. The general function of (3.50) reduces for the Wigner-Ville distribution to:

∞ X ∗ −j2θτ WVDx(n, θ) = 2 x(n + τ)x (n τ)e . (3.54) τ=−∞ −

Besides the perfect temporal and spectral resolution property, the WVD possesses a number of other interesting properties, which are discussed in length in [9]. In digital signal processing, the a WVD transform can only be performed on a finite length signal. To ensure finite duration signals, the Pseudo Wigner-Ville Distribution (PWVD) is introduced, which determines the WVD of a windowed time signal [16], by two windows hτ (n) and hµ(n) of length lτ and lµ respectively. By windowing the time signal the frequency resolution decreases and is limited by the window width. Besides that, these windows have no further fundamental role, unlike with the spectrogram and scalogram. The time resolution is naturally not affected by the windowing and remains equal to the sampling interval.

3.4.5 Choi-Williams Distribution Another frequently used distribution function is the Choi-Williams Distribution (CWD), which is char- acterized by a discrete kernel function defined as [3]:

µ2 Z π 2 2 (− 2 α) 1 (jξµ− ξ τ ) e 4τ µ, τ, α e α dξ . (3.55) Ψ( ) = p π 2π −π ≈ 2 τ α | | The traditional discrete form of the CWD can directly be derived from (3.50), (3.51) and inserting (3.55):

∞ µ2 (− 2 α) X ∗ e 4τ −j2θτ CWDx(n, θ, α) = 2 x(n + µ + τ)x (n + µ τ) e . (3.56) − 2p π τ τ,µ=−∞ α | | 1 In this derivation, the values of 2π Ψ(µ, τ) are neglected outside the range [ π, π] of ξ when τ = 0, according to [8]. − 6 The kernel function of the CWD function controls the interfering cross-terms by the parameter α, whereby for large values the CWD function becomes the WVD function. Decreasing α increases the power of the kernel function, which reduces the interference terms. However, since the cross terms also contribute to form the desirable properties of energy functions, like the optimal time and frequency resolution simultaneously, it is not desired to eliminate these artifacts completely. In [3] the exact relationship between the factor α and the time resolution of the Choi-Williams Distribution is explained. The time resolution can be calculated as half the hµ(n) window duration lµ, for smaller values of α:

lµ 1 δtC WD = − . (3.57) 2fs 3.5. APPLICATION OF THE ANALYSIS METHODS ON THE SAWTOOTH OSCILLATION37

Hence, for the time-frequency analysis of multicomponent signals, the CWD function is an effective method, provided that the α factor is properly chosen, to obtain a satisfactory trade-off between a high clarity and suppression of the unfavorable cross-terms.

3.5 Application of the analysis methods on the sawtooth os- cillation

In this section the time domain analysis, Fast-Fourier Transform, Short-time Fourier Transform, Dis- crete Wavelet Transform, and the discrete versions of the Wigner-Ville Distribution Function and the Choi-Williams Distribution Function will be investigated for the real-time application on the sawtooth crash recognition problem. The remaining Fourier Transforms and the Continuous Wavelet Trans- form are discarded, since they are not usable for digital implementation.

The aforementioned analysis methods possess different desired and undesired properties, which can intensify or weaken, depending on the analyzed signal. The different analysis methods are exam- ined according to some predefined required properties with respect to real-time crash detection in the sawtooth signal.

3.5.1 Representation A signal can be analyzed in the time domain, the frequency domain and a combination of both: the time-frequency domain. Depending on the stationarity of the signal and the purpose of the signal analysis, one domain representation suits more than the other.

Time domain algorithm Naturally, the main drawback of the single domain representation of the time domain analysis is the lack of knowledge of the frequency content at a particular moment in time. By looking at the sawtooth signal it is clear that the spread of the samples at the crash is higher then at the ramp part. Therefore, recognition of the sawtooth crash by use of the time domain analysis, can be established by application of accurately chosen data processing methods in the time domain, that make use of the difference in statistical dispersion of the samples along the sawtooth.

Frequency domain algorithm The frequency spectrum of the sawtooth signal can be used for the detection of the crash in the fre- quency domain. The sawtooth signal is an aperiodic-discrete signal, since the period of the sawtooth wave is not constant in time in high Te plasmas [26] like in TEXTOR, and therefore, the most suitable Fourier Transform for power spectrum analysis would be the Discrete-time Fourier Transform. How- ever, as already mentioned before, the DTFT is not usable in computer algorithms, since an infinite number of sinusoids are required to transform an aperiodic signal to the frequency domain. The only usable Fourier Transform is the DFT and its moderate equivalent: the FFT. The frequency spectra of these Fourier Transforms show leakage, from considering the finite aperiodic signal as an infinite long periodic signal. The leakage can be reduced by applying a weighting window to the signal before the transformation. The window reduces the influence of the boundaries of the signal, by which the fre- quency determination is explicitly based on the center part of the signal. Examples of such weighting windows are the Hamming window and the Hann window. So, the DFT or better the FFT, can be used to transform the sawtooth signal to the frequency domain, but they only give insight on the frequency content over a particular time range of the signal. It seems more logical to use the FFT to obtain a global insight on the frequency content of the signal, than to use it as an analysis method to be able to accurately indicate the moment of the crash of the sawtooth signal. 38 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

Time-frequency domain algorithms The STFT, DWT and the discrete distribution functions of Cohen’s class can give useful information about the time and frequency content of the sawtooth signal simultaneously. As already mentioned before, the moment of crash can be identified in the time domain. Characteristic frequency features of events in a signal can also be identified at specific moments when a signal is analyzed in the time and frequency domain. This property of time-frequency analysis methods make these techniques fa- vorable with regard to the representation, compared to the pure time domain analysis techniques. The coefficients of the STFT and discrete TFD’s are presented in a time-frequency plane, while the DWT represents its coefficients in a time-scale plane. This has no further consequences, since the scale is directly related to a central frequency for each wavelet family.

The conclusion drawn here is that only the analysis techniques with a time domain or time-frequency domain representation are applicable for the sawtooth recognition problem, in order to be able to identify the moment of crash. Therefore, pure frequency domain techniques, like the FFT, are not suitable for a detection algorithm for sawtooth crashes.

3.5.2 Clarity The clarity of an analysis method defines the accuracy and reliability of the obtained results. This term is especially often used when verifying the results of the distributions of Cohen’s class, since the time-frequency representation of (most of) these distributions attends with ambiguous cross-terms. The clarity of a feature detection in the sawtooth signal depends on the properties of the analysis method used and on the characteristics of the feature. The desired and undesired properties of each of the discussed analysis methods concerning the clarity of the analysis method, are discussed in this subsection with respect to the sawtooth crash recognition application. The accuracy of a crash detec- tion algorithm can be defined as the percentage of correctly detected crashes with respect to the total number of crashes within a certain time range. The reliability is determined by the ambiguity of the obtained results.

Time domain algorithm The clarity of the time domain processing methods described in Section 3.1 depends among others on the corresponding time resolutions, listed in Table 3.2.

Processing method Time resolution Difference filter (a + 1)/fs Averaging filter + DF B(a + 1)/fs Standard deviation + DF B(a + 1)/fs

Table 3.2: Time resolutions of the processing methods.

Here, a represents the order of the difference filter, and B represents the number of samples in a data set, from which the average and/or standard deviation is determined. The time resolutions of the averaging filter or standard deviation in combination with a difference filter is a factor B finer than the time resolution of a single difference filter for equal order of the difference filter. However, a crash detection algorithm based on only a difference filter is much more sensitive to noise than the algorithms which compare the average or statistical dispersion of two B length data sets with each other. Especially the averaging filter is more robust to noise for high values of B.

The conclusion drawn here is that for sawtooth signals with a lot of noise evaluation of sequencing data sets gives better results at the expense of the fine time resolution. For sawtooth oscillations with low noise levels the application of an algorithm with a single difference filter is preferable above algo- rithms based on the average and/or standard deviation of a data set. 3.5. APPLICATION OF THE ANALYSIS METHODS ON THE SAWTOOTH OSCILLATION39

Short-time Fourier Transform A serious drawback of the Short-time Fourier Transform and the corresponding constant window width, is the resulting constant time and frequency resolution for all frequencies, see (3.28) and (3.27). This can result in a too coarse frequency resolution to clearly detect the lower frequencies, while the time resolution is typically higher than the variation time for these low-frequent events. At high frequencies, the frequency resolution is typically unnecessary fine, while the time resolution can be too coarse to detect changes in the high-frequent behavior.

The crash in the sawtooth oscillation can be detected by directly analyzing the moment of crash or by determining the moment of NTM onset, since this onset appears simultaneously with or immediately after the sawtooth crash [4]. The STFT has been applied to the Joint European Tokamak in 2002, for magnetohydrodynamic mode analysis to resolve the time of the NTM onset with respect to the sawtooth, see [22]. The NTM destabi- lizations in JET H-mode discharges, resulting from the presence of a rich variety of MHD instabilities [22], were investigated for pulses with large Neutral Beam Injection powers. The destabilizations were also investigated for H-mode and L-mode discharges where combined Ion Cyclotron Resonance Heat- ing and NBI heating were used to control the NTM onset through control of the sawtooth period [30]. Because the NTM’s may have started right before, with or right after a sawtooth crash, a high time resolution is required to detect the exact moments of onset. For large NBI powers, the time of the NTM onsets were clearly identified, but for the combined ICRH and NBI heating with NBI powers below 5MW, the time resolution was not sufficiently fine enough to resolve the NTM times of onset. These poor results gave rise to another research of MHD mode analysis on JET with combined NBI and ICRH heating (PNBI = 3MW plus PICRH = 1.5MW). This research was executed in 2003 by Figueiredo et al. [3, 4], using several time-frequency analysis techniques, including the STFT. To be able to identify the different MHD modes in the sawtooth signal from a magnetic pick-up coil, a Hann window with relatively large‘window length l was chosen, to obtain a high frequency resolution. As a result, the time resolution δtSTFT was not sufficiently fine to draw any conclusions about the times of the NTM onsets with respect to the sawtooth. The results of the experiment is shown in Figure 3.9(a), at which the NTM’s can be recognized by the horizontal stripes along the time-frequency planes. The broadband sawtooth crash can be clearly identified in the time-frequency plots obtained by a vertical stripe, but as with the NTM onsets, the moment of crash is not very clear, resulting from the coarse time resolution. The time resolution can be improved by narrowing δtSTFT but, consequently, the frequency resolution decreases, making it harder to distinguish between the different modes [4].

Figure 3.9: Analysis of a magnetic pick-up coil signal on JET, using (a) the STFT, and (b) the DWT.

Detection of the broadband sawtooth with the STFT is difficult, as a result of the constant window width. Detection of the NTM onsets separately with the STFT would be easier, since the window width can be accurately chosen for a particular small frequency range. 40 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

Discrete Wavelet Transform The constant relative time-frequency resolution of the Discrete Wavelet Transform allows multires- olution analysis for the time and frequency resolution, see (3.2). Therefore, lower frequencies can be analyzed with a fine frequency resolution, while the higher frequencies can be identified at small time intervals. Nevertheless, the achievable frequency resolution of the DWT is still limited, as a re- sult of the logarithmic rule used for the discretization of the scale, while still satisfying the required minimum sampling rate to avoid aliasing. Another useful property of DWT with respect to the clarity of this method, is the irregular shape of wavelets. Signals with sharp transitions, like the sawtooth signal, might be more accurately analyzed with a properly chosen series of wavelets than with a smooth sinusoid.

The use of wavelets for detecting events in the plasma has been investigated in several studies, among which the aforementioned research by Figueiredo et al. on JET for MHD mode analysis. The DWT with complex Morlet wavelets were applied to the identical sawtooth signal as the STFT. The time and frequency resolutions of the DWT are similar to those of the spectrogram for the higher frequen- cies, see Figure 3.9(b). However, for the low frequency NTM’s the time-frequency plane obtained has an unsatisfying coarse time resolution and a redundant fine frequency resolution. Consequently, the frequency content of the NTM onsets are clearly depicted, but the moments of onset is unclear. Increasing the time resolution of the DWT would decrease the frequency resolution, which is espe- cially undesired for the identification of the lower amplitude higher frequency NTM’s. The moment of crash of the sawtooth is also unclear at low frequencies, as a result of the low time resolution. In other words, the frequency dependency of the time resolution of the scalogram is for this experiment disadvantageous to the quality of the timeUfrequency representation [4]. A better time resolution is necessary at all frequencies for this signal to be able to identify the moment of onset of different fre- quency NTM’s and the broadband sawtooth crash. In this application the STFT showed better results than the DWT. Better results with wavelet application were obtained by experiments on the ASDEX Upgrade tokamak in Germany in 1998, see [20]. Since plasma events typically result in much larger wavelet coefficients than the background noise, the plasma events were distinguished by the exceeding of some predefined thresholds by the wavelet coefficients. Furthermore, a paper from Santoso et al. from 1997 on nonstationary plasma fluctuations demon- strated the efficiency of the DWT with complex Morlet wavelets, by analyzing the transient broadband electrostatic potential fluctuations inside the inversion radius of sawtoothing plasmas in the TEXT-U tokamak during ECRH [29]. It appeared that the potential fluctuation levels increase for a short period of time at several points in the core of the tokamak plasma, around the moment of sawtooth crash. The results of the DWT analysis were compared to an identical research on the potential fluctuations levels, using the STFT as analysis method. The dynamics of the nonstationary fluctuation levels were much clearer identified with the DWT, but one must keep in mind that the complex Morlet wavelets used consists of complex sinusoids multiplied by a Gaussian window, and therefore, by careful selec- tion of the type of window and the window width for the STFT, probably an almost identical result could have been obtained. The application of an other wavelet family with a more irregular shape, would presumably result in even better results for all aforementioned DWT experiments.

Cohen’s class distribution functions The auto-correlation function of the Wigner-Ville Distribution allows optimal temporal and spectral resolutions simultaneously. However, the main drawback of this bilinear representation is the creation of cross-terms whenever multiple frequencies are superimposed, like in case with the sawtooth signal. The Choi-Williams Distribution Function suppresses these interfering cross-terms, by means of the kernel function [8] and therefore, this distribution function is more suitable for the time-frequency analysis of the multicomponent sawtooth signal. However, the α factor should be chosen properly to obtain a satisfactory trade-off between a high accuracy and suppression of the undesired cross-terms.

The WVD and CWD were also applied to JET for the analysis of the magnetic pick-up coil signals, executed by Figueiredo et al. With the WVD a fine time resolution could be achieved from which the 3.5. APPLICATION OF THE ANALYSIS METHODS ON THE SAWTOOTH OSCILLATION41 moment of NTM onset could accurately be determined, provided that the frequencies of the NTM’s were known, since the WVD also shows the cross-terms, see Figure 3.10(a). Especially the higher frequency modes with the lower amplitudes are masked by these artifacts, since the magnitude of the artifacts is proportional to the product of the interfering components [4]. The best results were obtained by the CWD analysis, see Figure 3.10(b) by careful selection of α and the length of the win- dows hτ and hµ. The gained time resolution of the CWD is not as fine as the one with the WVD, but significantly better than the time resolutions of the STFT and the DWT for all frequencies. The broadband sawtooth crash can also clearly be identified in the obtained time-frequency plots of the WVD and CWD. The moment of crash is very clear, especially for the WVD, since the cross-terms do not obscure frequency spectra of the broadband crash event.

Figure 3.10: Analysis of a magnetic pick-up coil signal on JET, using (a) the WVD, and (b) the CWD.

Although the higher frequencies modes were still slightly masked by the cross-terms, the CWD ob- tained the best results when resolving the moment of the NTM’s onsets with respect to the sawtooth in the JET experiments. The moment of the crash could also be the most accurately identified with the algorithms based on the distributions of Cohen’s class. Especially the WVD obtained a very high time resolution, but the clarity of the CWD is higher, as a result of the reduced artifacts.

3.5.3 Computational complexity

The last crucial requirement for a real-time crash detection analysis method is fast detection. Since the period estimation obtained will be the input signal of a controller to control the frequency of occur- rence and the amplitude of sawtooth crashes using ICRH, the detection should be as fast as possible to be able to control the onset of NTM’s as accurate as possible [30]. Fast detection requires a low com- putational complexity of the crash detection algorithm and fast computers for the calculation of the transforms desired. The computational complexity can be described by the algorithm’s usage of com- putational resources, whereby the running time or memory usage of the algorithm is expressed as a function of the length of the algorithm’s input. A common notation for the computational complexity is the exact number of arithmetic operations, defined by the number of additions and multiplications a computer has to perform on an algorithm to obtain a single output value.

Time domain algorithm The computational complexity of time domain algorithms depends on the processing method used and the corresponding variables. For the determination of the moment of crash of the sawtooth os- cillation, different processing methods can be used to amplify the difference in statistical dispersion between the ramp and crash part of the signal. The computational complexities of the processing methods discussed in Section 3.1 are all of the order of (O), see Appendix A.5.1: 42 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

The filter order a has for a difference filter no consequence for the computational complexity, which results in a constant number of additions and multiplications. The computational complexities of the algorithms, which uses the average and/or standard deviation of a data set followed by a difference filter, are dependent on the number of samples in the data set B. Consequently, low values for B are desired for the real-time implementation of the methods for the detection of the crash in the sawtooth signal.

Short-time Fourier Transform The STFT is naturally computed by multiplying the Fast-Fourier Transform by a window function [21]. The obtained dyadic grid of the FFT for the time axis reduces the computational effort for real- time implementation significantly. The computational complexity of the STFT depends strongly on the used FFT algorithm, but all FFT algorithms known compute the DFT of size N in (N log2 N) operations. Differences in computational complexity rely on the exact number of additionsO and multi- plications, rather than their functional form [18]. In 1968 Yavne presented the "split-radix" algorithm; an improvement of the classic "radix-2" algorithm of Cooley and Tukey. The Cooley-Tukey algorithm repetitively breaks down the DFT of size N = N1N2 into smaller DFTs of sizes N1 and N2, at which for the radix-2 algorithm the size of the N1 and N2 are equal to N/2 at each step. The split-radix algorithm recursively expresses the summation of the DFT in three smaller summations, one of size N/2 and two DFTs of length N/4. A modified version of this algorithm, presented by Johnson and Frigo in 2007, gained an even smaller number of real additions and multiplications required to compute the FFT. The number of real addi- tions and multiplications per algorithm are listed in Appendix A.5.2, for a real-data FFT of length N = 2m. The DFT is also included.

The computational complexity of the STFT can be derived by multiplying the complexity of the dis- cussed algorithms by the complexity of the window function. Windowing with a Hann or Hamming window costs N real multiplication, which results in a total number of real additions and multiplica- tions for the STFT of order (N log N), see Appendix A.5.3. O 2 Discrete Wavelet Transform The real-time implementation of the DWT by use of filter banks is easy, due to the repetitive applica- tion of the identical low- and highpass filters at each subsequent level. The halved sample rates, and resulting halved computational time, at each consecutive filter step also makes the filter bank compu- tationally efficient. The use of filter banks reduces the complexity by half by using the dilation property of wavelets instead of using the precomputed discrete wavelets[28]. Nevertheless, fast algorithms have been invented to further reduce the number of arithmetic operations to be performed to obtain the DWT of a signal using filter banks.

For example, the transform domain implementation algorithm proposed in [5] needs half the num- ber of real multiplications and additions to obtain the DWT, compared to the standard filter bank algorithm. Another algorithm for fast computation of the DWT is the FFT-based DWT, known as the Fast Wavelet Transform (FWT) [28]. This algorithm reduces the arithmetic complexity of an FIR filter implementa- tion, such as used in filter banks, by bringing together the computation of several successive outputs [31]. This algorithm was even further improved by [31]. Another algorithm for fast computation of the DWT is the short-length "fast-running FIR" algorithm. This class of algorithms is especially interesting for short filters and has proven to reduce the number of real arithmetic operations by 30 percent [28].

The computational complexities of the DWT and several efficient implementation algorithms are listed in Appendix A.5.4. The efficient algorithms all compute the DWT in order (N log2 N) operations, at which the exact computational efficiency depends on a large number ofO variables, like the maxi- mum level of decomposition J, and therefore, for each particular implementation another algorithm is the most suitable. For shorter wavelets, such as the Haar wavelet, the Modified lattice is an effective 3.5. APPLICATION OF THE ANALYSIS METHODS ON THE SAWTOOTH OSCILLATION43 algorithm, while for the longer wavelets frequency domain convolution (like used in the FFT-based DWT’s) allows efficient, high speed implementation [5, 28].

Wigner-Ville Distribution and Choi-Williams Distribution The computational complexity of algorithms based on the Cohen’s class distribution functions are significantly higher than for the aformentioned STFT and DWT. For on-line applications this can be decisive by selecting a time-frequency analysis method. Fortunately, different approaches have been proposed to calculate the Wigner-Ville Distribution and Choi-Williams Distribution faster, making use of some of the properties of the distributions.

For example, Claasen and Mecklenbraucker [9] used the advantages of the symmetric structure of the autocorrelation and kernel matrix of a real signal to reduce the computational efficiency of the algorithm. This was further extended by Boashash and Black, by also exploiting these symmetry properties of the complex kernel sequence generated from the analytical signal, and hereby obtaining a reduction in the number of calculations of 50 percent compared to direct evaluation of the WVD [1]. Evaluation of the analytical signal instead of the real signal is necessary to allow sampling at the Nyquist frequency instead of half the Nyquist frequency, and eliminate the undesired cross-terms between negative and positive frequencies. The analytical signal can be evaluated by the time domain definition, characterized by the use of the FFT and inverse FFT, or by the frequency domain definition, which uses an FIR filter, see Subsection 3.4.3. The computational complexity of the two methods per plot are listed in Appendix A.5.5. In [6] a matrix calculation method is presented to further reduce the number of arithmetic operations required for the WVD calculation with the aforementioned methods of evaluating the analytical signal. It was also demonstrated that parallel processing architectures allow implementation of the algorithm with speeds that are appropriate for real-time running window calculations. The processing time is in that case independent of the number of samples. Other approaches based on considering the eigendecomposition of the kernel for the computation of the alias-free generalized discrete TFD’s are also proven to be faster than the standard WVD and CWD computations [11, 21]. Finally some results obtained in [17] are presented considering a computationally efficient algorithm. This algorithm applies linear convolution of the discrete TFD’s with the kernel in both the time and frequency directions. For the WVD the order of computational complexity is approximately halved, compared to the traditional WVD computation method. For the computational complexer lag-independent kernels, like the kernel of the Choi-Williams Distribution, the order of computational complexity remains equal.

The computational complexity of the efficient implementation algorithms for Cohen’s class distribu- tion functions are all of the order of (N log2 N) arithmetic operations per plot and therefore, the computational complexity is significantlyO higher than the complexity of the time domain processing methods, and the STFT and DWT.

Considering the computational complexity of the analysis methods discussed, the algorithms based on time domain signal processing methods seems to be the most suitable for real-time implementation. The STFT is also easy to implement, as a result of the large number of fast FFT implementation algorithms available and the relatively simple structure of the FFT. Implementation of the DWT and, especially, the distributions from Cohen’s class is not as straightforward as the previously mentioned analysis methods. Fortunately, there are a number of implementation algorithms designed, which significantly reduce the number of required arithmetic operations. 44 CHAPTER 3. ANALYSIS METHODS OF THE SAWTOOTH OSCILLATION

3.5.4 Concluding remarks A judgement could be pronounced on the analysis methods, according to their representation, clarity and computational complexity.

Only the analysis techniques with a time domain or time-frequency domain representation are appli- cable for the sawtooth recognition algorithm, and therefore, the pure frequency domain FFT is not suitable. When looking at the clarity of the different methods, conclusions can be drawn according to the ac- curacy expected and reliability of the obtained moment of sawtooth crash. The time domain algo- rithms will have a high accuracy of the moment of crash, resulting from the fine time resolutions. Experiments with the STFT showed some pretty good results, but the constant time and frequency resolutions for all frequencies remains a major limit to obtain an accurate estimation of the moment of crash. The multi-resolution DWT offers finer time resolution for the high frequencies and fine frequency resolution for the lower frequencies, but this frequency dependency of the time resolution showed to be disadvantageous to the quality of the time-frequency representation. The WVD has the finest time and frequency resolutions simultaneously. However, the clearness of the auto-terms is masked by the cross-terms, which reduces the reliability of the obtained results significantly. The CWD solves this problem by means of the kernel function. However, a reduction of the cross-terms attends with reduced time and frequency resolutions. Nevertheless, the CWD showed to have the highest clarity in the time-frequency domain. According to the computational complexity of the analysis methods discussed, real-time implemen- tation of the time domain algorithms is the easiest. The time-frequency analysis techniques are more difficult to implement, since the arithmetic operations concerned with the calculation of a time- frequency transformed signal are of order (N log2 N). The most straightforward time-frequency analysis method is the STFT for which numerousO efficient real-time implementation algorithms are available. The DWT, WVD and CWD are more difficult to implement, but also for these techniques a number of fast implementation algorithms exist.

The overall conclusion is that a crash detection algorithm using the Choi-Williams distribution is advantageous if the time domain algorithm and the STFT fails to produce satisfying results, as long as the sawtooth signal structure is not too complex. Chapter 4

Time domain sawtooth recognition algorithm

In this chapter a sawtooth recognition algorithm is designed for real-time determination of the saw- tooth period, based on the real sawtooth signal of TEXTOR shot 106478. The first required property of a sawtooth recognition algorithm is, according to Section 3.5, an algorithm in the time or time- frequency domain. In this chapter a time domain algorithm is designed.

The operating principle of the algorithm is explained by performing and displaying each algorithm step on shot 106478. Shot 106478 consists of five clear sawteeth shaped signals, measured on five different ECE channels and with a nearly constant period. By using this sawtooth signal to design the algorithm, the performance of different parts of the algorithm becomes clearer than when using a sawtooth signal dominated by irregularities and noise. Figure 4.1a shows the temperature profile of discharge 106478 between t = 0 [s] and t = 6 [s]. Figure 4.1b shows the zoomed sawtooth signal between t = 2 [s] and t = 2.15 [s]. The ECE system possesses a sixth ECE channel with frequency 147.5 [GHz], but this channel was malfunctioning during all of the shots discussed in this thesis, so this channel is omitted in all of the calculations and figures.

8 132.5 GHz 7 135.5 GHz 7 138.5 GHz 141.5 GHz 144.5 GHz 6 6

5 5 4

3 4 Temperature [A.U.] 2 Temperature [A.U.] 3 1

0 2 0 1 2 3 4 5 6 2 2.05 2.1 2.15 Time [s] Time [s] (a) Complete signal (b) Zoomed signal

Figure 4.1: Sawtooth signal of shot 106478.

The total plasma current during this discharge is Ip = 350 [kA] and the toroidal magnetic field is Bθ = 2.4 [T].

45 46 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

First, the frequency content of a sawtooth signal is analyzed in Section 4.1. The obtained frequency information enables the application of a filter to attenuate the noise of the signal. The sawtooth period can be computed as the difference between subsequent repeating sawtooth events like the crash in the sawtooth. Therefore, in Section 4.2 several data processing methods are considered for the emphasis of the sawtooth crash. Since the noise level is different for different ECE channel, Section 4.3 intro- duces the normalization function of the algorithm, before the exact crash samples are determined from the separate and combined channels in Section 4.4. Finally, in the section 4.5 and 4.6 the final real-time period and location of the inverse radius are determined by the algorithm. In the last section the performance of the algorithm is examined according to the clarity and com- putational complexity of the algorithm. The algorithm is designed with MATLAB and the m-file is included in Appendix B.

4.1 Noise filtering

A logical first step in designing a time domain sawtooth recognition algorithm is applying a filter to cancel out as much noise as possible. In this section the frequency content of the sawtooth signal is investigated, different types of filters are analyzed and compared, and Finally a properly selected low-pass filter is applied to the signal to filter out the high-frequency noise.

4.1.1 Frequency analysis of the sawtooth signal To obtain a better insight on the frequency content of the sawtooth the time domain signal can be transformed into the frequency domain by applying the Discrete Fourier Transform to the signal. Es- pecially the difference in frequency content between the crash part and the rest of the sawtooth is interesting, because it provides insight on the noise level in the signal and specific characteristic fre- quency features of the crash might arise. Therefore, a single sawtooth is cut in half, one with and one without the crash, and the frequency spectra of both parts are determined and analyzed. A drawback of splitting the signal into multiple parts, or in other words, by shrinking the time window, is the decrease of the frequency resolution. This is especially unfavorable for the analysis of the lower fre- quencies. However, the accuracy of the obtained Fourier coefficients can be increased by determining the average frequency content of a sawtooth.

The average frequency spectrum of a sawtooth signal with constant period could easily be determined by applying the Discrete Fourier Transform to exactly the same part of several sawteeth. The period is determined by subtracting subsequent moments of crash for each sawtooth of channel 132.5 [GHz] between t = 1.21371 [s] and t = 5.11913 [s]. The moment of crash is determined by manual inspect- ing the moment of the center sample in the sawtooth crash, see Figure 4.2. This figure shows that the crash times of channel 132.5 [GHz] corresponds to the moments of the crashes of the other channels.

As can be seen in Figure 4.3, the period of the data varies in time. This is due to the changed settings of the plasma current Ip. 4.1. NOISE FILTERING 47

5 132.5 GHz 135.5 GHz 4.5 138.5 GHz 141.5 GHz 144.5 GHz 4

3.5

3

2.5 Temperature [A.U.] 2

1.5

1 3.5 3.52 3.54 3.56 3.58 Time [s]

Figure 4.2: Sawtooth signal of the five channels with the encircled moments of crash.

0.014

0.013

0.012

0.011 Period [s] 0.01

0.009

0.008 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 Time [s] (a) Period

−250

−300

−350 Current [kA] −400

−450 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 Time [s] (b) Plasma current

Figure 4.3: Period of the sawtooth and corresponding ECCD current.

Despite of the varying period of the sawtooth profile, it is still possible to determine accurately the frequency content of different segments of the sawtooth, by using the coordinates measured from the crash points when dividing the signal in two parts. Between t = 3.30983 [s] and t = 4.81153 [s] the period of the sawtooth appears to be quite constant, with a mean of 11.74 [ms] and a standard deviation of 0.40 [ms]. By splitting one sawtooth into two parts with equal sample points, the sawtooth is divided 48 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM into a segment with the ramp and a segment with the crash of the sawtooth, see Figure 4.4.

4.5 crash 4.4

4.3

4.2

4.1

4

3.9 Temperature [A.U.] 3.8 ramp- crash- 3.7 segment segment

3.6 2.05 2.06 2.07 2.08 2.09 Time [s]

Figure 4.4: The time-domain signal divided in ramp- and crash-segments

Because the segments contain half the number of mean samples per sawtooth, 1174/2 = 587 sam- ples, the overlap between the begin- and endpoints for both segments is small and approximately equal. This is necessary to avoid leakage when the Discrete Fourier Transform is used to determine the frequency content of the segments. There will still be some leakage because of the variable period and the signal noise, but this is reduced by applying a Hamming window before transforming the signal to the frequency domain.

Figure 4.5a and 4.5b show the frequency spectrum of the ramp segment and the crash segment of the sawtooth. The difference between both frequency spectra is displayed in Figure 4.5c.

Especially at lower frequencies there is a distinct difference in frequency content between both seg- ments, resulting from the step shaped sawtooth crash. A step in the time domain results in a fre- quency spectra with higher amplitudes for the lower frequencies and lower amplitude for the higher frequencies. Furthermore, there is a conspicuous frequency peak at about 3000 [Hz] in the channel with 138.5 [GHz], see Figure 4.5d. The crashes between t = 3.30983 [s] and t = 4.81153 [s] last for approximately 16 samples, which agrees with 0.16 [ms]. Therefore, by applying the Fourier transform the crash is recognized by fitting a sine with a period of 2 0.16 = 0.32 [ms], i.e. 3000 [Hz]. This only holds for the channel with 138.5 [Hz]. The signal of this channel∗ does not show the ramps, but there are crashes. The crashes in this channel close to the inversion radius are preceded by a small fall, then the actual crash is visible as a larger jump, followed again by a small fall, see Figure 4.5d. The shape of the crash and the moments right before and after the crash correspond closely to the shape of a sine. The crashes in the remaining channels are steeper and do not show the same behavior right before and af- ter the crash, and consequently, these channels do not have a peak at 3000 [Hz]. Since some channels do and some do not show the peak at 3000 [Hz], the peak is not included in the design of the algorithm. 4.1. NOISE FILTERING 49

60 60 132.5 GHz 135.5 GHz 138.5 GHz 141.5 GHz 40 144.5 GHz 40

20 20 tude [dB] tude [dB] 0 0 Magni Magni

−20 −20

−40 −40 2 3 4 5 2 3 4 5 10 10 10 10 10 10 10 10 Frequency [Hz] Frequency [Hz] (a) The ramp segment (b) The crash segment

60 25

40 20

20 15 tude [dB] tude [dB] 0 10 Magni Magni

−20 5

−40 0 2 3 4 5 3.2 3.4 3.6 3.8 10 10 10 10 10 10 10 10 Frequency [Hz] Frequency [Hz] (c) The difference (d) Zoom of the difference

Figure 4.5: The average frequency spectrum of the ramp and crash segments, and the difference between both spectra.

4.1.2 Filter design

The previous chapter showed the frequency content of the ramp and crash segments of the signal for the five channels. The difference between these two segments mainly contained lower frequencies. The higher frequencies, above approximately 2000 3000 [Hz], are due to the noise in the signal. Applying a filter to the signal to attenuate this noise,− simplifies the analysis of the signal in the time domain. In this subsection different filters are reviewed. Important design variables are the compu- tational complexity and the delay of the filter, which is strongly related to the (unit) impulse response, the filter type and some filter parameters. First a filter category is selected according to the frequency response of the filter. Next, the (unit) impulse response of several different filters is reviewed, and finally, a filter type is selected according to the shape of the frequency response and results of

The frequency response The higher frequency content of the sawtooth signal is due to noise and should be attenuated. A filter that passes the low-frequency signals but attenuates the signals with frequencies higher than a predefined frequency, the cut-off frequency, is called a low-pass filter. Here, we focus on linear time- 50 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM invariant (LTI) filters, since these filters are generally easier to analyze than time-varying or non-linear filters. The transfer function of a LTI systrm is not a function of time except expressed by the the input and output. Digital LTI filters are characterized by a transfer function of the form:

−1 −2 −N B(z) b0 + b1z + b2z + + bN z H(z) = = −1 −2 ··· −M . (4.1) A(z) 1 + a1z + a2z + + aM z ···

In this equation, z are generally complex numbers. The constants bi, i = 0, 1, 2,...,N, ai, i = 1, 2,...,M are called the coefficients, which determine the positions of the zeros and the poles re- spectively.

The order of the filter is the greater of N and M and determines the number of previous inputs and/or outputs for the calculation of the new output, and consequently, the delay of the filter. The per- formance of the filter depends strongly on the filter order. For example, a higher order low-pass filter can achieve a steeper high-frequency roll-off then a lower order low-pass filter. The exact relationship between the slope of a low-pass filter and the filter order depends on the filter type. The computational complexity is also more or less proportional to the order of the filter. Lower order filters naturally require less additions and multiplications than higher order filters. Therefore, when designing a low-pass filter for real-time implementation purposes, careful selection of the filter order is necessary considering the trade-off between a steep high-frequency roll-off and low computational complexity.

The (unit) impulse response Digital LTI filters can be classified into two categories, according to how they respond to a unit impulse. The simplest category are the Finite Impulse Response (FIR) filters, which have a transfer function as shown in (4.1), but with a denominator equal to unity. This means that all the poles are located at the origin and the new output is calculated by using inputs only. As a result, when the filter input has remained zero for a certain time, the filter output becomes zero as well. In other words, the impulse response of the filter is finite. A very useful property of FIR filters is the inherently stable behavior, due to the fact that all the poles are located at the origin and thus located within the unit circle. Since FIR filters only uses inputs, they do not require any feedback, which make them easy to implement. Another advantage of FIR filters is that they can be designed with linear phase, which means that the wave shape is preserved in the passband and the phase shift is equal for all frequencies. The main disadvantage of FIR filters is that considerably more computation power is required to get almost similar results as when using an IIR filter. As the name already implies, the Infinite Impulse Response (IIR) filter has an impulse response func- tion which is non-zero over an infinite length of time. This is due to the non-unity denominator in the transfer function as a result of which the IIR filter uses previous filter outputs to calculate the new output. This means that a lower order low-pass filter is required to process the same input values as for FIR low-pass filters. Consequently, IIR low-pass filters are faster and better suited for real-time operations. Examples of IIR filters are the Bessel, Butterworth and Chebyshev filter.

The required low-pass filter becomes part of the real-time recognition algorithm and therefore, a com- putational faster IIR low-pass filter is chosen to be designed.

Digital IIR filter design The most common design methods for digital FIR filters is the Window design method. There are hardly any straightforward design methods for digital IIR filter design, while there are plenty of re- sources, works and straightforward design methods concerning analog feedback filter design. There- fore, first an analog IIR filter is designed and then it is converted to a digital filter by applying dis- cretization techniques such as Bilinear transform or Impulse invariance. The sawtooth recognition algorithm is designed in MATLAB. The MATLAB functions uses the Bilin- ear transform to design a digital Bessel, Butterworth or Chebyshev filter. A characteristic of the bilinear 4.1. NOISE FILTERING 51 transform is that stable filters designed in the continuous-time domain are converted to stable filters in the discrete-time domain, because the bilinear transform maps the left half of the complex s-plane to the interior of the unit circle in the z-plane.

Filter types Digital IIR low-pass filters can be classified according to their transfer function, which results from certain requirements concerning the shape of the stop- and passband. Figure 4.6 shows the frequency response of a low-pass filter.

Figure 4.6: Frequency response of a digital low-pass filter.

The passband defines the unaltered frequency band of the signal by the filter, bounded by the fre- quency resolution and the passband frequency, or cut-off frequency. The stopband indicates the higher frequency content of the signal which is attenuated by the low-pass filter. The stopband is bounded by the stopband frequency and the Nyquist frequency. The filter types which can obtain a steeper slope generally attends with an undesired ripple in the passband and/or stopband.

In this thesis the well-known Bessel and Butterworth filter and the Chebyshev filter Type II are in- vestigated, but first values for the cut-off frequency fc and the order n are selected. Figure 4.5c in Subsection 4.1.1 showed that the difference in frequency spectra between the ramp and crash part of the sawteeth mainly lies in the lower frequency content of the signal. Above approximately 2500 [Hz] the signals are dominated by noise. To investigate the optimal cut-off frequency for the low-pass filter, several 3rd order Butterworth filters are implemented with different values for the cut-off frequency fc, see Figure 4.7. Figure 4.7 shows that a low-pass filter with a cut-off frequency of 2000 [Hz] obtains the best results, since the noise is more attenuated than with fc = 3000 [Hz] and the length of the crash is not affected by the filter, like with fc = 1000 [Hz]. This also applies to the Bessel and Chebyshev Type II filter and therefore, the cut-off frequency is allocated at 2000 [hz]. A similar test can be performed for the selection of the filter order. A higher filter order results naturally in a steeper roll-off and therefore, more attenuation of the higher frequencies, but also in a higher computational complexity and a larger delay. A 3rd order low-pass filter is selected on account of an optimal trade-off between these favorable and unfavorable effects. 52 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

6.4

6.3

6.2

6.1

6 Magnitude [dB]

5.9

5.8 2 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 Frequency [Hz]

(a) fc = 1000 Hz

6.4

6.3

6.2

6.1

6 Magnitude [dB]

5.9

5.8 2 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 Frequency [Hz]

(b) fc = 2000 Hz

6.4

6.3

6.2

6.1

6 Magnitude [dB]

5.9

5.8 2 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 Frequency [Hz]

(c) fc = 3000 Hz

Figure 4.7: Filtered signal with a 3rd order Butterworth low-pass filter with three different cut-off frequencies. 4.1. NOISE FILTERING 53

Figure 4.8 shows the Bode plots of the Bessel, Butterworth and the Chebyshev Type II filters with a cut-off frequency of fc = 2000, indicated by the dotted line, and a filter order n = 3. As can be seen in Figure 4.8a, the Bessel filter is attended with the slowest high-frequency cutoff, followed by the Butterworth filter. The Chebyshev Type II filter obtains the steepest roll-off, but at the expense of a gain ripple in the stop band. The Bessel filter is an example of a linear phase system, characterized by a phase response as a linear function of frequency. In Figure 4.8c, the phase delay τφ at a frequency f is related to the phase shift φ by:

φ(f) τφ = . (4.2) − f The almost constant phase delay across the entire passband of the Bessel filter preserves the wave shape of a filtered signal in the passband. The Butterworth and Chebyshev filters are filters with non- linear phase, indicated by the phase delay that varies with frequency in the passband, resulting in phase distortion. Despite of the linear character of the phase delay of the Bessel filter, this filter type is not selected for application on the sawtooth signal, because of the slow high-frequency roll-off. The Butterworth and Chebyshev Type II filters are further investigated for attenuation of the higher frequency noise of the sawtooth signal, since these filters obtain the steepest roll-off.

The filter order n and cut-off frequency fc are for the low-pass Butterworth filter related to the ampli- tude GB by:

G0 GB(f) = H = , (4.3) | | r  2n 1 + f fc and for the Chebyshev Type II filter by:

G0 GC (f, fH ) = . (4.4) q 1 1 + 2 2 ε Tn(fH /f)

In these equations, G0 represents the gain at zero frequency. The parameter ε is related to the stop- band attenuation γ in decibels, see Figure 4.6, by:

1 ε = . (4.5) √100.1γ 1 − For Chebyshev filters the cut-off frequency fc is defined as the smallest frequency at which a stopband attenuation of γ is attained. The 3 [dB] frequency fH is related to the cut-off frequency by:

 1 1 f = f cosh cosh−1 . (4.6) H c n ε 54 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

Bessel 0 Butterworth Chebyshev II −20

−40

−60 Magnitude [dB]

−80

−100 2 3 4 5 10 10 10 10 Frequency [Hz] (a) Amplitude response

0

−50

−100

−150

Phase [degree] −200

−250

−300 2 3 4 5 10 10 10 10 Frequency [Hz] (b) Phase response

−3 x 10 1.5

1

0.5 Phasedelay [rad/Hz]

0 2 3 4 5 10 10 10 10 Frequency [Hz] (c) Phase delay

Figure 4.8: Frequency response of three different filters.

rd rd A 3 order Butterworth filter with cut-off frequency fc = 2000 [Hz] and a 3 order Chebyshev Type II filter with 3 [dB] frequency fH = 2000 [Hz] are applied to the sawtooth signal of shot 106478. The application of different values for the cut-off frequency of the Chebyshev filter are examined in order to obtain the best trade-off between a steep roll-off and a high stopband attenuation. Figure 4.9 shows the applied Butterworth and Chebyshev filter with a cut-off frequency fc = 4300 [Hz] and a stopband attenuation γ = 30 [dB] for the Chebyshev filter. 4.1. NOISE FILTERING 55

6.4

6.3

6.2

6.1

6 Magnitude [dB]

5.9

5.8 2 2.05 2.1 2.15 Frequency [Hz] (a) Butterworth filter

6.4

6.3

6.2

6.1

6 Magnitude [dB]

5.9

5.8 2 2.05 2.1 2.15 Frequency [Hz] (b) Chebyshev Type II filter

Figure 4.9: Filtered signal with two types of 3rd order low-pass filters.

As can be seen, the results of the filtered signals are almost similar for both filters. Some crashes ap- pear clearer with the Butterworth filtered signal, while at others the attenuated noise results in a more distinct crash. Since the zeros of the Chebyshev Type II filter are not all located at z = 1, as is the case with the Butterworth filter, more multiplications are needed. Furthermore, the phase− response of the Chebyshev filter is less linear than the phase response of the Butterworth filter, which results in more frequency dependent phase distortion. Therefore, the Butterworth filter is preferred and a 3rd order low-pass Butterworth filter is chosen for the attenuation of the high-frequency noise of the sawtooth signal.

In this subsection a digital low-pass filter was designed for the real-time attenuation of the higher rd frequency noise. In the next subsection the 3 Butterworth filter with fc = 2000 [Hz] is applied to the sawtooth signal.

4.1.3 3rd order Butterworth filter Applying the obtained 3rd order Butterworth filter to the signal exemplifies the sawtooth shape and especially the moments of crash, as can be seen in Figure 4.10.

4.1.4 Implementation structures For digital IIR filters there are several ways for numerical implementation of the filter in software of hardware. 56 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

7 7 132.5 GHz 135.5 GHz 138.5 GHz 141.5 GHz 6 144.5 GHz 6

5 5

4 4 Temperature [A.U.] Temperature [A.U.]

3 3

2 2 2 2.05 2.1 2.15 2 2.05 2.1 2.15 Time [s] Time [s] (a) Original signal (b) Filtered signal

Figure 4.10: Original and filtered sawtooth signal of shot 106478.

The most straightforward implementation is the Direct Form I, which has the following difference equation, derived from eq. (4.1):

y(n) = b0 x(n) + b1 x(n 1) + + bN x(n N) a1 y(n 1) aM y(n M) (4.7) − ··· − − − − · · · − −

N M X X = bi x(n i) aj y(n j). (4.8) − − − i=0 j=1

Here, x is the input signal and y is the output signal. A restriction on the implementation is the computational complexity; the designed filter should be able to be implemented real-time, so the number of operations needed to compute the filter response should be as low as possible. This computational effort depends for example on the order of the filter, the number of filter coefficients which corresponds to a specific type of filter, but also on the implementation structure used. The Direct Form I implementation structure requires equal number of multiplications and additions as the Direct Form II implementation, characterized by the difference equations:

y(n) = b0w(n) + b1w(n 1) + b2w(n 2), (4.9) − − where:

w(n) = x(n) a1w(n 1) a2w(n 2). (4.10) − − − − However, the number of delays involved with the Direct Form I is a factor 2 higher than the number of delays of Direct Form II, resulting from the block diagram of both implementation structures, see Figure 4.11. 4.2. DATA PROCESSING METHOD 57

(a) Direct Form I (b) Direct Form II

Figure 4.11: Blockdiagrams of the Direct Form I and II implementation structures.

The computational complexity of the two Direct Form implementation structures, in terms of the number of multiplications, and the delays are listed in Table 4.1.

Implementation structure Number of multiplications Number of additions Delay Direct Form I 2n + 1 2n 2n Direct Form II 2n + 1 2n n

Table 4.1: Computational complexity and delay of the Direct Form I and II implementation structures.

The Direct Form II implementation is called the canonical form, since it uses the minimal amount of delays, additions and multiplications. This implementation form is desired for the real-time imple- mentation of the filter of the recognition algorithm.

With the filtered signal it becomes easier to discriminate between sawtooth crashes and signal noise. The next step in designing a crash recognition algorithm is selecting a statistical operation to empha- size the crash moments, which is done in the next section.

4.2 Data processing method

By considering the sawtooth signal it is clear that the spread of the samples at the crash is higher than at the ramp part. Several statistical operations that uses this statistical dispersion were examined in Section 3.1, such as the difference between subsequent samples and the standard deviation of a batch of samples of a signal. Not only a distinct difference between crash and ramp samples is important, but also the computational complexity and the accuracy of the crash detection, corresponding to the application of each of the operations ,is decisive. In Subsection 4.2.1 several statistical dispersion methods are analyzed. In Subsection 4.2.2 one of the methods is applied to the signal.

4.2.1 Statistical dispersion

The most common measure of dispersion is the previously mentioned standard deviation σ[b], which can for a discrete random variable x[n] be defined as:

v u bB u 1 X σ[b] = t (x[n] µ[b])2 for n = 1, 2, ..., . [3.7] B − ∞ n=(b−1)B+1 58 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM where µ is defined as the mean of the values of the data set X:

bB 1 X µ[b] = x[n] for n = 1, 2, ..., . [3.3] B ∞ n=(b−1)B+1

Variable n represents the number of data points in a data set. This means that when using the standard deviation to determine the statistical dispersion of the sawtooth signal the incoming samples have to be buffered in batches before they can be processed. A drawback of treating the signal in batches is the decreased time resolution, see (3.9). B + a + 1 δtSD = . [3.9] fs Here, B represents the batch size. A low time resolution will result in an inaccurate record of the crash moments and a less accurate period estimation. Furthermore, Table A.1 in Subsection 3.1.3 shows that the computational complexity, in terms of number of additions and multiplications, grows with a factor 6 for increased batch size. Keeping the batch size as small as possible will reduce these unfavorable effects.

Considering a perfect sawtooth without any noise, the standard deviation in both the ramp part and the crash part of the sawtooth is constant as a function of time for every batch size. More important, the ratio between both standard deviations is also constant. This is verified by the following example: Suppose the data set of the ramp part of a perfect sawtooth, defined as Xr, and the data set of the crash part of a perfect sawtooth, defined as Xc, consist of samples xr and xc respectively, with the linear distributions:

xr[n] = arn, (4.11)

xc[n] = acn. (4.12)

In these equations ar and ac represent two constants. Assume a batch size of B samples, with B smaller than the number of samples in the crash. For the linear data sets Xr and Xc, the mean can be defined as:

bB bB 1 X a X 1 µ = x[n] = n = a (b + 1). (4.13) B B 2 n=(b−1)B+1 n=(b−1)B+1

Inserting (4.13) in equation (3.7) gives the following formula for the standard deviations at both parts of the sawtooth:

v v u bB u bB u 1 X 1 u 1 X 1 σ = t (an a (B + 1))2 = t a2(n (B + 1))2. (4.14) B − 2 B − 2 n=(b−1)B+1 n=(b−1)B+1

The ratio between the standard deviation in the crash part and the ramp part of the sawtooth can now be defined as:

q q 1 PbB 2 1 2 1 PbB 1 2 σ B n=(b−1)B+1 ac (n 2 (B + 1)) a B n=(b−1)B+1(n 2 (B + 1)) a c = − = c − = c . (4.15) σ q 1 bB 1 a q 1 bB 1 a r P a2(n (B + 1))2 r P (n (B + 1))2 r B n=(b−1)B+1 r − 2 B n=(b−1)B+1 − 2 4.2. DATA PROCESSING METHOD 59

From this, the conclusion can be drawn that the ratio between the standard deviation at the ramp segment and the standard deviation at the crash segment only depends on the steepness of the ramp and crash, defined by ar and ac respectively, and does not depend on the buffer size B. One should keep in mind that this ratio is analyzed for a perfect sawtooth without any noise. The real sawtooth signal does contain noise, but simulations on real data correspond to the previously obtained analysis results, at which the buffer size does not influence the ratio between the standard deviation at the ramp segment and the standard deviation at the crash segment. Furthermore, the transition between the ramp and crash segments was not considered and the distributions of Xr and Xc were considered to be linear. The real sawtooth oscillation is not exactly linear, but here also applies that the results obtained in future simulations show that the ratio between the standard deviations is not necessary dependant of the batch size.

Since the batch size does not influence the ratio between the standard deviation at the ramp segment and the standard deviation at the crash segment, the smallest possible batch size B = 2 is chosen in order to keep the computational complexity as low as possible and the moment of crash as accurate as possible. The corresponding formula for the standard deviation is:

v u 2 u1 X σ = t (x[n] µ[b])2. (4.16) 2 − n=(b−1)2+1

Since x1 µ equals x2 µ for B = 2, this equation can be simplified to: − −

v u 2 u1 X p σ = t (x[n] µ[b])2 = (x[n] µ[b])2 = x[n] µ[b]. (4.17) 2 n=1 − − −

In other words, the standard deviation of a batch of B = 2 samples is half the difference of the samples. Figure 4.12a shows a graphical representation of a noise-free sawtooth signal with a linear progress for the ramp and crash segments. Figure 4.12b shows the signal after applying a 1st order difference filter and Figure 4.12c the signal after applying the standard deviation with B = 2. The sawtooth crash is not recognizable in Figure 4.12c due to the calculation of the difference between sequencing batches. The 1st order difference filter determines the difference between sequencing samples. Therefore, the computational complex- ity is reduced and the time resolution remains equal to the sample time Ts. In Subsection 3.1.3 the standard deviation of subsequent batches was subtracted from each other, to emphasize the difference in statistical dispersion between subsequent batches. Obviously, this only makes sense for larger batch sizes.

The conclusion drawn here is that applying a 1st order filter to the sawtooth signal emphasizes the crash with respect to the statistical dispersion of the sawtooth. The filtered signal will show large peaks where the crashes appear, but also some peaks will be caused by the remaining noise in the signal. The transfer function of a 1st order difference filter is given by:

H[z] = 1 z−1. (4.18) − and the difference equation by:

y[n] = x[n] x[n 1]. (4.19) − − In the next subsection the 1st order difference filter is applied to the signal. 60 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

(a) Sawtooth signal

(b) 1st order difference filter

(c) Standard deviation for a batch with B = 2

Figure 4.12: Difference

4.2.2 1st order difference filter Applying the 1st order difference filter to the signal of all five channels results in the signals of Figure 4.13.

The figures of the channels with 132.5 and 135.5 [GHz] show negative peaks while the channels with 141.5 and 144.5 [GHz] show positive peaks. This corresponds to the crash and jump respectively in the sawtooth signal. The signal from channel 138.5 [GHz] does not show a clear sawtooth oscillation in Figure 4.10 and, therefore, neither the clear positive or negative peaks in the filtered signal. The fourth power is taken from the filtered signals, to level between positive and negative values and to amplify large jumps with respect to smaller noise influences. The resulting signals are shown in Figure 4.14. 4.2. DATA PROCESSING METHOD 61

0.03 0.03

0.02 0.02

0.01 0.01

0 0

−0.01 −0.01

−0.02 −0.02

−0.03 −0.03 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (a) Channel 132.5 GHz (b) Channel 135.5 GHz

0.03 0.03

0.02 0.02

0.01 0.01

0 0

−0.01 −0.01

−0.02 −0.02

−0.03 −0.03 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (c) Channel 138.5 GHz (d) Channel 141.5 GHz

0.03

0.02

0.01

0

−0.01

−0.02

−0.03 2 2.05 2.1 2.15 (e) Channel 144.5 GHz

Figure 4.13: Signals per channel after application of a 1st order difference filter.

Figure 4.14 shows that the noise level in each of the channels is of different size. By normalizing the signals, this noise level becomes equal for all channels, after which the signals of the different channels can be combined to obtain extra variables for the detection of the sawtooth crash. The normalization process is described in Section 4.3. 62 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

−9 −9 x 10 x 10 5 5

4 4

3 3

2 2

1 1

0 0 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (a) Channel 132.5 GHz (b) Channel 135.5 GHz

−9 −9 x 10 x 10 5 5

4 4

3 3

2 2

1 1

0 0 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (c) Channel 138.5 GHz (d) Channel 141.5 GHz

−9 x 10 5

4

3

2

1

0 2 2.05 2.1 2.15 (e) Channel 144.5 GHz

Figure 4.14: Filtered signals to the fourth power.

4.3 Normalization

The signals have to be normalized before the signals can be further processed, to obtain equal noise levels for each channel. The normalization is realized by estimating the noise contribution in each signal by means of determining the average of the smallest 92% of the data in relation to the total average. This procedure can be split into three steps: buffering the signals, determination of the noise level per channel and finally, the actual normalization of the signals. 4.3. NORMALIZATION 63

4.3.1 Buffering the signals In shot 106478 the noise levels at the channels are nearly constant during the whole discharge, but this is not necessary true for other shots. Figure 4.15 shows the filtered signals of the fifth channel of shot 106480, which clearly shows that the noise level in a channel can also vary with time. Therefore, real-time determination of the noise levels is necessary.

−10 x 10

1.8

1.6

1.4

1.2

1

0.8

0.6

0.4

0.2

0 1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3 Figure 4.15: The processed signal from channel 144.5 [GHz] of shot 106480 with a time-varying noise level.

The noise levels are recalculated every 5000 samples. This is done by storing the incoming signal samples in buffers with a buffer size of 5000 samples. When the buffers is saturated, the next step is performed on the content of the buffers and new buffers are constructed. A buffer size of 5000 samples is chosen with use of the data of shot 106478. This shot has a mean period of 1174 samples, see Subsection 4.1.1, so one buffer will contain at least 4 whole sawteeth. Increasing the buffer size will increase the accuracy of the approximation of the noise level, but the application will have a larger computational complexity. Furthermore, the first 5000 samples can not detect a sawtooth crash since these samples are only used to determine an initial noise level estima- tion. Increasing the buffer size means increasing the initial delay of the eventual controller.

In the next subsection the noise level of the signals is determined with help of the buffered samples, by making a distinction between crash samples and ramp samples.

4.3.2 Noise level determination Studying several sawteeth of shot 106478 gives an indication of the number of samples in the crash part of a sawtooth. It appears that there is a small range in numbers of samples in one crash, with a mean of approximately 40 samples. This corresponds with approximately 3.2% of the total number of samples in one sawtooth. For this shot, sorting the 5000 samples and averaging 96.8% of the low- est values would give a good estimation of the noise level. By looking at other shots it turns out that the number of samples in the crash is variable and not necessary related to the period. Choosing a percentage significantly lower than 96.8% assures that all the crash-samples are excluded when deter- mining the noise level, but for very noisy channels it also results in a too low estimation of the noise level, because the biggest noise is left out.

The average of the lowest 92% of the buffer with 5000 samples is calculated and this represents the noise level of the signal. 64 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

4.3.3 Normalizing the signal Dividing the five signals by the corresponding estimated five noise levels gives the normalized signal per channel, with approximately equal noise levels for all channels, see Figure 4.16.

1000 1000

800 800

600 600

400 400

200 200

0 0 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (a) Channel 132.5 GHz (b) Channel 135.5 GHz

1000 1000

800 800

600 600

400 400

200 200

0 0 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (c) Channel 138.5 GHz (d) Channel 141.5 GHz

1000

800

600

400

200

0 2 2.05 2.1 2.15 (e) Channel 144.5 GHz

Figure 4.16: Normalized

The normalized signals can be used to determine the moments of crash. In the next section is ex- plained how samples belonging to the sawtooth crash are distinguished, by comparing the signal samples with some predefined thresholds.

4.4 Determination crash times

The moment of crash can be determined with use of the obtained processed signals. Hereto, the signals and combinations of the signals are compared with thresholds in Subsection 4.4.2, to obtain a series of crash times. In Subsection 4.4.3 and 4.4.4 the crash times from all of the five channels and the combined channels are processed to obtain an exact moment of crash.

4.4.1 Combining channels The signals from each of the channels can be considered as a separate variable when trying to detect a crash. The number of detection variables can be increased by combining the channels. Only the sum 4.4. DETERMINATION CRASH TIMES 65 and product of all of the concerned channels are considered here, since increasing the variables also increases the computational complexity, which is unfavorable for real-time implementation. Figure 4.17 shows the sum and product of the separate channels between t = 2 [s] and t = 2.15 [s].

8 x 10 1000 10

800 8

600 6

400 4

200 2

0 0 2 2.05 2.1 2.15 2 2.05 2.1 2.15 (a) Sum (b) Product

Figure 4.17: Sum and product of the separate channels of shot 106478.

4.4.2 Comparing with thresholds

Three thresholds are defined: a threshold for the signals of the separate channels, a threshold for the summed signals and a threshold for the multiplied signals. As soon as one of the signals exceeds its threshold, the (exceeding) time is registered. The height of the thresholds is determined by consider- ing the normalized (combined) signals of several shots and making a trade-off between the number of skipped crashes and the number of false detected crashes. The obtained thresholds for the separate, summed and multiplied channels are listed in Table 4.2.

Threshold Separate and summed channels 400 Multiplied channels 1000

Table 4.2: Thresholds for the separate, summed and multiplied channels.

4.4.3 Hold subsequent exceeding times

Different channels can detect the same crash at slightly different sample points. Therefore, all of the separate channels and the combined channels are checked at the same time and the exceeding times belonging to one and the same crash are stored in four buffers. One buffer stores the exceeding times of the separate channels, at which only moments at which at least at two channels the signal exceeds the thresholds are encountered. This is done to permit an as low as possible threshold for the separate channels to detect as much crashes as possible, while reducing the number of false detected crash moments. Two buffers store the exceeding times of the summed and multiplied channels and the third buffer stores the crash samples of the separate, summed and multiplied channels all together. The algorithm can detect multiple crash samples for the same crash, see Figure 4.18. One should determine whether the exceeding of the threshold belongs to the crash of the previous sawtooth or a new sawtooth. Crash samples which occur at the most 0.7 [ms] apart are classified as being from the same crash. So, after a crash detection on two of the separate channels or either one of the combined channels, the algorithm ’waits’ at the most for 0.7 [ms] until the final crash time is determined and new buffers are created. 66 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

6.4

6.3

6.2

6.1

6 Temperature [A.U.] 5.9

5.8 2 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 Time [s]

Figure 4.18: Part of the filtered sawtooth signal of channel 132.5 [GHz] with detected moments of crash.

4.4.4 Determination exact crash-times

If there are multiple crash samples stored in a buffer, the exact begin and end times of the crash are defined as the first and last samples. The final crash time is calculated as the mean between the begin and end time. Figure 4.19 shows the final crash times of a number of sawtooth crashes from shot 106478 between t = 2 [s] and t = 2.1 [s], determined from the buffer with the stored crash samples of the separate, summed and multiplied channels all together.

6.4

6.3

6.2

6.1

6 Temperature [A.U.] 5.9

5.8 2 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 Time [s]

Figure 4.19: Center moment of crash.

The operations discussed so far results in the exact begin, end and center crash times of a sawtooth crash from the separate and combined channels. The next section explains how the corresponding periods are determined.

4.5 Period

Three different periods are calculated by adding a first order difference filter to the obtained exact crash-times of the separate, summed and multiplied channels, see Figure 4.20. The 1st order differ- ence filter corresponds to the one described in Subsection 4.2.2. Applying the 1st order difference filter to the combined crash-times of the separate, summed and multiplied channels results in the final period of Figure 4.21. As can be seen, the algorithm detects all of the crashes and no crashes are false detected. 4.6. INVERSION RADIUS 67

Separate channels 0.0135 Summed channels Multiplied channels 0.013

0.0125

0.012

0.0115

Period [s] 0.011

0.0105

0.01

0.0095

0.009 1 1.5 2 2.5 3 3.5 4 4.5 5 Time [s]

Figure 4.20: Estimated periods for the separate and combined channels.

0.0135

0.013

0.0125

0.012

0.0115

Period [s] 0.011

0.0105

0.01

0.0095

0.009 1 1.5 2 2.5 3 3.5 4 4.5 5 Time [s]

Figure 4.21: Final period.

4.6 Inversion radius

The algorithm determines the real-time location of the inversion radius by looking at the shapes of the crashes at the different channels. When the inversion radius is located in between two ECE channels at one channel the crash can be seen as a sudden drop of temperature, while at the other channel the crash can be detected as a jump in the sawtooth signal. Consequently, the location of the inversion can be detected by an opposite sign between the last and the first samples of the crashes from subsequent channels. The first and last samples of the crashes are already known and used by the algorithm for the determination of the period. Subtracting the temperature values of these samples results in the required information about the shapes of the crashes (jump or fall) and consequently, in the desired location of the inversion radius.

Figure 4.22 shows the location of the inversion radius during the discharge between t = 1 [s] and t = 5 [s]. As can be seen, the location of the inversion is nearly constant between channel 135.5 [GHz] and channel 138.5 [GHz]. 68 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM

144.5 [GHz]

141.5 [GHz]

138.5 [GHz] Channel

135.5 [GHz]

132.5 [GHz]

1 1.5 2 2.5 3 3.5 4 4.5 5 Time [s]

Figure 4.22: Location of the inversion radius.

4.7 Algorithm analysis

The performance of the algorithm for the real-time detection of sawtooth crashes can be examined according to the required properties stated in Section 3.5.

4.7.1 Computational complexity

A restriction on the implementation is the computational complexity; the designed algorithm should be implemented real-time, so the number of operations needed to compute the period should be as low as possible.

The computational effort of the algorithm depends for example on the number of ECE channels, but also on the complexity of the statistical operations performed on these input signals. The computa- tional complexity can not for all of the operations performed be described by the number of arithmetic operations required, since some functions do not require any arithmetic operations. For example, in sorting algorithms there are no arithmetic operations, only data comparison and data movement [7]. The computational complexity of the ’sort’ function and other comparison functions like the ’if’ and ’find’ functions, can be expressed by the number of comparisons and data movements. In Table 4.3, the maximum number of multiplications and additions required for the computation of the main algorithm operations are listed per input sample. The variable nch represents the number of observed channels and B the buffer size for the calculation of the noise level. The number of move- ments is not included, since this operation requires significantly less computational effort than the other three operations [7]. A number of functions used in the algorithm, such as the ’abs’ and ’round’ functions, are not listed, since these operations are easier to perform.

The operations listed in Table 4.3 are performed on all of the input samples. In the real-time im- plementation, if the algorithm does not detect a crash for more than 0.7 [ms] the exact crash times, position of the inversion radius and the periods are determined from the preceding stored crash sam- ples. Table 4.4 lists the total number of multiplications, additions and comparisons to be performed 0.7 [ms] after the last crash sample is detected. The number of stored crash samples per channel is assumed to be equal to the number of crash samples in the channel with the highest number of crash samples ncs. 4.7. ALGORITHM ANALYSIS 69

Algorithm function Multiplications Additions Comparisons Delay Low-pass filter 3rd order Butterworth filter 7 6 0 3 [samples] Signal processing 1st order difference function 0 1 0 1 [samples] arithmetic operations 3 0 0 0 Normalization function

2 quick sort functions 0 0 B(B 1)nch 0 − 1 mean function nch B 1 0 0 − 1 if function 0 0 1 0 arithmetic operations 3 1 0 0 Combining channels

summation of the channels 1 nch 1 0 0 − product of the channels nch 1 0 0 0 − Comparing with thresholds

1 if function 0 0 nch + 2 0 Observing last crash moments

1 if function 0 0 nch + 2 0.7 [ms]

Table 4.3: Computational complexity and delay of the algorithmic operations per sample time.

Algorithm function Multiplications Additions Comparisons Delay Determination exact crash times

1 find function 0 0 4ncs 0 st 1 order difference function 0 4ncs 1 0 0 − dc 2 mean functions 4 8 0 2 [samples]

arithmetic operations 2nch 0 0 0 Determination inversion radius

arithmetic operations 2nch nch 0 0 Determination period 1st order difference function 0 4 0 0

Table 4.4: Total computational complexity and delay of the algorithmic operations after the last crash sample.

The computational complexity of the designed algorithm depends on the number of ECE channels analyzed, the number of crash samples per crash and most important, the number of samples in the normalization buffer, which is equal to B = 5000 [samples]. The order of the number of arithmetic operations is B. The buffer size B can be changed in order to reduce the computational complexity, but in that caseO the noise level determination becomes more sensitive to spikes in the noise of the signal, resulting in a less reliable noise level determination. The number of comparisons is of the 70 CHAPTER 4. TIME DOMAIN SAWTOOTH RECOGNITION ALGORITHM order of B2 operations and depending on the software and hardware of the implementation system these operationsO are more or less time consuming than the arithmetic operations. Compared to the signal analysis methods discussed in the previous chapter, the computational complexity is signifi- cantly lower and the operations needed to determine the period and location of the inversion radius are presumably satisfactory low to implement the algorithm real-time on TEXTOR. Another important property for the real-time implementation of the sawtooth crash detection algo- rithm is the delay between the sawtooth crash and the moment of period estimation, resulting from the computational operations performed. Table 4.3 and Table 4.4 show the delay corresponding to specific operations which attends with a delay. The input of the low-pass filter and the 1st order differ- ence filter at the beginning of the algorithm result in a total delay of 4 samples. The ’if’ function at the end of Table 4.3 observes for 0.7 [ms] if any new crash moments are detected, before the final begin, end and central crash moments are determined in the separate and combined channels. Therefore, this operation results in a time delay of 0.7 [ms], or in case of shot 106478 with a sample frequency 5 fc = 1 10 , a delay of 70 samples. The exact time of crash is defined as the center moment between · dc the first and last crash detection of a certain crash. Consequently, this results in a delay of 2 samples between the exact time of crash and the last crash detection, at which dc represents the total number of crash samples. Adding the separate delays gives an estimation of the total delay between the exact crash time and the moment of algorithm output. 40 For shot 106478, with a mean of dc = 40 samples, the total average delay is 1 + 3 + 70 + 2 = 93 samples, which corresponds to 0.93 [ms]. The sawteeth of shot 106478 contain on average 1174 samples, and therefore the delay is approximately 7.9% of the total number of samples per period. This seems acceptable, since drastic changes in the period typically requires a few sawteeth, except for the changes due to changed settings of the diagnostics.

4.7.2 Clarity The clarity of the algorithm can be determined by the accuracy and reliability of the detected crashes for a wide range of sawtooth periods, crash sizes and sawtooth shapes. The results of the time domain algorithm are unambiguous, since the obtained time domain plots of the period and the inversion radius of the sawtooth signal do not show any misleading information, like the deceptive cross-terms of the distributions from Cohen’s Class can do. Therefore, the clearness and reliability of the results of the time domain algorithm is excellent. In this chapter the algorithm was designed by use of and applied to the sawtooth signals of TEXTOR shot 106478. For this shot, the center of the crash determined by the algorithm are accurately located on top of the crashes, see Figure 4.19 and the detection algorithm detected all of the crashes and did not detect any extra non-existing crashes, so this indicates on a accuracy of 100%. However, the sawtooth signal of this shot has a nearly constant period, crash size and sawtooth shape. In the next chapter the performance of the designed algorithm is inspected on two more shots with varying sawtooth period and shape. Chapter 5

Results

In this chapter the performance of the crash detection algorithm is tested on TEXTOR shots 107915, 110051, 110178 and 110185 with respect to the accuracy of the algorithm. These shots show varying noise levels, sawtooth periods, crash lengths and sawtooth shapes, as a result of the changed input of the diagnostics and the corresponding varying location of the inversion radius in the plasma.

5.1 Operating regime

The plasma in TEXTOR is dominantly heated by two NBI systems. The settings of the NBI systems and other diagnostics during the shots are listed in Table 5.1. As can be seen, the ECCD is turned off during the first two shots, but it is activated for the last two shots between t = 2 [s] and t = 4 [s] with a power of 400 [kW]. The total plasma current during the discharges is Ip = 350 [kA] and the toroidal magnetic field is Bθ = 2.5 [T] for shot 107915 and Bθ = 2.45 [T] for the other shots.

ECCD NBI 1 NBI 2 Ip [kA] Ip [kA] Bθ[T ] ECCD [kW] on off on off on off 107915 400 2.5 0 -- 1 5 1.5 3 110051 400 2.45 0 -- 1 5 1.5 4.5 110178 400 2.45 400 2 4 1 5 1.5 4.5 110185 400 2.45 400 2 4 1 5 1.5 4.5

Table 5.1: Settings of the diagnostics.

5.2 Shot 107915

First the algorithm is applied to shot 107915. Figure 5.1 shows the sawtooth signals of the five ECE channels of shot 107915. Since the plasma is dominantly heated by the NBI, the activation and shutting down of the NBI 2 system is clearly visible at t = 1.5 [s] by an instant jump in the sawtooth signal and at t = 3 [s] by a rapid fall respectively. The crash length and period also changes gradually, resulting from this increased temperature.

71 72 CHAPTER 5. RESULTS

7 132.5 GHz 135.5 GHz 138.5 GHz 141.5 GHz 144.5 GHz 6

5

4

3 Temperature [A.U.]

2

1

0 1 1.5 2 2.5 3 3.5 Time [s]

Figure 5.1: Sawtooth signal of shot 107915.

0.04

0.035

0.03

0.025

0.02 Period [s] 0.015

0.01

0.005

0 1 1.5 2 2.5 3 3.5 Time [s]

Figure 5.2: The period of shot 107915. 5.2. SHOT 107915 73

Figure 5.2 shows the period of the sawtooth signal, obtained by the crash detection algorithm. The period varies in time as a result of the actuation of the NBI 2 system and the applied current drive. A gradual increase in period is visible at t = 1.5 [s], corresponding to the increased period shown at Figure 5.3a of channel 135.5 [GHz].

6.2 5.8 6 5.6 5.8 5.4 5.6 5.2 5.4 Temperature [A.U.] Temperature [A.U.] 5 5.2 4.8 5 1.5 1.55 1.6 1.65 1.7 1.75 1.8 2.5 2.55 2.6 2.65 2.7 2.75 2.8 Time [s] Time [s] (a) Zoom 1 (b) Zoom 2

Figure 5.3: Zoom of shot 107915, channel 135.5 [GHz]. During the discharge the location of the inversion radius varies with time, resulting in a change of crash length and a switch between positive and negative crashes at each of the channels. This can be seen in Figure 5.4. For channel 135.5 [GHz], this switch is clearly visible around t = 2.6 [s], see Figure 5.3b. This figure also shows the cause of the fall and jump in the period between t = 2.5 [s] and t = 2.8 [s]. The crash after t = 2.66 [s] is not detected since the crash has a gradual slope, while at t = 2.71 [s] a crash is false detected, caused by a small disturbance in the signal.

144.5 [GHz]

141.5 [GHz]

138.5 [GHz] Channel

135.5 [GHz]

132.5 [GHz]

1 1.5 2 2.5 3 3.5 Time [s]

Figure 5.4: Location of the inversion radius.

For shot 107915 the algorithm only failed twice at the previously mentioned missed and false detected crashes between t = 2.65 [s] and t = 2.75 [s]. In total there were 75 crashes between t = 1.5 [s] and t = 3 [s], not including the disturbance due to the shut down of NBI 2 system. Furthermore, the crash detections of the correct detected crashes are precisely located on top of the crash. Therefore, this results in an accuracy of the algorithm of 98.67% for this shot with strongly varying crash lengths, crash shapes and sawtooth period. 74 CHAPTER 5. RESULTS

5.3 Shot 110051

Next, the algorithm is applied to shot 110051, see Figure 5.5 for the sawtooth signals of the five ECE channels.

7 132.5 GHz 135.5 GHz 138.5 GHz 141.5 GHz 144.5 GHz 6

5

4

3 Temperature [A.U.]

2

1

0 2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 3.8 4 Time [s]

Figure 5.5: Sawtooth signal of shot 110051.

0.04

0.035

0.03

0.025

0.02 Period [s] 0.015

0.01

0.005

0 2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 3.8 4 Time [s]

Figure 5.6: The period of shot 110051. 5.3. SHOT 110051 75

Figure 5.6 shows the corresponding period between t = 2 [s] and t = 4 [s] of shot 110051. As can be seen, the period is nearly constant with one missed crash detection near t = 2.25 [s].

Two zoomed figures of the sawtooth crash of channel 135.5 [GHz] in Figure 5.7 clearly show the change in crash shape, as a result of the changed location of the inversion radius depicted in Figure 5.8.

6 6

5.5 5.5

5 5 4.5 Temperature [A.U.] Temperature [A.U.] 4.5 4

3.5 4 2.4 2.5 2.6 2.7 2.8 3.4 3.5 3.6 3.7 3.8 Time [s] Time [s] (a) Zoom 1 (b) Zoom 2

Figure 5.7: Zoom of shot 110051, channel 135.5 [GHz].

144.5 [GHz]

141.5 [GHz]

138.5 [GHz] Channel

135.5 [GHz]

132.5 [GHz]

2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 3.8 4 Time [s]

Figure 5.8: Location of the inversion radius.

The performance of the algorithm is again very good for this shot. One missed crash out of 144 crashes in total results in an accuracy of 99.31%. The accuracy of the correctly detected crashes is also good as can be seen from the vertical dashed stripes in Figure 5.7, which indicate the center crash determined by the algorithm and are located accurately on the crash. 76 CHAPTER 5. RESULTS

5.4 Shot 110178

Figure 5.9 and Figure 5.10 show the sawtooth signals and corresponding sawtooth period of the five ECE channels of shot 110178 between t = 1.8 [s] and t = 4.2 [s].

6 132.5 GHz 135.5 GHz 138.5 GHz 141.5 GHz 144.5 GHz 5

4

3 Temperature [A.U.]

2

1

0 2 2.5 3 3.5 4 Time [s]

Figure 5.9: Sawtooth signal of shot 110178.

0.04

0.035

0.03

0.025

0.02 Period [s] 0.015

0.01

0.005

0 2 2.5 3 3.5 4 Time [s]

Figure 5.10: The period of shot 110178. 5.4. SHOT 110178 77

The actuation of the ECCD system at t = 2 [s] with a power of 400 [kW] results in a sudden increase in sawtooth period, which is clearly visible in Figure 5.10 and in the zoomed figure of the signal between t = 1.8 [s] and t = 2.2 [s], see Figure 5.11a. The period gradually decreases after t = 2 [s] and at t = 4 [s] the shut down of the ECCD system is clearly visible as a drop in temperature and period, see Figure 5.11b.

3.6 2.2

3.4 2 3.2

3 1.8

2.8 1.6 2.6

2.4 1.4 Temperature [A.U.] Temperature [A.U.] 2.2 1.2 2

1.8 1 1.8 1.9 2 2.1 2.2 3.8 3.9 4 4.1 4.2 Time [s] Time [s] (a) Zoom 1 (b) Zoom 2

Figure 5.11: Zoom of shot 110178, channel 135.5 [GHz].

The location of the inversion radius stays constant between the channels with 135.5 [GHz] and 138.5 [GHz] until approximately t = 3 [s] and then gradually moves away from the ECE channels.

144.5 [GHz]

141.5 [GHz]

138.5 [GHz] Channel

135.5 [GHz]

132.5 [GHz]

2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 3.8 4 Time [s]

Figure 5.12: Location of the inversion radius.

The algorithm detected only one crash too many between t = 1.8 [s] and t = 4.2 [s]. This false detected crash is not included when judging the performance of the algorithm since this crash detection is a result of the large disturbance at t = 4 [s], due to the shutted down ECCD system. Therefore, the accuracy of the algorithm is 100% for this shot with strongly varying sawtooth period. 78 CHAPTER 5. RESULTS

5.5 Shot 110185

Finally, the algorithm is applied to shot 110185. Figure 5.13 shows the sawtooth signals of channels 132.5 [GHz] and 135.5 [GHz] between t = 2.7 [s] and t = 3.3 [s]. This shot is not representative for typical discharges of TEXTOR, but it is treated here to emphasize the operation of the algorithm nor- malization function and check the performance of the algorithm for varying sawtooth shaped signals. As can be seen, both signals contain substantially more noise between t = 3.1 [s] and t = 3.3 [s] than between t = 2.7 [s] and t = 3 [s] and the shape of the sawteeth is significantly different. Nevertheless, the crashes are detected accurately, due to the normalization of the signals and the distinct crashes. Between approximately t = 3 [s] and t = 3.1 [s] the algorithm falsely detects a number of crashes, due to the absence of two subsequent crashes after t = 3 [s], which results in a too low noise level estimation when 92% of the highest signal values is determined, since the highest noise samples are included instead of 8% of the crash samples.

12

10

8

6 Temperature [A.U.]

4

2

0 2.7 2.8 2.9 3 3.1 3.2 3.3 Time [s]

Figure 5.13: Zoomed sawtooth signal of shot 110185, channels 132.5 [Hz] and 135.5 [GHz].

5.6 Concluding remarks

The overall conclusion drawn here about the performance of the designed sawtooth recognition al- gorithm is that the algorithm accurately and reliably detects crashes of sawtooth signals with vary- ing noise levels, sawtooth periods, crash lengths and sawtooth shapes. The achieved accuracy varies between 98.67% and 100%. Furthermore, a sudden increase in noise level can be captured by the algorithm normalization function, as long as the crash length grows uniformly with the noise level. Chapter 6

Conclusion

An important instability occurring in nuclear plasmas in a tokamak reactor during discharge is the sawtooth instability. Although the sawtooth instability by itself is not a direct threat for maintaining nuclear fusion in a tokamak, control of the sawtooth period is necessary to control the unfavorable onset of NTM’s, which can lead to an abrupt end of discharge with possible severe tokamak damage. Sawtooth control also enables the control of the density of helium ash in the plasma center, which is desired to prevent dilution of the plasma.

Signal analysis methods for sawtooth detection algorithms In this thesis different signal analysis methods were reviewed and investigated for application in a real-time crash detection algorithm. The performance of the methods were investigated by their rep- resentation in the time, frequency or time-frequency domain. Furthermore, the clarity of the repre- sentation was investigated by means of the accuracy of the moment of crash and the reliability of the obtained results. Finally, the computational complexity of the signal analyzing methods plays an im- portant role when designing a real-time algorithm.

Only the analysis techniques with a time domain or time-frequency domain representation are appli- cable for the sawtooth recognition problem, in order to be able to identify the moment of crash, and therefore the frequency domain Fourier Transforms are not suited for the application in a detection algorithm. The remaining time domain algorithm, Short-time Fourier Transform, Discrete Wavelet Transform and two distributions from Cohen’s class; the Wigner-Ville and Choi-Williams distribu- tions were further investigated. According to results obtained in different experiments based on the recognition of sawtooth crashes or the onset of NTM’s, especially the application of the Wigner-Ville distribution function obtained good results concerning the accuracy of the moment of crash, due to the optimal temporal and spectral resolutions simultaneously. However, the clearness of these results can be ambiguous due to the cross-terms involved with auto-correlation functions. Therefore, the reli- ability is questionable. The Choi-Williams distribution function masks these cross-terms by means of a kernel function but at the expense of the optimal time and frequency resolutions. The constant time and frequency resolution of the STFT for all frequencies resulted in the considered researches in too low time resolutions for the higher frequencies and a too coarse frequency resolution to clearly detect the lower frequency NTM’s and the sawtooth crashes. The results obtained by applying a continuous Morlet wavelet were even worse, resulting from the constant relative time and frequency resolutions. Using an other wavelet family with a more irregular shape instead of the Morlet wavelets which con- sists of complex sinusoids multiplied by a Gaussian window, would presumably result in much better results. The computational complexity of the analysis methods depends strongly on the implementation method used and can be expressed in the number of arithmetic operations needed to calculate the output. A time domain algorithm based on a difference filter, or other statistical operations to emphasize the

79 80 CHAPTER 6. CONCLUSION statistical dispersion along a sawtooth, require only a number of multiplications and additions in the order B, at which B represents the number of samples in a data set. The computational complexity of theO STFT and the DWT for a FFT length of N are both of the order of (N log N) arithmetic oper- O 2 ations, while the distributions from Cohen’s class require (N log2 N) multiplications and additions per plot. O

According to the literature study of the signal analysis methods with respect to the required prop- erties of the sawtooth recognition algorithm, a time domain algorithm seems favorable for realtime detection of the sawtooth period, due to the low computational complexity and the unambiguity of the obtained time domain representation. If the time domain algorithm fails to produce satisfying results, using the straightforward STFT, for which numerous efficient real-time implementation algorithms are available, might be advantageous compared to the other analysis methods.

Time domain sawtooth detection algorithm In Chapter 4 a time domain algorithm was designed for real-time recognition of sawtooth crashes in TEXTOR data. The design procedure started with the application of a Butterworth low-pass filter to at- tenuate the high-frequent noise. Next several data processing methods were considered, to emphasize the difference in statistical dispersion of the samples in the sawtooth crash. A first order difference filter seemed to obtain the best results. Since the noise level is different for different ECE channels, a normalization function is included in the algorithm, before the exact crash samples were determined from the separate and combined channels. Finally, the final real-time period and location of the in- verse radius were determined by the algorithm.

The performance of the algorithm with respect to the clarity is very good, with an accuracy between 98.67% and 100% for sawtooth signals with varying noise levels, sawtooth periods, crash lengths and sawtooth shapes. Only a few crashes with a gradually progress are not detected by the algorithm and a few crashes were falsely detected by the algorithm, due to significant disturbances in the sawtooth signals. A sudden increase in noise level can be captured by the algorithm normalization function, as long as the crash length grows uniformly with the noise level. Furthermore, the results of the time domain algorithm are unambiguous, since the obtained time domain plots of the period and the inversion radius of the sawtooth signal do not show any misleading information, like the deceptive cross-terms of the distributions from Cohen’s Class can do. This results in a high reliability of the results obtained by the detection algorithm. The computational complexity of the designed algorithm in terms of the number of arithmetic op- erations per sample time is of the order B, at which B represents the number of samples in the normalization buffer. In the algorithm theO buffer size B equals B = 5000 [samples]. This number can be changed in order to reduce the computational complexity, but at the expensive of the reliability of the noise level determination. The number of comparisons is of the order of B2 operations and depending on the software and hardware of the implementation system these operationsO are more or less time consuming than the arithmetic operations. The computational complexity of the designed time domain algorithm is significantly lower than the complexity of the time-frequency domain signal analysis methods discussed Chapter 3, and will presumable be sufficiently low for real-time imple- mentation on TEXTOR.

With respect to the predefined required properties for real-time crash detection in the sawtooth signal, the analysis and performance of the designed time domain algorithm shows promising results for real-time determination of the period and the location of the inversion radius for sawtooth signals with varying noise levels, sawtooth periods, crash lengths and sawtooth shapes. If the time domain algorithm fails to produce satisfying results with real-time implementation, crash detection algorithms using the STFT or the Choi-Williams distribution is recommended, or a DWT algorithm with other wavelet families than the Morlet wavelets. Appendix A

Appendix I

A.1 Euler’s formula

j2π n t n n e T = cos(2π t) + jsin(2π t) (A.1) T T

Figure A.1 shows a graphical representation of Euler’s formula in the complex plane.

Im i

eiθ = cos(θ) + isin(θ)

θ sin(θ) A 0 cos(θ) 1 Re

Figure A.1: Complex plane

A.2 Interpretation negative frequencies

Figure A.2 represents a typical (co)sinusoide with amplitude A, initial phase θ and frequency f in both the amplitude-time plane and the complex plane. In the first part of the figure, the meaning of the negative frequency is not very clear. From the complex plane figuration, where the sinusoidal com- ponent is represented as the sum of two contra-rotating vectors with amplitude A/2, it becomes clear that the negative frequency indicates rotation in opposite direction or with other words, a negative rate of change of phase angle.

81 82 APPENDIX A. APPENDIX I

Ampl T (= 1 ) f Re 1

A θ θ θ − f A/2 -f Time (seconds) Im i 0 Phase (radians)

A

Figure A.2: Sine in the amplitude-time and the complex plane

A.3 Power spectrum

The frequency-domain representation of a signal is known as the power spectrum, and it reflects the squared amplitudes of the Fourier coefficients in the frequency spectrum. Other well-known power spectra are the 1-sided power spectrum, the (RMS) amplitude spectrum and the dB spectrum. These 1-sided power spectra have a peak amplitude of A, simple resulting from adding the amplitudes of the positive and negative frequencies.

A.4 Aliasing

With aliasing higher frequencies are incorrectly identified as lower frequencies. Let’s for example con- sider the periodogram of the signal x(t) with a frequency range between zero and 1/4 fs, see figure A.3.

f 1f 0 1f f 3f f 1f 0 1f 1f f 3f − s −2 s 2 s s 2 s − s −2 s 4 s 2 s s 2 s Figure A.3: No aliasing occurs, since the highest frequency is still lower then the new sample frequency.

In discrete time the spectrum is periodic with the sample frequency. Downsampling the signal results in a sample frequency of 1/2 fs. As can be seen in figure A.3 none of the amplitudes of the original signal overlap their 1/2 fs periodic component, as there is no aliasing. This corresponds to what’s stated before; aliasing does not occur when the highest frequency is still lower then the new sample frequency 1/2 fs.

Figure A.4 shows the periodogram for a signal bandlimited at 1/2 fs before the downsampling, figure A.4, and after downsampling the signal, figure A.4. In this case there is some aliasing because the A.5. COMPUTATIONAL COMPLEXITIES 83

Aliasing

1 1 3 1 1 1 3 fs fs 0 fs fs fs fs f 0 f f fs f − −2 2 2 − −2 s 4 s 2 s 2 s Figure A.4: Aliasing occurs at which the higher frequencies appear incorrectly as lower frequencies.

higher frequencies with a frequency between 1/4 fs and 1/2 fs appear incorrectly as lower frequen- cies. Figure A.5 shows that an original signal with a frequency range between 1/4 fs and 1/2 fs can be accurately downsampled, without any aliasing and that the frequency content of the downsampled signal is only present above the new Nyquist frequency.

f 1f 0 1f f 3f f 1f 0 1f 1f f 3f − s −2 s 2 s s 2 s − s −2 s 4 s 2 s s 2 s Figure A.5: No aliasing occurs, since the frequency content of the downsampled signal is only present above the new Nyquist frequency.

The conclusions we can draw with relation to the occurrence of aliasing while downsampling a signal, is that aliasing will never take place when the maximum frequency of the signal is lower then the new Nyquist frequency, which can be derived by taking half the sample frequency divided by the level of downsampling M. Aliasing is also bound to happen when the original signal is concentrated in only one of the bands of the original spectrum, where the bands are created by partitioning the original spectrum in M parts, because in that case there is also no overlap.

A.5 Computational complexities

In this appendix the computational complexity of implementation algorithm for the different signal analysis methods are listed, with the computation complexity defined as the number of arithmetic operations. 84 APPENDIX A. APPENDIX I

A.5.1 Time domain processing methods

Method Number of multiplications and additions Difference filter 1 Averaging + DF 2B Standard deviation + DF 6B

Table A.1: Computational complexity per time domain processing method.

A.5.2 FFT algorithms

Method Number of real multiplications and additions DFT 12N 2 4N − radix-2 [18] 5N log2 N split-radix [12] 2N log N 4N + 6 2 − 17 89 1 8 modified split-radix [18] N log N N log N ( 1)log2 N log N + ( 1)log2 N + 6 9 2 − 27 − 2 − 9 − 2 27 − Table A.2: Computational complexity per FFT algorithm.

These number of real multiplications and additions are derived from the number of complex multi- plications and additions, resulting from the complex term involved in the DFT computation, at which one complex multiplication in DFT and FFT is implemented with four real multiplications and two real additions. For example, evaluating the DFT directly involves N2 complex multiplications and N(N 1) complex additions, which results in a total of 12N 2 4N real additions and multiplica- tions.− The savings of the split-radix and modified split-radix algorithms− are due to simplifications of the complex multiplications.

A.5.3 STFT algorithms

Method Number of real multiplications and additions DFT 12N 2 3N − radix-2 5N log2 N + N split-radix 2N log N 3N + 6 2 − 17 62 1 8 modified split-radix N log N N log N ( 1)log2 N log N + ( 1)log2 N + 6 9 2 − 27 − 2 − 9 − 2 27 − Table A.3: Computational complexity per STFT algorithm. A.5. COMPUTATIONAL COMPLEXITIES 85

A.5.4 DWT algorithms

Implementation algorithm Number of real multiplications and additions DWT [28] 2J(L 1) + 1 − Filter banks [28] 2(2L 1)(1 2−J ) − − Transform domain 10N log N + 56N(1 2−J ) + 2N(1 2−J+1) 2 − − Modified lattice [5] (1 2−J )(8k + 3Lk) − FFT-Based DWT 2 ((4k 1)2k+1 + 8)(1 2−J ) B − − 1 k k−J Mod. FFT-based DWT B (2 (4k 8) + 12) + (2 (4(k J) 4) + 6)+... − − −  +(PJ 2k−j(k j + 22) + 6) + PJ−1 2n−jB j=1 − j=1 Table A.4: Computational complexity for DWT algorithms.

In these formulas N and L represent the FFT and filter length respectively. The maximum level of decomposition is indicated by J and the level number by j. Variable K represents the length of the real input data and k the data sample number. Each L/2 length highpass or lowpass filter operates on B/2 length samples, by which the input block-length of the DWT cell is defined as:

B = 2N (l 2). (A.2) − − A.5.5 Analytical signal computation methods

Method Number of multiplications and additions

Frequency domain definition 5N log2

Time domain definition LNs/2

Table A.5: Computational complexity of two methods for the computation of the analytical signal.

Here, N, Ns and L represent the number of samples in the kernel sequence, the number of samples between plots and the filter length respecaaaatively. 86 APPENDIX A. APPENDIX I Appendix B

Appendix II

B.1 algorithm

Function function [e] = algorithm(e,channels)

Loading the data

shotnr = struct(’name’,{... ’ECdata_106478’,’ECdata_106479’,’ECdata_106480’,’ECdata_106481’,... ’ECdata_106482’,’ECdata_106483’,’ECdata_106484’,’ECdata_106485’,... ’ECdata_106486’,’ECdata_106487’,’ECdata_106488’,’ECdata_106489’,... ’ECdata_106490’,... ’ECdata_107906’,’ECdata_107907’,’ECdata_107908’,’ECdata_107909’,... ’ECdata_107910’,’ECdata_107911’,’ECdata_107912’,’ECdata_107913’,... ’ECdata_107914’,’ECdata_107915’,’ECdata_107916’,’ECdata_107917’,... ’ECdata_107918’,’ECdata_107919’,’ECdata_107920’,’ECdata_107921’,... ’ECdata_110050’,’ECdata_110051’,’ECdata_110052’,’ECdata_110053’,... ’ECdata_110054’,’ECdata_110055’,’ECdata_110056’,... ’ECE_textor_110065’,’ECE_textor_110066’,’ECE_textor_110067’,... ’ECE_textor_110068’,’ECE_textor_110069’,’ECE_textor_110070’,... ’ECE_textor_110071’,’ECE_textor_110072’,... ’ECE_textor_110073’,’ECE_textor_110074’});

load(shotnr(1,e).name)

Defining the signal ’s’ and the timevector ’ts’

if e < 37 ec = [ec132.y ec135.y ec138.y ec141.y ec144.y ec147.y]; s = ec(:,channels); ts = ec132.x0; else s = V_ECE(:,channels); ts = t_ECE; end

87 88 APPENDIX B. APPENDIX II

3rd order Butterworth low-pass filter n = 3; fs = 1/abs(diff(abs(ts(1:2,1)))); fc = 2000; ripple = []; ftype = ’but’; % t_begin = find(ts > (1+.5*(1/fs)),1,’first’); t_end = find(ts > (5-.5*(1/fs)),1,’first’); [lpfs] = filt(s(t_begin:t_end,:),ftype,n,fs,fc,ripple);

Signal processing to emphasize the statistical dispersion % 1st order difference filter ds = diff(lpfs,1);

% 4th power function ds4 = ds.^4;

Real-time normalization % initial conditions nperc_92 = 0.92; nperc_i = []; noiselevel92_old = []; d3 = []; d3_i0 = cell(1,4); D3 = cell(1,4); Period = cell(1,4);

% Buffering the signals B = 5e3; for i = 1:(t_end-t_begin)/B - 1 b_old = (i-1)*B+1:(i*B); b = (i*B+1):(1+i)*B;

% Normalization function [dn(b,:),noiselevel_rt(b,:),nperc_i] = normal(ds4(b_old,:),... ds4(b,:),B,nperc_92,nperc_i); noiselevel92_old = [];

Combining channels by summation and multiplication dns(b,:) = sum(dn(b,:),2)/length(dn(1,:)); dnp(b,:) = prod(dn(b,:),2); end

Comparing with thresholds t = ts(t_begin:t_end); threshold_sep = 4e2* ones(1,length(s(1,:))); threshold_sum = 4e2; threshold_prod = 1e8; threshold = [threshold_sep threshold_sum threshold_prod]; crashdetection = crashdet([dn,dns,dnp],t,threshold); B.2. FILT 89

Hold subsequent exceeding times tol = 70e-5; n_chan = 1; d3{1} = merg(crashdetection(1,1:(end-2)),tol,n_chan,fs); d3{2} = crashdetection{1,end-1}; d3{3} = crashdetection{1,end}; d3{4} = merg(d3,tol,0,fs); if isempty(d3{4}) d3{4} = d3{1}; end

Determination exact crash-times [crash_time,d3_i0] = crashtime(d3,d3_i0,tol,s,fs);

Determination location inversie radius [dc,lc,ir] = invrad(crash_time);

1st order difference filter for period determination period = periode(crash_time);

Storing data in cell structures D3{1} = [D3{1}; d3{1}]; D3{2} = [D3{2}; d3{2}]; D3{3} = [D3{3}; d3{3}]; D3{3} = [D3{3}; d3{3}]; Period{1} = [Period{1}; period{1}]; Period{2} = [Period{2}; period{2}]; Period{3} = [Period{3}; period{3}]; Period{4} = [Period{4}; period{4}];

Plotting the final period and sawtooth signal with crash indication algorithm_plotfunctie(t,s(t_begin:t_end,:),crash_time,Period,shot)

Saving the data shotname = sprintf(’algorithm_data%i’,shot); save(shotname,’shot’,’s’,’lpfs’,’ds’,’ds4’,’t’,’B’,... ’dn’,’noiselevel_rt’,’dns’,’dnp’,’tol’,’threshold’,... ’crashdetection’,’crash_time’,’D3’,’Period’,’ir’)

B.2 filt

Function function [s] = filt(s,ftype,n,fs,fc,ripple)

3rd order low-pass filter function % normalized passband edge frequency, between 0 and 1 Wn = 2*fc/fs; if strcmp(ftype,’but’) 90 APPENDIX B. APPENDIX II

[b,a] = butter(n,Wn,’low’); elseif strcmp(ftype,’cheby’) [b,a] = cheby2(n,ripple,Wn,’low’); end s = filter(b,a,s);

B.3 normal

Function function [sn, noiselevel92, nperc_i] = normal(s_old,s,B,nperc_92,nperc_i)

Initial noise level determination h = length(s_old(1,:)); ssort_old = sort(s_old); noiselevel92 = zeros(B,h); n92 = mean(ssort_old(1:round(B*nperc_92),:)); for i1 = 1:h noiselevel92(1:B,i1) = ones(B,1)*n92(i1); end nperc_i = ssort_old(round(B*nperc_92),:);

Real-time noise level update h = length(s(1,:)); ssort = sort(s); noiselevel92_old = [noiselevel92(end,:)]; for i1 = 1:h for i2 = 1:B if s(i2,i1) < nperc_i(1,i1) noiselevel92(i2,i1) = .99*noiselevel92_old(:,i1)+.01*s(i2,i1); else noiselevel92(i2,i1) = noiselevel92_old(:,i1); end noiselevel92_old(1,i1) = noiselevel92(i2,i1); end end

Real-time normalization sn = []; for i1 = 1:h sn = [sn s(:,i1)./noiselevel92(:,i1)]; end

B.4 crashdet

Function function [crash] = crashdet(input,t,threshold) B.5. MERG 91

Initial conditions h = length(input(1,:)); l = length(input(:,1)); crash = cell(1,h); c = [];

Comparing input with thresholds for i1 = 1:h for i2 = 1:l if input(i2,i1) > threshold(i1) c = [c; t(i2)]; end end crash{i1} = c; c = []; end

B.5 merg

Function function [ct] = merg(input,tol,m,fs)

Initial conditions h = length(input(1,:)); tmin = zeros(h); tmax = zeros(h); c = []; ct = []; k = []; if h == 1 ct = input{1}; else

Determination of first and last element in the vector with crashmoments for i = 1:h if isempty(min(input{1,i})) tmin(i) = 0; tmax(i) = 0; else tmin(i) = min(input{1,i}); tmax(i) = max(input{1,i}); end end tmin = min(tmin); tmax = max(tmax); l_oud = tmin-tol;

Merging the crashmoments of the input into one crashmoments vector for l = tmin:(1/fs):tmax for i = 1:h; f1 = find((l) == (input{1,i})); if length(f1) > 0 92 APPENDIX B. APPENDIX II

if 0 < l-l_oud & l-l_oud < tol c = [c; l]; elseif l-l_oud >= tol if length(k) > m ct = [ct; c]; c = l; k = []; else c = l; k = []; end end if isempty(find(k == i,1)) k = [k; i]; end l_oud = l; end end end

ct = [ct; c]; end

B.6 crashtime

Function function [crash_time,d3_i0] = crashtime(input,d3_i0,tol,s,fs)

Initial conditions h = length(input(1,:)); crash_time = cell(1,h); bn = 1; b = length(s(1,:));

Composition of a matrix with crashmoments and corresponding signal values for i2 = 1:h if isempty(d3_i0{1,i2}) inp = [input{1,i2}]; else inp = [d3_i0{1,i2}; input{1,i2}]; end I = find(abs((diff(inp)))>tol); J = []; c = []; if isempty(inp) c = inp; elseif isempty(I) c = [inp(1) inp(end), ... round(mean(([inp(1):(1/fs):inp(end)])*fs))*(1/fs), ... s(round((inp(1))*fs),1), ... s(round((inp(1))*fs),2), ... s(round((inp(1))*fs),3), ... B.7. INVRAD 93

s(round((inp(1))*fs),4), ... s(round((inp(1))*fs),5), ... s(round((inp(end))*fs),1), ... s(round((inp(end))*fs),2), ... s(round((inp(end))*fs),3), ... s(round((inp(end))*fs),4), ... s(round((inp(end))*fs),5), ... s(round((round(mean(([inp(1):(1/fs):inp(end)])*fs))*(1/fs))*fs),2)]; else J(2:length(I)+1) = I; J = J+1; J(length(J)+1) = length(inp)+1; K = diff(J); for i = 1:length(J)-1 begin = J(i); eind = J(i)+K(i)-1; c(i,:) = [inp(begin), ... inp(eind), ... round(mean(([inp(begin):(1/fs):inp(eind)])*fs))*(1/fs),... zeros(1,2*b+1)]; for i3 = 1:b c(i,3+i3) = s(round((inp(begin))*fs),i3); c(i,3+i3+b) = s(round((inp(eind))*fs),i3); c(i,3+1+b+b) = ... s(round((round(mean(([inp(begin):(1/fs):inp(eind)])*fs))*(1/fs))*fs),1); end end d3_i0{i2} = inp(J(i-1):eind,:); end if isempty(c) c = []; else c = c(1:(length(c(:,1))-1),:); end crash_time{i2} = c; end

B.7 invrad

Function function [dc,lc,ir] = invrad(input)

Initial conditions inp = input{1,4}; if isempty(inp) dc = []; lc = []; ir = []; else h = length(inp(:,1)); b = (length(inp(1,:))-4)/2; dc = zeros(h,2); 94 APPENDIX B. APPENDIX II

lc = zeros(h,6); ir = zeros(h,2); determination of position inverse radius for i2 = 1:h % duration crash dc(i2,1) = inp(i2,3); dc(i2,2) = inp(i2,2) - inp(i2,1); % length crash lc(i2,1) = inp(i2,3); for i1 = 1:b lc(i2,i1+1) = inp(i2,i1+3+b)-inp(i2,i1+3); end % position inverse radius ir(i2,1) = inp(i2,3); for i3 = 1:4 if sign(lc(i2,i3+1)) ~= sign(lc(i2,i3+2)) ir(i2,2) = i3+abs(lc(i2,i3+1))/(abs(lc(i2,i3+1))+... abs(lc(i2,i3+2))); end if lc(1,i3+1) == 0 ir(1,2) = 5.5; elseif lc(i2,i3+1) == 0 ir(i2,2) = ir(i2-1,2); end end if ir(i2,2) == 0 if sign(lc(i2,2)) > 0 ir(i2,2) = 0.5; else ir(i2,2) = 5.5; end end end end

B.8 periode

Function function [period] = periode(input)

Initial conditions h = length(input(1,:)); period = cell(1,h);

Determination of the period by applying a first order difference filter for i = 1:h inp = [input{1,i}]; if isempty(inp) B.8. PERIODE 95

period{i} = []; else period{i} = [inp(2:end,3) diff(inp(:,3))]; end end 96 APPENDIX B. APPENDIX II Bibliography

[1] An efficient real-time implementation of the wigner-ville distribution. IEEE Transactions on Acous- tics, Speech and Signal Processing, ASSP-35(11):1611–1618, November 1987.

[2] Applications of wavelet transforms to damage detection in frame structures. Engineering Struc- tures, 26(1):39–49, 2004.

[3] M.F.F. Nave A.C.A. Figueiredo. Time-frequency analysis of non-stationary signals in fusion plas- mas using the choi-williams distribution. Proceedings of the 30th EPS Conference on Controlled Fusion and Plasma Physics, 27A:P–2.141, 2003.

[4] M.F.F. Nave A.C.A. Figueiredo. Time-frequency analysis of nonstationary fusion plasma signals: A comparison between the choi-williams distribution and wavelets. Review of Scientific Instru- ments, 75(10), October 2004.

[5] A. Baraniecki and V.N. Parikh. Efficient computation of time-frequency wavelet representation. IEEE, 1992.

[6] D.T. Barry. Fast calculation of the choi-williams time-frequency distribution. IEEE Transactions on Signal Processing, 40(2):450–455, February 1992.

[7] Donald C. Benson. The moment of proof, mathematical epiphanies. Oxford University Press, 2000.

[8] Hyung-Ill Choi and William J. Williams. Improved time-frequency representation of multicom- ponent signals using exponential kernels. IEEE Transactions on Nuclear Science, 37(6), June 1989.

[9] T.A.C.M. Claasen and W.F.G. Mecklenbräuker. The wigner distribution - a tool for time-frequency signal analysis. part iii: relations with other time-frequency transformations. Philips Journal of Research, 35:372–389, 1980.

[10] T.A.C.M. Claasen and W.F.G. Mecklenbräuker. The aliasing problem in discrete-time wigner distributions. IEEE Transactions on Acoustics, Speech and Signal Processing, ASSP-31(5), October 1983.

[11] Gregory S. Cunningham and William J. Williams. Fast implementations of generalized discrete time-frequency distributions. IEEE Transactions on Signal Processing, 42:1496–1508, June 1994.

[12] Pierre Duhamel. Implementation of "split-radix" fft algorithms for complex, real, and real- symmetric data. IEEE Transactions on Acoustics, Speech and Signal Processing, ASSP-34(2):285–295, April 1986.

[13] G. Witvoet et al. Control oriented modeling and simulation of the sawtooth instability in nuclear fusion tokamak plasmas. IEEE 48th Conference on Decision and Control, page Approved, December 2009.

[14] Patrick Flandrin. Time-Frequency / Time-Scale Analysis. Academic Press, 1999.

97 98 BIBLIOGRAPHY

[15] G. Weimann G. Kamelander, G. Sdouz. Effect of helium ash on advanced iter-scenarios. Pro- ceedings of the 26th EPS Conference on Controlled Fusion and Plasma Physics, 23J:1609 – 1612, June 1999. [16] Svend Gade and Klaus Gram-Hansen. Non-stationary Signal Analysis using Wavelet Transform, Short-time Fourier Transform and Wigner-Ville Distribution. Number 2. Brüel & Kjaer, 1992. [17] Mostefa Mesbah John M. O’Toole and Boualem Boashash. A computationally efficient imple- mentation of quadratic time-frequency distributions. IEEE 9th International Symposium on Signal Processing and Its Applications, 2007., pages 1–4, February 2007. [18] Steven G. Johnson and Matteo Frigo. A modified split-radix fft with fewer arithmetic operations. IEEE Transactions on Signal Processing, 55(1):111–119, 2007. [19] A.C. Figueiredo J.P.S. Bizarro. The wigner distribution as a tool for time-frequency analysis of fusion plasma signals: application to broadband reflectometry data. Nuclear Fusion, 39(1):61–82, 1999. [20] M. Zilker K. Hallatschek. Real time data acquisition with transputers and powerpcs using the wavelet transform for event detection. IEEE Transactions on Nuclear Science, 45(4), August 1998. [21] Thuyen Le and Manfred Glesner. A flexible and approximate computing approach for timeUfre- quency distributions. IEEE Transactions on Signal Processing, 48(4):1193–1196, April 2000. [22] R. Coelho P. Belo D. Borba R.J. Buttery S. Nowak F. Serra M.F.F. Nave, E. Lazzaro and EFDA- JET Contributors. Triggering of neo-classical tearing modes by mode coupling. Nuclear Fusion, 43:179–187, 2003. [23] Marvin K. Nakayama. Simulation output analysis. Proceedings of the 34th conference on Winter simulation: exploring new frontiers, pages 23–34, 2002. [24] Dirk Naujoks. Springer Series on Atomic, Optical, and Plasma Physics. Springer Berlin Heidelberg, 2006. [25] Gilbert Strang / Truong Nguyen. Wavelets and Filter Banks. Wellesley - Cambridge Press, 1996. [26] G. Gorini A. Jacchia G.M.D. Hogeweij N.J. Lopes Cardozo G.J. Kramer A.C.C. Sips P. Mantica, F. De Luca. Fourier analysis of sawtooth heat pulse propagation and comparison with other methods using jet data. Nuclear fusion, 32(12):2203–2215, 1992. [27] J.I. Paley. Real time control of the sawtooth period using ec launchers. Plasma Physics and Con- trolled Fusion, 51, 2009. [28] Olivier Rioul and Pierre Duhamel. Fast algorithms for discrete and continuous wavelet trans- forms. IEEE Transactions on Information Theory, 38(2):569–586, March 1992. [29] Roger D. Bengtson S. Santoso, E.J. Powers and A. Ouroua. Time-series analysis of nonstation- ary plasma fluctuation using wavelet transforms. Research of Scientific Aparatus, 68(1):898–901, January 1997. [30] O. Sauter, E. Westerhof, M. L. Mayoral, B. Alper, P. A. Belo, R. J. Buttery, A. Gondhalekar, T. Hell- sten, T. C. Hender, D. F. Howell, T. Johnson, P. Lamalle, M. J. Mantsinen, F. Milani, M. F. F. Nave, F. Nguyen, A. L. Pecquet, S. D. Pinches, S. Podda, and J. Rapp. Control of neoclassical tearing modes by sawtooth control. Phys. Rev. Lett., 88(10):105001, Feb 2002. [31] Tessamma Thomas V.P. Dinesh Kumar. A modified fft-based algorithm for real-time computation of discrete wavelet transform. IEEE Conference on Convergent Technologies for Asia-Pacific Region, 3:1030– 1034, October 2003. [32] J. Wesson. Tokamaks. Oxford Science Publications, third edition edition, 2004. BIBLIOGRAPHY 99

[33] Dongsheng Wu and Joel M. Morris. Discrete cohen’s class of distributions. Proceedings of the IEEE- SP International Symposium on Time-Frequency and Time-Scale Analysis, pages 532–535, 1994.