title: Sampling at exactly Nyquist rate in Matlab
body: <p>Today I have stumbled upon a strange outcome in matlab. Lets say I have a sine wave such that</p>
  
  <pre><code>f = 1;
  Fs = 2*f;
  t = linspace(0,1,Fs);    
  x = sin(2*pi*f*t);
  plot(x)
  </code></pre>
  
  <p>and the outcome is in the figure.</p>
  
  <p><img src="https://i.stack.imgur.com/p1EfD.jpg" alt="http://i.imgur.com/eUse3MO.jpg"></p>
  
  <p>when I set,</p>
  
  <pre><code>f = 100
  </code></pre>
  
  <p>outcome is in the figure below,</p>
  
  <p><img src="https://i.imgur.com/d5s5G0U.jpg" alt="http://i.imgur.com/d5s5G0U.jpg"></p>
  
  <p>What is the exact reason of this? It is the Nyquist sampling theorem, thus it should have generated the sine properly. Of course when I take <strong>Fs >> f</strong> I get better results and a very good sine shape. My explenation to myself is that Matlab was having hardtime with floating numbers but I am not so sure if this is true at all. Anyone have any suggestions?</p>