How can I fit a second Fourier component to a polar histogram?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!