title: double to int16 (generation or conversion?)
body: <pre><code>fsamp = 2;
  deltaf = fsamp/nfft;   % FFT resolution
  Nfreqtimestwo = 128;  % Used below
  Nsines = Nfreqtimestwo/2 - 1;   % Number of sine waves
  fmult = [1:Nsines];  % multiplicative factor
  freq_fund = fsamp/Nfreqtimestwo;
  freq_sines = freq_fund.*fmult; 
  omega = 2*pi*freq_sines;
  r = int16(0);
  for(ii=1:Nsines)
      r = r + cos((omega(ii)/fsamp)*(0:messageLen-1));   
  end
  </code></pre>
  
  <p>This is the code I am currently using to create my input signal. However, the end result of <code>r</code> is a 32,768 array of doubles. Now I would like to do the best approximation of that using <code>int16</code>. However, I would like to note that amplitude doesn't really matter. For example, my best approach so far I think has been:</p>
  
  <pre><code>    fsamp = 2;
      deltaf = fsamp/nfft;   % FFT resolution
      Nfreqtimestwo = 128;  % Used below
      Nsines = Nfreqtimestwo/2 - 1;   % Number of sine waves
      fmult = [1:Nsines];  % multiplicative factor
      freq_fund = fsamp/Nfreqtimestwo;
      freq_sines = freq_fund.*fmult; 
      omega = 2*pi*freq_sines;
      r = int16(0);
      for(ii=1:Nsines)
          r = r + int16(8192*cos((omega(ii)/fsamp)*(0:messageLen-1)));   
      end
  </code></pre>
  
  <p>Are there any better ways to approach this? </p>
  
  <p><strong>EDIT</strong>
  The reason I want to convert the doubles to ints is because this list is being used in an embedded system and eventually going to a 16-bit DAC... no doubles allowed</p>