d/q Transformation
To make a machine turn, we need three sinusoidal currents phase-shifted by 120°. The amplitude of the currents depends on the rotor angle. So the currents rotate with the rotor. The currents are added to a total current phasor. They generate the total stator field, which also rotates with the rotor. Ideally, the phasor of the total current is offset from the rotor by 90° in the direction of rotation, so that the stator field pushes and pulls the bar magnet of the rotor as well as possible.
This chapter is about a brilliant mathematical simplification for describing the total current phasor.
Triangle mathematics
First I will review the mathematics of right-angled triangles, which we will use later.


The upper figure shows how, in a right-angled triangle, the side lengths can be calculated as a function of the angle using sine and cosine. The hypotenuse c is the side that does not adjoin the right angle. It lies opposite the right angle. In the examples further down in this chapter, this length is always given.
The opposite side is side b. It lies opposite the angle φ. It is a leg of the triangle, because it lies directly at the right angle. You calculate the length of the opposite side with the sine.
The adjacent side is side a. It lies at the angle φ. You calculate the length of the adjacent side with the cosine.
The lower figure is a reminder that the two angles labelled φ are equal. This always applies when you halve a rectangle into two triangles with a straight line. The opposite sides of the rectangle are of course equally long. Then the opposite angles must be equal. You can see this if you calculate the lengths of the sides of the triangles with sine and cosine.
1st transformation step
From now on we work with RMS phasors instead of peak value phasors. The length of the current phasor corresponds to the RMS value. For RMS phasors:
In the first step, the three currents are transferred into a new coordinate system. A current iα is formed for the real component of the current. The imaginary component is called iβ. The names of the axes are adapted accordingly.

The general formula above applies to every rotor angle Ω. We apply it to the rotor angle positions of the three currents. The following applies:

The current I1 points completely in the α direction. The other two currents contain components in the α and β directions. The angles for the transformation are fixed, because the rotor angles of the three currents do not change. The three current phasors always point in the same three directions.
We are used to two orthogonal axes in graphs. Three current directions rotated by ±120° instead of 90° relative to one another are mathematically and visually awkward. So this first transformation step brings the individual currents into a familiar coordinate system.
The coordinate system of the space vector refers to the stator; it is “stator-fixed”. The axes of the coordinate system stand still; the rotor and the total current phasor rotate in a circle.
2nd transformation step
Then, in our minds, we sit on the rotor and rotate in a circle with the rotor. We sit on the south pole of the bar magnet and look outwards at the stator. The 6 coils then move past us. The rotor field always points in the direction in which we are looking.
If we have done everything right in controlling the currents, the stator field is 90° behind us in the direction of rotation. When we pass a coil, its current is just at 0A. The coil 90° ahead of us in the direction of rotation has the maximum positive current value. It attracts us. The coil 90° behind us in the direction of rotation has the maximum negative current value. It repels us.
Two directions are relevant: we call the direction in which we are looking “d” for “direct”. We call the direction 90° ahead in the direction of rotation “q” for “quadrature” (German: “quer”, transverse). We use these two directions as the axes of a new coordinate system.
Our viewing direction – the d axis – rotates. So the coordinate system rotates in a circle. The electromagnets of the stator move past us. Within this rotating coordinate system, the rotor always points in the direction of the d axis. In this coordinate system, the total stator current no longer moves; it has become a static quantity.
It is a pretty mind-blowing idea to set up a rotating coordinate system in which rotating quantities are constant. It is called a rotor-related coordinate system. The effect of this transformation is brilliant.
In the following figure, let us look at the stator-fixed αβ coordinate system in black and the rotor-related dq coordinate system in red. The dq axes are rotated by the rotor angle Ω (here in the example 30°). In the figure below, two currents Iα and Iβ are given as orange current phasors. From these, the currents Id and Iq are to be calculated. So I assume that the first transformation has already been carried out.
We can now use triangle geometry to calculate how large the d- and q-currents are as a function of the α- and β-currents. The current Iqα, for example, corresponds to the component of the current Iα that flows in the q direction.

These relationships apply generally for all rotor angles Ω.
Combining both transformation steps
To calculate the d and q current phasors in the rotating rotor coordinate system, both transformation steps are carried out one after the other. The following applies:
The currents I1, I2 and I3 are RMS phasors. Their time behaviour is already hidden. They only have length and direction. The phases (directions) of the current phasors are constant. If the peak value of all three currents is changed, the lengths of these RMS phasors change. So that the system is loaded symmetrically, the peak values of the three currents are normally equal.
The second variable quantity in the equations above is the rotor angle Ω. All other parameters are constant. From the RMS values of the currents and the rotor angle, we can calculate the currents Id and Iq.
If the stator current points in the q direction, the current space vector always points 90° ahead of the rotor in the direction of rotation. So we need the transformation the other way round. We specify a q-current as the setpoint and then have to calculate the currents I1, I2 and I3. The inverse second transformation is:

The general solution for inverting the first transformation is:

We apply these formulas to the fixed angles of the three stator currents:
Suppose a motor needs a q-current of Iq = 1A. How do we calculate the correct currents through the coils for this?
The user specifies how large the d- and q-currents are. These values are generally set to control the machines. From them, the motor control unit calculates the matching currents in the coils for every rotor angle.
The d/q coordinate system always points with its d axis in the direction of the south pole of the stator.

In the example above, the south pole of the stator points to 120°, so the rotor angle is Ω = 120°. As the rotor continues to turn, the d axis constantly points in a different direction. When we look at currents in the d/q coordinate system, we always rotate the coordinate system so that the d direction points to the right and the q direction upwards. We know that the d axis rotates with the rotor. But in the transformation we pretend that our viewing direction always points to the right when we sit on the rotor.
From now on we use the right-hand representation. In this representation it does not matter at all where the permanent magnet points. What matters is only how the stator current phasor is oriented relative to the permanent magnet. The stator current phasor IS in the left figure rotates. In the right figure it stands still. As a result, all rotating quantities come to rest; they become static quantities. Consequently, the angle Ω disappears from the figures.
We introduce a new angle γ that indicates the shift of the stator current phasor relative to the d axis. This angle γ is constant over one rotor revolution. It only indicates how the stator current is shifted relative to the permanent magnet. So far we have assumed that γ is always -90°. The stator current phasor then always points 90° behind the south pole of the permanent magnet during the rotor’s rotation.
The angle Ω changes during one rotor revolution; the angle γ is constant. The rotor points in the direction Ω, the stator field in the direction Ω + γ.
The following animation illustrates the transformation steps; it was created by Eirik Haustveit and Yngve Solbakken for their blog switchcraft:

In the top picture, the three stator currents are combined into a space vector. Below it, the middle picture shows the stator current in alpha / beta coordinates. The bottom picture shows this current in d/q coordinates.