title: how to plot the input analog signals from arduino in matlab
body: <p>I have been trying to read analog signals through arduino uno and plotting them in MATLAB. When i gave my input wave from function generator and tried to plot it, the plotted signals were not correct, e.g. an input sine wave didn't give a sine wave. What could be the possible reason? Do I need any external circuit for smooth reading?</p>
  
  <p><strong>ARDUINO CODE</strong> </p>
  
  <pre><code>void setup() 
  { Serial.begin(9600); } 
  void loop() 
  { 
  int a=analogRead(A0); 
  Serial.println(a); 
  delay(1); 
  }
  </code></pre>
  
  <p><strong>MATLAB CODE</strong> </p>
  
  <pre><code>s=serial('COM3','BaudRate',9600); 
  fopen(s) 
  x=1:100; 
  n=1; 
  while n==1 
     for i=1:length(x) 
         tmp=fscanf(s,'%d'); 
         if length(tmp)&gt;1 
            continue; 
         end 
         y(i)=tmp; 
     end 
     y=y/1024*5; 
     ylim([0 5]); 
     plot(x,y) 
     drawnow 
     end 
  fclose(s) 
  </code></pre>