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

5 ビュー (過去 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 Center および File ExchangeNetworks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by