MATLAB Newsgroup

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.

"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

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

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.

Got questions?

Get answers.

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

Learn moreDiscover what MATLAB ^{®} can do for your career.

Opportunities for recent engineering grads.

Apply TodayThe newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2