Sei sulla pagina 1di 3

13/3/2015

ArduinoRealtimeAudioSpectrumAnalyzerwithVideoout!

MakeRadioLocmanYourHomepage!

All News Articles Circuits Sites Datasheets Devices Forum


Search

AdvancedSearch+

SchematicsAudioVideoMeasurementMCUopensourceplatformsMicrocontrollersusage
12172010

ArduinoRealtimeAudioSpectrumAnalyzerwithVideoout!

eNewsletterSubscription
ContactUs
RadioLocmanontheSocialWeb:

PaulBishop
Onceagain,IdecidedtoputtheoldtravelDVDplayer'sscreentogoodusebyusingasanoutput
devicefortheArduino.ThoughtheDVDmechanismisbroken,thescreenallowsforstandardNTSC
compositevideoinput..runsonanattachedrechargeablebatterypack(canalsopowertheArduino.)

Imakenoguarantees,andyoudosoATYOUROWNRISK,butitshouldworkwithanyTVordevice
thatallowsNTSCVideoIn.Iaminnowayresponsibleifyoudamageyourselforyourequipment.This
isaprototypebuiltbyanamateur,keepthatinmind.

Abrilliantbitofcode,theTVoutlibraryforArduino,allowsyoutogeneratecompositeNTSC
monochromevideowithonlytwopinsandtworesistors.Igenerallyleavetheresolutionatthedefault
12896,whichtranslatesto1612textwiththedefault88font.Runningunderthedefaultsseemsto
givetheleastamountoftroublewiththislibrary,whichisaworkinprogress.Notethatduetothislibrary
beingactivelyworkedon,there'snoguaranteethecodeIamusingwillworkwithotherIDEorLibrary
versions.Thishasbeendevelopedusingversion0019,thoughIwillbetestingshortlyonthemost
recentreleases.Inaddition,thoughitshouldnotmatter,Iamusinga5vAdafruitBoarduino.There
shouldbenodifferences,aslongasyourArduinoisa5vdevice.AlsonotethatoldversionsofArduino
whichuseanAtmelATmega168won'tbeabletorunthis,theydon'thaveenoughmemory.

http://www.radiolocman.com/shem/schematics.html?di=71070

1/3

13/3/2015

ArduinoRealtimeAudioSpectrumAnalyzerwithVideoout!

Clicktoenlarge
Theotherpieceofthepuzzleiscollectingandprocessingaudio,sowehavesomethingtodisplayon
ourlittledisplay.
Thefirstpiecedatacollectionisfairlystandard.Iuseanelectretmicrophone(whichaloneonly
producesafewmVoutput,fartoolowforourArduinotousedirectly)withatransistoramplifierasthe
signalsource,whichisthensampledviatheADContheAnalog0pinoftheArduino.
Todospectrumanalysishowever,youneedtocapturesignalovertime,thenprocessthatdatawith
whatisknownasaFourierTransformation.Thismagicalprocesstakesasignalandbreaksitdowninto
bucketsbaseduponfrequenciesfoundwithinthesample.Thisproducesaremarkablygoodpictureof
thesignalandifdisplayed,functionsasavisualspectrumanalyzerifloopedoverandover.
Inthisproject,I'veusedcodepostedbyausertotheArduinoforums
ThispostcontainsalibrarywhichperformsboththesamplingandtheFastFourierTransformation
completelyinCin8bits,amazingfastconsideringthatfact,andusesafewtrickstobereallystingyon
memory,whichisatapremiumonArduinoespeciallywiththeTVoutdataspaceeatingupquiteabit.
SincetheAtmega328onlyhas2kofRAM,everybytecounts.Matrixmathdonelikethisisnothingshort
ofawesome.Bestofall,it'susableasalibrary.Cutandpastethe.cppand.hintoanewfoldernamed
"FFT"intheLibrariesdirectory.MyArduinoprojectcodeisadaptedfromtheoriginalcodefromthe
forumpostedArduinoprogram.
So,toproduceourdesiredoutcome,wejustneedtogetthewholeshowtogetherandhopeitcan
perform.Withonlyahandfulofcheapcomponents(afewdollarsatmost),itproducesaperfectlyusable
andquiteentertainingrealtime64bandvideospectrumanalyzer.Thoughnotreally"useful"foranyreal
purposes,itmakesanentertainingpartydisplayoutofanytelevisionwithavideoinput...
Therearealotofimprovementswhichcanbemadethefirstbeingtheamplifiergaintomakeitabit
moreresponsive,andoptimizationoftheFFTcode.Inreality,it'sthedrawingofthebarswhichtakes
themosttimepersample/displaycycle..notthematrixmath!
Thecircuitrequiredisasimplemicrophoneandtransistoramplifier,aswellastworesistorsconnected
toD8andD9toprovidevideosignal..drawingisamuchbiggerpainthanyou'dthink!

Clicktoenlarge
Sourcecode(Arduino)
#include TVout.h
#include fix_fft.h
TVoutTV;

http://www.radiolocman.com/shem/schematics.html?di=71070

2/3

13/3/2015

ArduinoRealtimeAudioSpectrumAnalyzerwithVideoout!

charim[128],data[128],lastpass[64];
charx=32,ylim=90;
inti=0,val;
voidsetup()
{
TV.begin(_NTSC,128,96);//InitializeTVoutput,128x96.
TV.print_str(2,2,"RealtimeArduino");//TVoutlibusesx,yforprint
TV.print_str(2,11,"SpectrumAnalyzer");//statements.8x8defaultfont.
analogReference(DEFAULT);//Usedefault(5v)arefvoltage.
for(intz=0;z<64;z++){lastpass[z]=80;};//fillthelastpass[]arraywithdummydata
};
voidloop()
{
for(i=0;i<128;i++){//Wedon'tgoforcleantiminghere,it's
val=analogRead(0);//bettertogetsomewhatdirtydatafast
data[i]=val/4128;//thantogetdatathat'slabaccurate
im[i]=0;//buttooslow,forthisapplication.
};
fix_fft(data,im,7,0);

for(i=1;i<64;i++){//Inthecurrentdesign,60Hzandnoise
data[i]=sqrt(data[i]*data[i]+im[i]*im[i]);//ingeneralareaproblem.Futuredesigns
TV.draw_line(i+x,lastpass[i],i+x,ylim,0);//andcodemayfixthis,butfornow,I
TV.draw_line(i+x,ylim,i+x,ylimdata[i],1);//skipdisplayingthe0500hzbandcompletely.
lastpass[i]=ylimdata[i];//ifyouinsist,initializetheloopwith0
};//ratherthan1.
};

blurtime.blogspot.com
Youmayhavetoregisterbeforeyoucanpostcommentsandget
fullaccesstoforum.

UserName UserName
Password

RememberMe?
Login

Schematicsontheme:

AudiospectrumanalyzeronPIC32
ImplementingDiscreteFourierTransforminAtmega32tomakeanaudiospectrumanalyzer
Handheld2.4GHzSpectrumAnalyzer.Part1
Handheld2.4GHzSpectrumAnalyzer.Part2
AudioSpectrumMonitor

RadioLocmanMedia

FreeServiceManualsFreeelectronicProjects

http://www.radiolocman.com/shem/schematics.html?di=71070

3/3

Potrebbero piacerti anche