How can I fit a second Fourier component to a polar histogram?

조회 수: 3 (최근 30일)
Eric Gbadam
Eric Gbadam 2017년 5월 23일
댓글: David Goodmanson 2017년 5월 26일
I would like to fit a second Fourier series function: E(x) = (1/2*pi)*(1+A1*cos(2*xdata-A2))
to
theta = atan2(rand(100000,1)-0.5,2*(rand(100000,1)-0.5)); polarhistogram(theta,25);
Regards, Eric

답변 (1개)

David Goodmanson
David Goodmanson 2017년 5월 24일
Hi Eric, see how this works. I added an adjustable tilt angle to the random data to test the fit. The code compares the fit to the unnormalized histogram, with its total of 1e5 points. To go to the normalized expression you have, then A1 = B1/c(n0) and A2 = -B2.
npts = 1e5;
n = 25; % should be odd
tilt = pi/4;
theta = atan2(rand(npts,1)-0.5,2*(rand(npts,1)-0.5)) + tilt;
theta = mod(theta+pi,2*pi)-pi;
h = polarhistogram(theta,n);
% start fit
val = h.Values;
c = fftshift(fft(ifftshift(val)))/n; % fourier coefficients
% n0 is index for constant term. c(n0) = npts/n = average bin value
n0 = (n+1)/2;
B1 = 2*abs(c(n0+2));
B2 = angle(c(n0+2));
theta1 = (h.BinEdges(1:end-1) + h.BinEdges(2:end))/2; % bin centers
E = c(n0) + B1.*cos(2*theta1 + B2);
hold on
polarplot(theta1,E,'-o')
hold off
  댓글 수: 3
Eric Gbadam
Eric Gbadam 2017년 5월 26일
David, I get this error message anytime I run the code
Undefined function or variable 'polarhistogram'.
Error in polarfit (line 6) h = polarhistogram(theta,n);
David Goodmanson
David Goodmanson 2017년 5월 26일
Hi Eric, what version of matlab are you using? This seems a bit odd since your original question contains that function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by