# Extracting the phase of a jittering sine wave using python

The background: I conducted an experiment where I rotated an object (with three-fold symmetry) many times and recorded the projection of the object. I should be able to tomographically reconstruct the object using an inverse Radon transform.

However, first, I need to know the exact angle of the object at each step. Unfortunately, our experiment was not perfectly stable and the object did not rotate in perfectly consistent steps. The object has a "three-leaf clover" shape, and if I plot the "asymmetry" of the projection (top-bottom/(top+bottom)), then it should look like a sine wave that has a peak every 120 degrees of phase (due to the three-fold symmetry).

Anyway, here is the real problem: In the figure below, I plotted the real asymmetry of the images in blue. In red, I plot a simple sine wave of what the asymmetry should be if there was no experimental jitter. If you look at the blue data with your eye, you can clearly see where it deviates from the model and you can infer what the actual phase of the wave should be. However, I have no idea how to convince python to assign a phase to each datapoint based on its actual asymmetry value. Any ideas?? Here is the data and the code used to make the simple plot:

text = """0.58018836  0.54719772  0.35009603 -0.07093418 -0.38495609 -0.56433715
-0.58238798 -0.58197763 -0.79733289 -0.91822821 -0.88177671 -0.71078292
-0.1013863   0.53490235  0.50354981  0.05747148 -0.49258035 -0.86043242
-0.73366264 -0.11736485  0.40830017  0.75403686  0.76892275  0.74578394
0.67759482  0.58632213  0.38615145 -0.04784894 -0.58773909 -0.80827248
-0.70176645 -0.3018048   0.33288852  0.75568507  0.52563443 -0.09271778
-0.74360484 -0.93751009 -0.84840137 -0.62956237 -0.18022792  0.23716647
0.58545184  0.70021713  0.61602417  0.39086982 -0.09830602 -0.73635755
-0.83658372 -0.36582787  0.12293982  0.51728333  0.72395964  0.77727396
0.71986029  0.43646683  0.0821097  -0.33721973 -0.75678586 -0.59755965
0.08786262  0.59804408  0.76638545  0.4829408  -0.01587402 -0.42493757
-0.63032865 -0.70086101 -0.71030878 -0.55375893 -0.16074062  0.42243708
0.78208721  0.58585221  0.14783457 -0.32854651 -0.73844163 -0.74110153
-0.28917785 -0.03469134 -0.03392741  0.10028943  0.5273808   0.8099916
0.60887728 -0.0270428  -0.64313701 -0.8553194  -0.82824477 -0.60014313
-0.2471473   0.2198018   0.56404379  0.71217775  0.81460569  0.66100642 """

import numpy as np
import matplotlib.pyplot as plt

asym = np.array(text.split())
plt.plot(asym)

step = 11.76
theta = np.linspace(0,np.shape(asym)*step,np.shape(asym))

plt.plot(np.sin(3*theta/180*np.pi),color='r')
plt.show()

• What exactly do you mean by "assign a phase to each datapoint based on its actual asymmetry value"? Do you know how to do it "by hand"? – Matt L. Sep 9 '14 at 20:38
• Well, in general, the phase of the data (blue curve) matches the simple model (red curve). But, sometimes you see that there are little glitches in the blue curve, for example, near x=5 it flattens out for a few datapoints. Obviously the phase is not changing here. So, I want some way of extracting the phase from the actual data. – DanHickstein Sep 10 '14 at 0:19