I know that exp(J*phi)=cos(phi)+Jsin(phi)=(Re,Im)=(cos(phi),sin(phi)). But in Qspice Re=sin(phi) and Im=cos(phi).

I gave a simple example of calculating the current phases of the simplest elements.

Phasi.qsch (3.3 KB)

I know that exp(J*phi)=cos(phi)+Jsin(phi)=(Re,Im)=(cos(phi),sin(phi)). But in Qspice Re=sin(phi) and Im=cos(phi).

I gave a simple example of calculating the current phases of the simplest elements.

Phasi.qsch (3.3 KB)

A mistake in atan formula? Should be imaginary / real for phase calculation.

arctangent is a bit tricky, for correct phase calculation in handling negative real part in complex number, we have to use atan2 (atan2 - Wikipedia) which is four quadrant arctangent.

Here is an example to convert I(L1) from `(Re,Im)`

to `(Mag,Phase) = |Mag|*exp(-j*(Phase))`

complex-atan2-L.qsch (3.1 KB)

This is matlab result in calculating `9.68929e-5*exp(j*+178.819*pi/180)`

Even though I used the wrong formula I got the right result. I agree that tan=im/re is necessary when calculating tangent, but in this case the result is not correct. I wrote much earlier that the Meas Four result gives an inverted result - (im,re) but I was not understood then. They said that I didn’t understand anything, the number is complex. Now I proved with my example that I was right then! The result is reversed. Of course, I will survive this cul-de-sac of the author of Qspice with the representation of complex numbers.

In the example I shown in previous post, (Re,Im) can match to (Magnitude,Phase), I don’t see any evidence `exp(j*Phase)`

is reversed.

For phase calculation from (Re,Im) complex format, you cannot get a correct answer with atan, but only with atan2.

But I think may be I misunderstand your question? **Or, you are saying four calculated an incorrect result?**

For .meas with four, the useful information from phase is its relative relationship. For example, here you can see signal x, y and z calculated with correct relative phase, where if x at -90 degree, y at -45 degree and z at 0 degree.

four.qsch (2.8 KB)

It is known from a school physics course that the current of an ideal (lossless) inductance lags behind the voltage by 90 degrees. And the current of an ideal capacity (without losses) is ahead of the voltage by 90. This is what I calculated in my circuit.

Below is a more correct calculation.

faz.qsch (3.6 KB)

Above math looks nice in -90 to 90 degree… but if for example, change phase to 135 and -135, it will still give you angle at 45 and -45.

The key issue is that, there are two angle give same answer for sin, cos and tan. asin, acos and atan can only give you one answer. If you need angle in correct quadrant, you requires atan2.

If really need the 0 degree sine source give a 0 degree reading with .meas four, in the atan2 math, add +90 degree, and here we can get

V(X) is 0 degree, with .meas result ~ 0 degree

V(Y) is 135 degree, with .meas result = 135 degree

V(Z) is -135 degree, with .meas result = 360 degree - 135 degree = 225 degree

I guess Qspice fourier transform convolution with a cosine wave and naturally gives -90 degree for a sine wave with 0 degree at t=0s [ i.e. sin(theta) = cos(theta-pi/2) ]. Normally, I just take phase as relative, as it doesn’t have much meaning to say what is the angle of a sine wave alone.

four-offset.qsch (2.8 KB)

You deviated from my topic. I argued that the result of the Meas Four operation is not true. More precisely, it has the order of the real and imaginary parts mixed up. I wasn’t interested in phases. More precisely, I was interested in the phase shift in inductance and capacitance, and their phases are in the interval [-90°,+90°]. In order to calculate the phase I used the relationship tan=sin/cos. But for correct calculation I had to equate sin~Re and cos~im, which is not correct, but it gave the correct result.

Similarly, when using the calculation via sin, I also had to break the natural order.

It is known that when the real and imaginary parts of Re ↔ im are swapped, the complex vector is rotated by -90°.

This is confirmed by your last expressions, where you made +90°. In fact, you have rotated the vector backwards, i.e. you have put the real and imaginary parts correctly!

I’m all for Qspice being infallible, but this case casts a shadow on the program.

It looks like I have been accused of going off-topic several times.

OK, when we talk about the Fourier transform, we need to understand what signal is used to reconstruct the result of the Fourier transform. In Qspice, the mathematical representation suggests that the result of the Fourier transform provides the amplitude in RMS and a phase, which is what you mentioned as `|Mag|*exp(j*theta)`

.

What’s important to note is that the signal is actually reconstructed using a cosine function. That’s why when your signal is a sine wave with a phase angle of 0 degrees at t=0, the Fourier transform has to give you a phase angle of -90 degrees, as its time domain reconstruction function is cosine instead of sine.

Fourier transform results is **NOT** a time domain signal, it only give amplitude and phase information of the time domain cosine function. The reason that cosine is used, is because it is symmetric at t=0 (i.e. symmetric between positive and negative time axis).

meas four - phase - math.qsch (641.5 KB)

2 Likes