Author Topic: Interpolating Complex Numbers  (Read 41433 times)

0 Members and 4 Guests are viewing this topic.

Offline jaxbirdTopic starter

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Interpolating Complex Numbers
« on: January 18, 2015, 07:07:08 pm »
Not sure if this is even the correct forum for such a question, but here we are.

The problem is, when applying a calibration, I need to use complex numbers, meaning I build tables of these, indexed by frequency.

But as the actual measurement frequency is likely to be between 2 recorded calibration points in my lookup table, interpolation is needed.

Is there an easy/standard way to interpolate between 2 complex numbers? (just linear interpolation, no fancy spline needed)

Must be a somewhat common problem, but quick google just seem to suggest everyone just use matcad :-\

I'm sure there is a simple way of doing it, and I'll figure it out eventually, but any hints much appreciated.

Note: Repeat of a question in my Impedance Analyzer thread, but I hope this might get more exposure.

Cheers

« Last Edit: January 18, 2015, 07:08:47 pm by jaxbird »
Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline photon

  • Frequent Contributor
  • **
  • Posts: 260
  • Country: us
Re: Interpolating Complex Numbers
« Reply #1 on: January 18, 2015, 07:10:11 pm »
Just interpolate real and imaginary part.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11727
  • Country: my
  • reassessing directives...
Re: Interpolating Complex Numbers
« Reply #2 on: January 18, 2015, 07:16:39 pm »
Treat i as x and j as y, visualize as in cartesian plane, things should become clearer and google will get many hits. unless there is application specific that you are aiming requiring fancy methods or splines prediction.

Offline jaxbirdTopic starter

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #3 on: January 18, 2015, 07:45:14 pm »
Just interpolate real and imaginary part.

I don't believe that will work.

Treat i as x and j as y, visualize as in cartesian plane, things should become clearer and google will get many hits. unless there is application specific that you are aiming requiring fancy methods or splines prediction.

Thanks, I believe that is what I will need to figure out, as is based on angle between the vectors and the difference in magnitude.

Linear interpolation is fine.

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #4 on: January 18, 2015, 08:03:46 pm »
Linear interpolation with complex numbers is the same as with real numbers.

If z1 and z2 are two complex numbers and you want to find the number halfway between them, you simply compute:

    z = (z1 + z2) / 2

More generally, if q is an interpolating fraction (0 <= q <= 1) you compute:

    z = q * z1 + (1-q) * z2

Complex numbers are just numbers. You can do arithmetic with them.
 

Offline jaxbirdTopic starter

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #5 on: January 18, 2015, 08:18:38 pm »
Linear interpolation with complex numbers is the same as with real numbers.

If z1 and z2 are two complex numbers and you want to find the number halfway between them, you simply compute:

    z = (z1 + z2) / 2

More generally, if q is an interpolating fraction (0 <= q <= 1) you compute:

    z = q * z1 + (1-q) * z2

Complex numbers are just numbers. You can do arithmetic with them.

Thanks Ian, that is very helpful (as I'm sure you can tell, complex numbers is not something I get to play with very often)

It really simplifies everything to just keep the numbers complex instead of treating the real and imag parts individually.

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1621
  • Country: lt
Re: Interpolating Complex Numbers
« Reply #6 on: January 18, 2015, 08:20:22 pm »
Most interpolation methods treat real and imaginary parts separately. As mentioned by others, you can use linear interpolation separately for real and imaginary parts and add them up.
If you have very specific restrictions on the number in the first place (like having fixed magnitude), then use something more suitable.
 

Offline jaxbirdTopic starter

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #7 on: January 18, 2015, 08:31:40 pm »
Most interpolation methods treat real and imaginary parts separately. As mentioned by others, you can use linear interpolation separately for real and imaginary parts and add them up.
If you have very specific restrictions on the number in the first place (like having fixed magnitude), then use something more suitable.

That was my first attempt, but results were not successful (I'm sure the linear interpolation was working just fine) Results were very strange compared to using exact values not needing interpolation.

Could be due to my use case only cares about the phase being between -180 and 180 degrees and not absolute.

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #8 on: January 18, 2015, 08:38:08 pm »
Thanks Ian, that is very helpful (as I'm sure you can tell, complex numbers is not something I get to play with very often)

It really simplifies everything to just keep the numbers complex instead of treating the real and imag parts individually.

Well, you can keep the numbers complex when you do algebra with them, but to actually work out the values you will have to work with the real and imaginary parts (unless you have a computer or calculator that is doing the arithmetic for you).

A complex number is a pair of numbers, the real part and the imaginary part. So we can say:

    z1 = (x1, y1)
    z2 = (x2, y2)

In this notation x is the real part and y is the imaginary part (commonly written as z = x + iy).

So if we want to compute the interpolation

    z = (z1 + z2) / 2

we are going to have

    x = (x1 + x2) / 2
    y = (y1 + y2) / 2

    z = (x, y)

So you can't really get away from looking at the real and imaginary parts, but you don't have to worry about it until you do the actual calculations.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #9 on: January 18, 2015, 08:40:13 pm »
Quote
when applying a calibration, I need to use complex numbers, meaning I build tables of these, indexed by frequency.

There really is no answer without knowing the relationship between frequency and the "variable", as expressed in complex numbers. Most of the time, it is likely that the relationship is modulus based but that may not always the case.
================================
https://dannyelectronics.wordpress.com/
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #10 on: January 18, 2015, 08:41:45 pm »
Could be due to my use case only cares about the phase being between -180 and 180 degrees and not absolute.

If your complex numbers are represented as a magnitude and phase angle (r,theta) rather than real and imaginary parts (x,y), then you will have to convert from polar coordinates to rectangular coordinates before you do the interpolation. You can't do linear interpolation on r and theta like you can do with x and y.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #11 on: January 18, 2015, 08:46:31 pm »
Quote
Could be due to my use case only cares about the phase being between -180 and 180 degrees and not absolute.

Usually people want the phase to be -90 to +90 degrees. there is a level of redundancy between -180 to +180 -> for example -180 is 0, and so is +180.

To bound the phase to -90 and +90 is fair easy, if that's what you want.
================================
https://dannyelectronics.wordpress.com/
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #12 on: January 18, 2015, 08:49:27 pm »
Usually people want the phase to be -90 to +90 degrees. there is a level of redundancy between -180 to +180 -> for example -180 is 0, and so is +180.

Why is -180° the same as 0°? I don't follow.
« Last Edit: January 18, 2015, 08:51:09 pm by IanB »
 

Offline jaxbirdTopic starter

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #13 on: January 18, 2015, 08:58:00 pm »
Thanks Ian, that is very helpful (as I'm sure you can tell, complex numbers is not something I get to play with very often)

It really simplifies everything to just keep the numbers complex instead of treating the real and imag parts individually.

Well, you can keep the numbers complex when you do algebra with them, but to actually work out the values you will have to work with the real and imaginary parts (unless you have a computer or calculator that is doing the arithmetic for you).

A complex number is a pair of numbers, the real part and the imaginary part. So we can say:

    z1 = (x1, y1)
    z2 = (x2, y2)

In this notation x is the real part and y is the imaginary part (commonly written as z = x + iy).

So if we want to compute the interpolation

    z = (z1 + z2) / 2

we are going to have

    x = (x1 + x2) / 2
    y = (y1 + y2) / 2

    z = (x, y)

So you can't really get away from looking at the real and imaginary parts, but you don't have to worry about it until you do the actual calculations.

Understand, but luckily I don't have to go that deep as I have available fully functional complex libraries/classes, so I don't have to worry about the inner implementation of complex algebra and have pretty much any common complex function available :)

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline jaxbirdTopic starter

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #14 on: January 18, 2015, 09:05:12 pm »
Quote
Could be due to my use case only cares about the phase being between -180 and 180 degrees and not absolute.

Usually people want the phase to be -90 to +90 degrees. there is a level of redundancy between -180 to +180 -> for example -180 is 0, and so is +180.

To bound the phase to -90 and +90 is fair easy, if that's what you want.

I do want the full 360 degrees, but as in 200 degrees is actually -160 degrees, not a big deal though, easy to sort out.

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11727
  • Country: my
  • reassessing directives...
Re: Interpolating Complex Numbers
« Reply #15 on: January 18, 2015, 10:47:50 pm »
Just interpolate real and imaginary part.
I don't believe that will work.
everybody is trying to tell you the same thing,just different length of elaboration.

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #16 on: January 19, 2015, 01:55:10 am »
If your complex numbers are represented as a magnitude and phase angle (r,theta) rather than real and imaginary parts (x,y), then you will have to convert from polar coordinates to rectangular coordinates before you do the interpolation.

No, you don't have to do that conversion. Whether or not you do that conversion depends on the meaning you are assigning to the numbers.

For an oversimplified but concrete example, consider an easterly wind for one hour followed by a westerly wind for one hour. What is the "average" wind? Clearly there are multiple equally correct answers.

I don't think this is clear at all.

Quote
Quote
You can't do linear interpolation on r and theta like you can do with x and y.

Correct, but you are presuming a linear interpretation is the only valid thing to do; it isn't.

I am not a mathematician, but I suspect they will start muttering phrases such as "inside a complex hull". Or not :)

I will have to disagree with you on this, unless you can provide a concrete counter-example.

Let me use your wind example to illustrate.

Suppose a boat drifts on the wind in a northeasterly direction for one hour traveling 3 miles, and then drifts in an easterly direction for one hour traveling 2 miles. What is the average drift speed and direction of the boat?

If you tried to average this in polar coordinates you would say the drift speed is (3+2)/2 = 2.5 miles per hour, and the drift direction is, what? Do you average that by time or by distance, since direction is neither? Clearly this is not going to work out.

In fact, polar coordinates are not additive (interpolation is adding with scale factors), and you can't do addition or subtraction with them in terms of magnitudes and angles and get a useful result.

To solve the averaging problem you have to go via rectangular coordinates. You figure out where the boat ends up and then reference that back to the origin. The boat ends up 4.12 miles east of its original position and 2.12 miles north. The boat has therefore traveled 4.64 miles from the starting point in 2 hours, giving an average speed of 2.32 miles per hour. The direction of travel is arctan(4.12/2.12) = 62.8°.

The average drift speed of the boat has therefore been 2.32 miles per hour on a bearing of 62.8°.
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2187
  • Country: au
Re: Interpolating Complex Numbers
« Reply #17 on: January 19, 2015, 02:18:01 am »
Thanks Ian.
I've only just began using complex math, so to recap what you are saying and to re-enforce the methods I have been using... If I have phase and magnitude I can leave them in that form for multiplication/division but to add/subtract it has to be converted to rectangular format. Is that about it?

That's one of the many pitfalls of being self taught, it can take a very long time before you realise you have been doing something the wrong or long way :-[
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #18 on: January 19, 2015, 02:39:18 am »
I've only just began using complex math, so to recap what you are saying and to re-enforce the methods I have been using... If I have phase and magnitude I can leave them in that form for multiplication/division but to add/subtract it has to be converted to rectangular format. Is that about it?

Absolutely. Angle and magnitude are perfect for multiplication and division (multiply/divide the magnitudes, add/subtract the angles), but inconvenient for addition and subtraction. On the other hand rectangular coordinates are great for addition and subtraction, but ugly for multiplication and division.
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 23122
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Interpolating Complex Numbers
« Reply #19 on: January 19, 2015, 03:04:44 am »
If your complex numbers are represented as a magnitude and phase angle (r,theta) rather than real and imaginary parts (x,y), then you will have to convert from polar coordinates to rectangular coordinates before you do the interpolation.

No, you don't have to do that conversion. Whether or not you do that conversion depends on the meaning you are assigning to the numbers.

For an oversimplified but concrete example, consider an easterly wind for one hour followed by a westerly wind for one hour. What is the "average" wind? Clearly there are multiple equally correct answers.

I don't think this is clear at all.

No, it isn't clear, as a result of lost and improperly reinstated edits. Mea culpa.

I meant consider an 5kt easterly wind for one hour followed by a 5kt westerly wind for one hour.

Then, if you are a pilot the average affect on your groundspeed is zero. But if you are interested in the energy passing through a windmill, then the useful average value is 5kt.

Yes, that is an oversimplified contrived example, buit it is sufficient to indicate that there can be other useful definitions of "average" depending on the purpose and meaning of the averaging.

Another point is that your average is the simple arithmetic mean. What's your definition for the other "averages" such as geometric, mode, median, etc?
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #20 on: January 19, 2015, 06:46:54 am »
Yes, that is an oversimplified contrived example, buit it is sufficient to indicate that there can be other useful definitions of "average" depending on the purpose and meaning of the averaging.

Another point is that your average is the simple arithmetic mean. What's your definition for the other "averages" such as geometric, mode, median, etc?

We seem to be talking at crossed purposes. I don't deny that there are many different kinds of average, and that different averages are useful for different purposes.

What I was saying before is that if you have a complex number expressed in polar form as (r, theta), then you can't simply take the average of r and the average of theta and put the two back together again. Complex numbers don't work that way, for any kind of average. You have to treat the number as a whole and obey the rules of complex arithmetic.

For other averages such as the geometric mean the definition with complex numbers is the same as with the reals:

    zmean = sqrt(z1 * z2)

Since there are two square roots of any complex number it is necessary to pick the preferred root for the answer. But I am not sure that the geometric mean of complex numbers is useful.

For something like the median, you need to define what you want the median of, for example the median magnitude.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22435
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Interpolating Complex Numbers
« Reply #21 on: January 19, 2015, 08:49:56 am »
As said before, the standard linear interpolation form holds on the complex domain as well.

It may not be the most suitable method however, as for example if your data points trace out curves on a Smith chart, you would want to use circular segments to interpolate.  The suggestion of higher order interpolation methods (such as splines: quadratic or cubic curves, polynomial least-squares, etc.) will have similar results.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4564
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Interpolating Complex Numbers
« Reply #22 on: January 19, 2015, 12:37:47 pm »
Suppose the two numbers in question are 1 and i respectively.

Taking a simple arithmetic mean of the two yields an interpolated result of 0.5 + 0.5i.

This is indeed the point on the complex plane that's half way along a straight line joining the two - but the magnitude of this number is 1/SQRT(2), ie. less than the magnitudes of the two numbers we started with.

Is this correct? Sure - though personally I find it an unintuitive result, and if you're using the magnitude of a complex number to represent something important, then it's probably not what you wanted.

Perhaps what you really want is a number whose magnitude is halfway between that of the two numbers you started with, and a phase that's halfway between the two as well. In that case, you'd need to convert to polar coordinates before taking your average, and then back again. You'd end up with (1/SQRT(2)) + i(1/SQRT(2)), which has a different "correct" magnitude and phase.

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Interpolating Complex Numbers
« Reply #23 on: January 19, 2015, 01:24:19 pm »
Quote
If I have phase and magnitude I can leave them in that form for multiplication/division but to add/subtract it has to be converted to rectangular format.

All arithmetic operations can be done in either forms, or exponent form as well.
================================
https://dannyelectronics.wordpress.com/
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 13125
  • Country: us
Re: Interpolating Complex Numbers
« Reply #24 on: January 19, 2015, 05:44:32 pm »
It may not be the most suitable method however, as for example if your data points trace out curves on a Smith chart, you would want to use circular segments to interpolate.  The suggestion of higher order interpolation methods (such as splines: quadratic or cubic curves, polynomial least-squares, etc.) will have similar results.

Perhaps what you really want is a number whose magnitude is halfway between that of the two numbers you started with, and a phase that's halfway between the two as well. In that case, you'd need to convert to polar coordinates before taking your average, and then back again. You'd end up with (1/SQRT(2)) + i(1/SQRT(2)), which has a different "correct" magnitude and phase.

As I implied, and as you spelled out, both procedures/answers are valid.

Which is preferable depends on the significance/meaning/interpretation placed on those numbers in a specific application.

Taking all these answers together and summarizing for people reading along, what it tells us is that interpolation is a path dependent process. If you want to know what value is "half way" between points A and B you need to know what path is followed in getting from A to B. You can then find the point that is half way along this path. The path may be a straight line, an elliptical arc, or some other path. (For instance, if you wanted to interpolate the intermediate position of a planet in orbit you would interpolate along an elliptical arc.)

The arithmetic mean makes the assumption of a straight line path, but this is not always the actual or most meaningful path.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->