How can I fit a second Fourier component to a polar histogram?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
David Goodmanson
il 24 Mag 2017
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 Commenti
David Goodmanson
il 26 Mag 2017
Hi Eric, what version of matlab are you using? This seems a bit odd since your original question contains that function.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!