Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Trigonometric interpolation with arbitrary frequencies

Subject: Trigonometric interpolation with arbitrary frequencies

From: gp wr

Date: 30 Apr, 2010 00:43:04

Message: 1 of 2

I am trying to interpolate equidistant data points with trigonometric functions (cos and sin). "Trigonometric interpolation" of equidistant data points typically means Fourier interpolation with preset frequencies of 2*Pi*k/N. This is NOT what I am looking for. Imagine noise-free data consisting of 4 datapoints y(i) where i=0..3. Theoretically, this data can be described by the following model function with 4 variables:
y(i) = a + b*cos(w*i + phi)
The task is to find a, b, w and phi such that the model function fits the data with zero error. I could derive simple formulas for these four parameters in the case of 4 data points and "single-tone" model. A "two-tone" model
y(i) = a + b1*cos(w1*i + phi1) + b2*cos(w2*i + phi2)
can describe 7 data points with zero error. But the derivation of equations for a, b1, b2, w1, w2, phi1 and phi2 is way too complex. Is there a matlab routine that can solve this task? In other words, given 7 noise-free data points generated by two unknown tones, the task is to fins the parameters of these tones.

Thanks.

Subject: Trigonometric interpolation with arbitrary frequencies

From: Roger Stafford

Date: 3 May, 2010 00:09:04

Message: 2 of 2

"gp wr" <gpwr9k95@yahoo.com> wrote in message <hrd92o$cdn$1@fred.mathworks.com>...
> I am trying to interpolate equidistant data points with trigonometric functions (cos and sin). "Trigonometric interpolation" of equidistant data points typically means Fourier interpolation with preset frequencies of 2*Pi*k/N. This is NOT what I am looking for. Imagine noise-free data consisting of 4 datapoints y(i) where i=0..3. Theoretically, this data can be described by the following model function with 4 variables:
> y(i) = a + b*cos(w*i + phi)
> The task is to find a, b, w and phi such that the model function fits the data with zero error. I could derive simple formulas for these four parameters in the case of 4 data points and "single-tone" model. A "two-tone" model
> y(i) = a + b1*cos(w1*i + phi1) + b2*cos(w2*i + phi2)
> can describe 7 data points with zero error. But the derivation of equations for a, b1, b2, w1, w2, phi1 and phi2 is way too complex. Is there a matlab routine that can solve this task? In other words, given 7 noise-free data points generated by two unknown tones, the task is to fins the parameters of these tones.
>
> Thanks.

  This is in answer to your request for a solution to the "two-tone" problem. It turns out there is a direct solution to the problem that avoids iterative methods. For convenience I have used slightly different notation than yours. My u is your w1, v is w2, p is 3*w1+phi1, q is 3*w2+phi2, a is a, b is b1, and c is b2. Given these definitions, the equations below are equivalent to yours. The understanding here is that the unknown quantities, u, v, p, and q, are regarded as lying anywhere in the full circle of values between -pi and +pi.

 y1 = a + b*cos(-3*u+p) + c*cos(-3*v+q);
 y2 = a + b*cos(-2*u+p) + c*cos(-2*v+q);
 y3 = a + b*cos(-u+p) + c*cos(-v+q);
 y4 = a + b*cos(p) + c*cos(q);
 y5 = a + b*cos(u+p) + c*cos(v+q);
 y6 = a + b*cos(2*u+p) + c*cos(2*v+q);
 y7 = a + b*cos(3*u+p) + c*cos(3*v+q);

  Whenever the y's are such that a solution is possible, there are actually 32 different solutions within the above full circle limitation. The matlab code below finds just one of these. The remaining solutions are obtained from five different kinds of alterations. First the sign of F can be reversed which has the effect of interchanging u and v. Next, each of the 'acos' functions always yields a non-negative answer. The sign of each of them can independently be made negative for valid solutions. Finally the output of the 'atan' functions always has a positive cosine - that is, it lies in the first or fourth quadrants. If it is positive, pi can be subtracted, and otherwise pi can be added, and this will also provide valid solutions for either of the 'atan's. In all, there are 2*2*2*2*2 = 32 combinations of these five alternatives, all of which lead to valid solutions.

  The matlab code to find what could be regarded as the "principal" solution out of the thirty-two is as follows:

 A1 = y1+y3-y5-y7;
 A2 = 2*(-y2+y6);
 A3 = 4*(y3-y5);
 B1 = -y1+2*y2-3*y3+4*y4-3*y5+2*y6-y7;
 B2 = 2*(y2-2*y3+2*y4-2*y5+y6);
 B3 = 4*(-y3+2*y4-y5);
 C = A2*B3-A3*B2;
 D = A1*B3-A3*B1;
 E = A1*B2-A2*B1;
 F = sqrt(D^2-4*C*E);
 u = acos((-D+F)/(2*C));
 v = acos((-D-F)/(2*C));
 p = atan(((y2-y6)-2*(y3-y5)*cos(v))*(cos(u)-1)/...
      (sin(u)*((y2-2*y4+y6)-2*(y3-2*y4+y5)*(cos(v)+1))));
 q = atan(((y2-y6)-2*(y3-y5)*cos(u))*(cos(v)-1)/...
      (sin(v)*((y2-2*y4+y6)-2*(y3-2*y4+y5)*(cos(u)+1))));
 c = ((y2-y6)-(y3-y5)*2*cos(u))/(4*sin(v)*sin(q)*(cos(v)-cos(u)));
 b = ((y2-y6)-(y3-y5)*2*cos(v))/(4*sin(u)*sin(p)*(cos(u)-cos(v)));
 a = y4-b*cos(p)-c*cos(q);

  It should be noted that not all sets of y-numbers possess solutions. If the quantity D^2-4*C*E in the square root is negative, there is no solution. Also if either argument in the 'acos' functions fails to fall between -1 and +1, there can be no solution.

  The above solution was found by combining the y-equations in various ways so as to first eliminate a, then b and c, and finally p and q, resulting in the two grand simultaneous equations

 A1 + A2*(cos(u)+cos(v)) + A3*cos(u)*cos(v) = 0
 B1 + B2*(cos(u)+cos(v)) + B3*cos(u)*cos(v) = 0

where these A's and B's refer to the quantities computed above. The solution to these two is a common quadratic equation in both cos(u) and cos(v), with these quantities being the two different roots of this quadratic. The remaining unknowns, a, b, c, p, and q, were determined from some of the intermediate equations obtained along the way prior to their being eliminated.

  You can easily subject the above algorithm to a numeric test by first creating temporary random values for u, v, p, q, c, b, and a in order to produce y-values which would then be guaranteed to have valid solutions. Then the above code could produce its own u, v, p, q, c, b, and a values, which would be different from the random ones first generated, about 31 times out of 32. The new unknown values from this last can then be used to generate a new set of y-values which should be the same (within round off errors) as the original y-values.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us