Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Interpolation over complex numbers

Subject: Interpolation over complex numbers

From: Elvis Dieguez

Date: 5 Feb, 2007 15:54:42

Message: 1 of 12

Hi,

I'm running into an interesting problem with interp2. I am
implementing an algorithm that requires the following steps:

fimage = FFT2(image)
POLARTRANSFORM(fimage)
....
CARTESIANTRANSFORM(fimage)
image2 = IFFT2(fimage)

What I've discovered is the process of polar/cartesian transforming
introduces serious errors into the phase component of the FFT'd image
but NOT into the magnitude component. I do the polar/cartesian polar
transforms using interp2 as follows:

function [pim, radius, theta] = c2p(im, N, rlower, rupper)

[rows, cols] = size(im);
cx = cols/2.0 + 0.5; % Add 0.5 because index starts at 1
cy = rows/2.0 + 0.5;

[theta, radius] = meshgrid(linspace(0, 2*pi, N),
logspace(log10(rlower), log10(rupper), N));

xi = radius.*cos(theta) + cx; % Locations in image to interpolate
data
yi = radius.*sin(theta) + cy; % from.

[x,y] = meshgrid([1:cols],[1:rows]);

% Older versions of interp2 may not handle complex numbers correctly!
% Need to interpolate the magnitude and phase separately to avoid
problems.
pim = interp2(x, y, abs(im), xi, yi, 'cubic').*exp(i*interp2(x, y,
angle(im), xi, yi, 'cubic'));

mask = isnan(pim);
pim(mask) = 0;

Is there a reason I am getting junk of the phase interpolation but
not for the magnitude?

Subject: Interpolation over complex numbers

From: Ken Davis

Date: 5 Feb, 2007 16:19:43

Message: 2 of 12

"Elvis Dieguez" <edieguez@ieeeREMOVEME.org> wrote in message
news:ef4cfe8.-1@webcrossing.raydaftYaTP...
> Hi,
>
> I'm running into an interesting problem with interp2. I am
> implementing an algorithm that requires the following steps:
>
> fimage = FFT2(image)
> POLARTRANSFORM(fimage)
> ....
> CARTESIANTRANSFORM(fimage)
> image2 = IFFT2(fimage)
>
> What I've discovered is the process of polar/cartesian transforming
> introduces serious errors into the phase component of the FFT'd image
> but NOT into the magnitude component. I do the polar/cartesian polar
> transforms using interp2 as follows:
>
> function [pim, radius, theta] = c2p(im, N, rlower, rupper)
>
> [rows, cols] = size(im);
> cx = cols/2.0 + 0.5; % Add 0.5 because index starts at 1
> cy = rows/2.0 + 0.5;
>
> [theta, radius] = meshgrid(linspace(0, 2*pi, N),
> logspace(log10(rlower), log10(rupper), N));
>
> xi = radius.*cos(theta) + cx; % Locations in image to interpolate
> data
> yi = radius.*sin(theta) + cy; % from.
>
> [x,y] = meshgrid([1:cols],[1:rows]);
>
> % Older versions of interp2 may not handle complex numbers correctly!
> % Need to interpolate the magnitude and phase separately to avoid
> problems.
> pim = interp2(x, y, abs(im), xi, yi, 'cubic').*exp(i*interp2(x, y,
> angle(im), xi, yi, 'cubic'));
>
> mask = isnan(pim);
> pim(mask) = 0;
>
> Is there a reason I am getting junk of the phase interpolation but
> not for the magnitude?

Without thinking too hard or looking at your code, my guess is a problem
with phase unwrapping.

Subject: Interpolation over complex numbers

From: Herbert Ramoser

Date: 6 Feb, 2007 09:08:16

Message: 3 of 12

Elvis Dieguez wrote:
> I'm running into an interesting problem with interp2. I am
> implementing an algorithm that requires the following steps:
>
> fimage = FFT2(image)
> POLARTRANSFORM(fimage)
> ....
> CARTESIANTRANSFORM(fimage)
> image2 = IFFT2(fimage)
>
> What I've discovered is the process of polar/cartesian transforming
> introduces serious errors into the phase component of the FFT'd
> image
> but NOT into the magnitude component. I do the polar/cartesian
> polar
> transforms using interp2 as follows:

As Ken pointed out you run into a phase unwrapping problem. Phase
information has a discontinuity at 2*pi which is not handled by
imresize. For example: if two neighboring pixels have the angles 0
and 2*pi imresize may use the average value for the output pixel.
This obviously introduces a huge error. Instead of using magnitude
and phase images as input to imresize you could use real and
imaginary part images. These images can be resized savely.

-Herbert

Subject: Interpolation over complex numbers

From: Steve Amphlett

Date: 6 Feb, 2007 10:07:35

Message: 4 of 12

Herbert Ramoser wrote:
>
>
> Elvis Dieguez wrote:
>> I'm running into an interesting problem with interp2. I am
>> implementing an algorithm that requires the following steps:
>>
>> fimage = FFT2(image)
>> POLARTRANSFORM(fimage)
>> ....
>> CARTESIANTRANSFORM(fimage)
>> image2 = IFFT2(fimage)
>>
>> What I've discovered is the process of polar/cartesian
> transforming
>> introduces serious errors into the phase component of the FFT'd
>> image
>> but NOT into the magnitude component. I do the polar/cartesian
>> polar
>> transforms using interp2 as follows:
>
> As Ken pointed out you run into a phase unwrapping problem. Phase
> information has a discontinuity at 2*pi which is not handled by
> imresize. For example: if two neighboring pixels have the angles 0
> and 2*pi imresize may use the average value for the output pixel.
> This obviously introduces a huge error. Instead of using magnitude
> and phase images as input to imresize you could use real and
> imaginary part images. These images can be resized savely.

Don't know much about 2D, but in 1D you get unwanted effects if you
interpolate the real and imaginary parts rather than the magnitude
and phase.

Subject: Interpolation over complex numbers

From: NZTideMan

Date: 6 Feb, 2007 11:18:31

Message: 5 of 12

On Feb 7, 4:07 am, "Steve Amphlett"
<Firstname.Lastname@where_I_work.com> wrote:
> Don't know much about 2D, but in 1D you get unwanted effects if you
> interpolate the real and imaginary parts rather than the magnitude
> and phase.
>

Really?
I don't believe it.
But if you're right, then all the work by hundreds of researchers on
developing global tide models using data from TOPEX/Poseidon
oceanographic satellite is down the drain.
Can you demonstrate a single case where interpolation on real and
imaginary parts gives "unwanted" effects.
Seems to me interpolation on real and imag parts is the ONLY valid way
to interpolate in 1D or 2D without getting screwed up with phase, as
mentioned by others.

Subject: Interpolation over complex numbers

From: Steve Amphlett

Date: 6 Feb, 2007 15:31:56

Message: 6 of 12

NZTideMan wrote:
>
>
> On Feb 7, 4:07 am, "Steve Amphlett"
> <Firstname.Lastname@where_I_work.com> wrote:
>> Don't know much about 2D, but in 1D you get unwanted effects if
> you
>> interpolate the real and imaginary parts rather than the
> magnitude
>> and phase.
>>
>
> Really?
> I don't believe it.
> But if you're right, then all the work by hundreds of researchers
> on
> developing global tide models using data from TOPEX/Poseidon
> oceanographic satellite is down the drain.
> Can you demonstrate a single case where interpolation on real and
> imaginary parts gives "unwanted" effects.
> Seems to me interpolation on real and imag parts is the ONLY valid
> way
> to interpolate in 1D or 2D without getting screwed up with phase,
> as
> mentioned by others.

Ok, let's say you have two sine waves at very similar frequencies and
amplitudes but significantly different phases and want to smoothly
move from one to the other. If you interpolate the real and
imaginary parts independently the amplitude will dip as you move from
one point to the other, whereas you'd probably want the amplitude and
phase to gradually adjust each in a monotonic way. What you really
want in the complex plane is a spiral from one point to the other,
not a straight line.

Subject: Interpolation over complex numbers

From: Steve Amphlett

Date: 6 Feb, 2007 15:48:16

Message: 7 of 12

Steve Amphlett wrote:
>
>
> Ok, let's say you have two sine waves at very similar frequencies
> and
> amplitudes but significantly different phases and want to smoothly
> move from one to the other. If you interpolate the real and
> imaginary parts independently the amplitude will dip as you move
> from
> one point to the other, whereas you'd probably want the amplitude
> and
> phase to gradually adjust each in a monotonic way. What you really
> want in the complex plane is a spiral from one point to the other,
> not a straight line.

... I'm not advocating averaging or any other DSP calcs in general
using amplitude and phase. Just highlighting a case where unusual
interpolation requirements may lean toward it. As in other areas,
one curve that's mathematically in the middle of two others may not
be what's desired.

Subject: Interpolation over complex numbers

From: NZTideMan

Date: 6 Feb, 2007 13:09:57

Message: 8 of 12

On Feb 7, 9:48 am, "Steve Amphlett" <m...@home.now> wrote:
> Steve Amphlett wrote:
>
> > Ok, let's say you have two sine waves at very similar frequencies
> > and
> > amplitudes but significantly different phases and want to smoothly
> > move from one to the other. If you interpolate the real and
> > imaginary parts independently the amplitude will dip as you move
> > from
> > one point to the other, whereas you'd probably want the amplitude
> > and
> > phase to gradually adjust each in a monotonic way. What you really
> > want in the complex plane is a spiral from one point to the other,
> > not a straight line.
>
> ... I'm not advocating averaging or any other DSP calcs in general
> using amplitude and phase. Just highlighting a case where unusual
> interpolation requirements may lean toward it. As in other areas,
> one curve that's mathematically in the middle of two others may not
> be what's desired.

In your (pathological) case, I'd interpolate on real and imag on one
signal, then the other and superpose.

Subject: Interpolation over complex numbers

From: Steve Amphlett

Date: 7 Feb, 2007 04:18:02

Message: 9 of 12

NZTideMan wrote:
>
>
>
> In your (pathological) case, I'd interpolate on real and imag on
> one
> signal, then the other and superpose.

Pathological? It comes up all the time in the simulation world. If
you have noise predictions at a set of finite (engine) speeds and
want to synthesise a slow transient through them, this is exactly
what you have.

Subject: Interpolation over complex numbers

From: Elvis Dieguez

Date: 8 Feb, 2007 13:40:49

Message: 10 of 12

Herbert Ramoser wrote:

I've tried doing the interpolation over real and imaginary parts and
the errors are different but just as bad. I believe you are correct
in diagnosing the problem (i.e. the phase discontinuity). I've tried
using 'unwrap' but that doesn't solve the problem. Could it be that
'unwrap' works column or row wise thereby still leaving
discontinuities on the 2D surface?

> As Ken pointed out you run into a phase unwrapping problem. Phase
> information has a discontinuity at 2*pi which is not handled by
> imresize. For example: if two neighboring pixels have the angles 0
> and 2*pi imresize may use the average value for the output pixel.
> This obviously introduces a huge error. Instead of using magnitude
> and phase images as input to imresize you could use real and
> imaginary part images. These images can be resized savely.
>
> -Herbert

Subject: Interpolation over complex numbers

From: Elvis Dieguez

Date: 8 Feb, 2007 14:31:57

Message: 11 of 12

Never mind I found the error! It was a problem with circular shifting
the matrix.

Elvis Dieguez wrote:
>
>
> Herbert Ramoser wrote:
>
> I've tried doing the interpolation over real and imaginary parts
> and
> the errors are different but just as bad. I believe you are correct
> in diagnosing the problem (i.e. the phase discontinuity). I've
> tried
> using 'unwrap' but that doesn't solve the problem. Could it be that
> 'unwrap' works column or row wise thereby still leaving
> discontinuities on the 2D surface?

Subject: Interpolation over complex numbers

From: NZTideMan

Date: 8 Feb, 2007 11:47:24

Message: 12 of 12

On Feb 9, 7:40 am, "Elvis Dieguez" <edieg...@ieeeREMOVEME.org> wrote:
> Herbert Ramoser wrote:
>
> I've tried doing the interpolation over real and imaginary parts and
> the errors are different but just as bad. I believe you are correct
> in diagnosing the problem (i.e. the phase discontinuity). I've tried
> using 'unwrap' but that doesn't solve the problem. Could it be that
> 'unwrap' works column or row wise thereby still leaving
> discontinuities on the 2D surface?
>
>
>
> > As Ken pointed out you run into a phase unwrapping problem. Phase
> > information has a discontinuity at 2*pi which is not handled by
> > imresize. For example: if two neighboring pixels have the angles 0
> > and 2*pi imresize may use the average value for the output pixel.
> > This obviously introduces a huge error. Instead of using magnitude
> > and phase images as input to imresize you could use real and
> > imaginary part images. These images can be resized savely.
>
> > -Herbert- Hide quoted text -
>
> - Show quoted text -

Sounds to me like you've got a "feature" in your code, otherwise known
as a bug.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us