Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your example</p> <pre><code>eq1=0.2*cos(2pi*t*3+phase1)+vertical offset1 eq2=0.7*cos(2pi*t*9+phase2)+vertical offset2 eq3=0.8*cos(2pi*t*5+phase3)+vertical offset3 eq_total=eq1+eq2+eq3 </code></pre> <p>where the maximum amplitude should be less than 0.8, has infinitely many solutions. Unless you have some additional objective you'd like to achieve, I suggest that you modify the problem such that you find the combination of phase angles that has a maximum amplitude of <em>exactly</em> 0.8 (or 0.79, such that you're guaranteed to be below). </p> <p>Furthermore only two out of three phase angles are independent; if you increase all by, say, <code>pi/3</code>, the solution still holds. Thus, you have only two unknowns in <code>eq_total</code>.</p> <p>You can solve the nonlinear optimization problem using e.g. <a href="http://www.mathworks.com/help/techdoc/ref/fminsearch.html" rel="nofollow noreferrer">FMINSEARCH</a>. You formulate the problem such that <code>max(abs(eq_total(phase1,phase2)))</code> should equal 0.79.</p> <p>Thus:</p> <pre><code>%# define the vector t, verticalOffset here %# objectiveFunction is (eq_total-0.79)^2, so the phase shifts 1 and 2 that %# satisfy this (approximately) should guarantee that signal never exceeds 0.8 objectiveFunction = @(phase)(max(abs(0.2*cos(2*pi*t+phase(1))+0.7*cos(2*pi*t*9+phase(2))+0.8*cos(2*pi*t*5)+verticalOffset)) - 0.79)^2; %# search for optimal phase shift, starting at no shift solution = fminsearch(objectiveFunction,[0;0]); </code></pre> <p><strong>EDIT</strong></p> <blockquote> <p>Unfortunately when I Try this code and plot the results the maximum amplitude is not 0.79 it's over 1. Am I doing something wrong? see code below t=linspace(0,1,8000); verticalOffset=0; objectiveFunction = @(phase)(max(abs(0.2*cos(2*pi*t+phase(1))+0.7*cos(2*pi*t*9+phase(2))+0.8*cos(2*p‌​i*t*5)+verticalOffset)) - 0.79)^2; s1 = fminsearch(objectiveFunction,[0;0]) eqt=0.2*cos(2*pi*t+s1(1))+0.7*cos(2*pi*t*9+s1(2))+0.8*cos(2*pi*t*5)+verticalOffs‌​et; plot(eqt)</p> </blockquote> <p><code>fminsearch</code> will find a minimum of the objective function. Whether this solution satisfies all your conditions is something you have to test. In this case, the solution given by <code>fminsearch</code> with the starting value <code>[0;0]</code> gives a maximum of ~1.3, which is obviously not good enough. However, when you plot the maximum for a range of phase angles from 0 to 2pi, you'll see that `fminsearch didn't get stuck in a bad local minimum. Rather, there is no good solution at all (z-axis is the maximum).</p> <p><img src="https://i.stack.imgur.com/rrPM2.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload