From: Nimit Dhulekar on
Hi,
I've been trying to compute the angular average of the power spectrum i.e. finding how much power is concentrated at different orientations/angles. The code I have is as follows:

function angswath3(pwrspec)
%pwrspec is the power spectrum
clc;
[N N] = size(pwrspec);

% coordinates of the power spectrum
[X Y] = meshgrid(-N/2:N/2-1);

% converting to polar coordinates
theta = linspace(0,2*pi,100); % angle
rho = linspace(0,N/2-1,100); % radius

py = zeros(length(theta),1);
for p = 1 : length(theta)

xfinal = rho * cos(theta(p)); % converting back to cartesian coordinates
yfinal = rho * sin(theta(p)); % converting back to cartesian coordinates

% using interpolation to compute intermediate power values
px = interp2(X,Y,pwrspec,xfinal,yfinal,'cubic');
py(p) = sum(px); % summing power along different orientations
end
% plotting the angular distribution of the power spectrum
figure; plot(theta*180/pi,py,'r'); hold on; plot(theta*180/pi,py,'*');
end


I'm getting negative values in the interpolated power spectrum which is definitely wrong since the original power spectrum cant have negative values. Can anyone please tell me what might be the error?

Thanks,
Nimit
From: Doug Schwarz on
Nimit Dhulekar wrote:
[snip]

> % using interpolation to compute intermediate power values
> px = interp2(X,Y,pwrspec,xfinal,yfinal,'cubic');

[snip]

> I'm getting negative values in the interpolated power spectrum which is
> definitely wrong since the original power spectrum cant have negative
> values. Can anyone please tell me what might be the error?

You have used the 'cubic' method with your interpolation which can lead
to values outside the range of the data. Try 'linear' interpolation
instead or just clip those values that are less than zero.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.