Offline
Newbie
Karma: 0
Posts: 26
|
 |
« Reply #2 on: April 13, 2011, 08:08:05 pm » |
sorry i was reffering to other peoples code and i wasnt sure if i could post that
here goes:
#include <TVout.h> #include <fix_fft.h> TVout TV; char im[128], data[128], lastpass[64]; char x=32, ylim=90; int i=0,val; void setup() { TV.begin(_NTSC,128,54); // Initialize TV output, 128x96. TV.print_str(2,2," Realtime Arduino"); // TVout lib uses x,y for print TV.print_str(2,11," Spectrum Analyzer"); // statements. 8x8 default font. analogReference(DEFAULT); // Use default (5v) aref voltage. for (int z=0; z<64; z++) {lastpass[z]=80;}; // fill the lastpass[] array with dummy data }; void loop() { for (i=0; i < 128; i++){ // We don't go for clean timing here, it's val = analogRead(0); // better to get somewhat dirty data fast data = val/4 -128; // than to get data that's lab-accurate im = 0; // but too slow, for this application. };
fix_fft(data,im,7,0); for (i=1; i< 64;i++){ // In the current design, 60Hz and noise data = sqrt(data * data + im * im); // in general are a problem. Future designs TV.draw_line(i+x,lastpass,i+x,ylim,0); // and code may fix this, but for now, I TV.draw_line(i+x,ylim,i+x,ylim-data,1); // skip displaying the 0-500hz band completely. lastpass=ylim-data; // if you insist, initialize the loop with 0 }; // rather than 1. };
|