Sei sulla pagina 1di 28

NoDozeEEGSleepDetector

Createdby:
BenjaminSchneider
DavidMahr
KuangTan

ECE445,SENIORDESIGNPROJECT
FALL2006

TA:HyesunPark

December5,2006
ProjectNo.9

ABSTRACT
Anappreciabledifferenceexistsbetweenbrainwavesofapersonthatisawakeandapersonthatison
thevergeofsleep.Asapersontransitionsfromalertnesstosleep,thealpharhythmsofhis/her
brainwavesdecreaseinfrequency,diminishinamplitude,andbecomemoreirregularinfrequency.
Thesebrainwavechangescanbesensedusinganelectroencephalogram(EEG).Wedevelopedadevice
thatwillrecognizetheshiftfromwakefulnesstosleep,viarecognitionofthefrequencyoftheEEG
signal,andthenrelaythatinformationwirelesslytoanalarmsystem.Thealarmsystemwillvisually
displaytheawarenessleveloftheuserandprovideaudioalertswhentheuserisdrowsyorhasfalling
asleep.

ii

1.

INTRODUCTION....................................................................................................................4
1.1Purpose...............................................................................................................................5
1.2Specifications......................................................................................................................5
1.3Subprojects.........................................................................................................................2
1.3.1EEGModule.........................................................Error:Referencesourcenotfound
1.3.2SleepSignalProcessingModule..........................Error:Referencesourcenotfound
1.3.3BuzzerAlarmModule..........................................Error:Referencesourcenotfound
1.3.4WirelessCommunicationModule........................Error:Referencesourcenotfound
1.3.5LEDAwarenessIndicatorModule............................................................................2
1.3.6AudioModule............................................................................................................2
1.3.7PowerSupplyModule...............................................................................................2

2.

DESIGNPROCEDURE...........................................................................................................3
2.1EEGModuleDesign...........................................................................................................3
2.2SignalProcessingModuleDesign......................................................................................3
2.3BuzzerModuleDesign.......................................................................................................5
2.4WirelessModule................................................................................................................5
2.5LEDAwarenessIndicatorModuleDesign.........................................................................5
2.6AudioModule.....................................................................................................................6
2.7PowerSupplyDesign.........................................................................................................6

3.

DESIGNDETAILS..................................................................................................................7
3.1EEGModule.......................................................................................................................7
3.2SignalProcessingModule..................................................................................................8
3.3BuzzerModule....................................................................................................................9
3.4WirelessModule................................................................................................................9
3.5LEDAwarenessIndicatorModule...................................................................................10
3.6AudioModule...................................................................................................................11
3.7PowerSupply....................................................................................................................11

4.

DESIGNVERIFICATION..............................................13Error:Referencesourcenotfound
4.1Testing..............................................................................................................................13
4.1.1EEGModule...........................................................................................................13
4.1.2SignalProcessingModule.......................................................................................15
4.1.3BuzzerModule........................................................................................................15
4.1.4WirelessModule......................................................................................................16
4.1.5LEDAwarenessIndicatorModule..........................................................................16
4.1.6AudioModule..........................................................................................................16
4.1.7PowerSupplyModule.............................................................................................17
4.2Conclusions.......................................................................................................................17

5. COST......................................................................................................................................18
5.1Parts..................................................................................................................................18
5.2Labor.................................................................................................................................18
6.

ETHICALCONSIDERATIONS............................................................................................19
6.1DeviceEthics....................................................................................................................19
iii

7. CONCLUSIONS....................................................................................................................20
REFERENCES.......................................................................................................................21
APPENDIXABLOCKDIAGRAMS.................................................................................22
APPENDIXBSCHEMATICS............................................................................................23
APPENDIXCFLOWDIAGRAMS...................................................................................28
APPENDIXDSIMULATIONS&TESTDATA...............................................................30
APPENDIXEPICTURES..................................................................................................40
APPENDIXFPARTSANDCOST....................................................................................45
APPENDIXGMISCELLANOUS......................................................................................47
APPENDIXHPICCODE...................................................................................................48

iv

1.INTRODUCTION
AnEEGcollectsbrainwavesbymeasuringthevoltagedifferentialsacrossthescalp.Thesebrainwaves
varyinfrequencyandamplitudeandfallintofourmaincategories:alpha,beta,delta,andtheta.The
typeofbrainwave,whichisbasedmainlyonfrequency,isindicativeofapersonslevelofawareness
(seeTableG.1).Wecreatedadevicethatmonitorsthefrequencyofausersbrainwaves,andalarmsthe
user(andusingbothvisualandaudioalerts)whentheusersbrainwavesdecreaseinfrequencytoa
pointthatisindicativeofdrowsinessorsleep.ThisprocessisaccomplishedthroughtheuseofanEEG,
asignalprocessingmodule,awirelesstransmissionunit,andalarmcircuits.TheEEGprovidesthe
signalprocessingPICwiththebrainwavesignal.ThePICthencalculatestheEEGsignalsfrequency,
determinestheusersawarenesslevel,andoutputsaccordingly.ThePICoutputsarethenrelayed
wirelesslytotheaudioandvisualalarmunits.
1.1Purpose
Ourgoalincreatingthisproductwastodevelopalifesavingdevicethatwillalertdriversthatare
drowsyorhavefallenasleep.Fatigueexistsasthedirectcauseofapproximatelyhundredthousand
crashesintheUnitedStateseachyear.Additionally,drowsinessisamajorcontributortodriver
inattention:thecauseofonemillioncrashesannually,oronesixthofallcrashes.Theseautomobile
accidentsresultinfifteenhundredfatalities,seventyonethousandinjuries,andtwelveandonehalf
billiondollarsinmonetarylosses[1].Evenwiththismagnitudeofloss,noeffectivesleepdetectorfor
driversiscurrentlyavailableonthemarket.Wechosethisprojectbecauseadevicethatcouldprevent
thesetragicphysicaldamagesandfinanciallossesassociatedwithfatiguerelatedautomobileaccidents
wouldbeverybeneficialtothewelfareofoursociety.
1.2Specifications
Themainspecificationofourdeviceisthattheusermustbealertedwithinonesecondoftheoccurrence
ofsleep.Toaccomplishthisfeat,severalspecificationsweresetforeachmodule.TheEEGmodule
mustamplifythemicrovoltbrainwavesignaltoprovidethesignalprocessingPICwithaninputsignalof
atleast1Vpeaktopeakandamaximumof10Vpeaktopeak(0.5V5Vinamplitude).TheEEG
modulemustalsoeliminateanyDCbiasinthebrainwavesignal,andfilteroutanysignalwitha
frequencyoutsidetherangeof1to40Hz.Also,theEEGmodulemustbesuppliedby+5Vand6V.
Thesignalprocessing,buzzer,wireless,LEDawarenessindicator,andaudiomodulesmustbesupplied
by+5V.ThePICmicrocontrollersinthesignalprocessingandaudiomodulesmustnotsourceorsink
morethan25mA.Thebuzzercircuitmusthavethreedistinctvolumelevelsinwhichthemodule
progressesthrough(separatedby1.5s).TheRSSIsignalofthewirelessmodulehastobeatleast3.85V
v

(fortheLEDcircuittofunction).Also,thecommunicationbetweenthetransmitterandreceiverinthe
wirelessmodulemusthavearangeofatleast6ft.
1.3Subprojects
Ourprojectisdividedintoseveralsubprojectswhicheachperformspecifictask(seeFigureA.1):
1.3.1EEGModule
TheEEGmoduleamplifiesbrainwavesviathedifferentialvoltagemeasuredonthescalpbyelectrodes
ontheforehead.TheEEGcircuitshouldamplifythebrainwavesignaltoatleast1Vpeaktopeakand
sufficientlyfilteroutfrequencies2.38to39.38Hz.AfavorableSNRratioalsoneedstobemaintained
throughouttheamplificationprocess.
1.3.2SignalProcessingModule
ThesignalprocessingmoduleisusedtocalculatethefrequencyoftheanalogEEGsignal.The
determinedfrequencyisthenusedtoclassifythelevelofawarenessoftheuser.Thismoduleoutputs
fourdifferentsignals:Transmitter_Power,Sleep_Indicator,Buzzer0,andBuzzer1.The
Transmitter_Poweroutputservestopowerupthewirelesstransmitter.TheSleep_Indicatoroutput
servesasthedatabitsentbythetransmitter.Shiftinthevalueoftheseoutputsreflectachangeinthe
awarenessleveloftheuser,andthus,changesinthevaluesofthesetwosignalswillonlyoccurat8Hz
and12Hzthethresholdfrequenciesbetweenhighalertnessandlowawarenessandbetweenlow
awarenessandsleep,respectively.Buzzer0andBuzzer1outputsareusedtoselectthevolumelevelof
thebuzzeralarm.
1.3.3BuzzerModule
Thebuzzermoduleisusedtoalertasleepinguser.Thismodulereceivestwoinputsignalsfromthe
signalprocessingunit.Theseinputsselectthevolumeofthebuzzerbyselectingoneoffourdifferent
voltagelevelsthatareavailabletothepiezobuzzer.Whentheuserisnotasleep,thebuzzerwillbe
silent.However,whentheuserfallsasleep,thebuzzerproceedsthroughaprogressionofthreealarm
volumesfromlowestintensitytohighestintensity.Thetransitionsinthealarmvolumeareseparatedby
1.5seconds.Thealarmwillremainatthehighestintensityuntiltheuserisnolongerasleep.
1.3.4WirelessModule
Thewirelessmodulereceivestwosignalsfromthesignalprocessingmodulewhichareusedasthe
controlinputsfortheLEDlogicmodule(afterproperconversion).Transmissionrangeofthismoduleis
about10to15feet.
1.3.5LEDAwarenessBarModule
TheLEDlogicmodulereceivestwodigitalinputsfromthewirelessmodule,andusestheminputs,
whicharebasedontheawarenessstatusoftheuser,toselectthecoloroftheLED.Thismodulealso
controlstheoutputoftheaudiomodule.
vi

1.3.6AudioModule
ThismodulereceivesinputfromtheLEDlogicmodule.ByusingaPIC,thismodulegeneratesmelodies
basedontheinputfromtheLEDlogicmodule(reflectsstatusoftheuser).Audioistransmittedviaa
speakerasanoutput.

1.3.7PowerSupplyModule
Thepowersupplymoduleconvertsinputvoltagesfrom6Vto24VunregulatedDCsourceinto+5Vand
6Vwithrespecttoground.Batteriesthatcanbeusedinthismoduleare12Vbatteries,9Vbatteries,or
AA/AAAbatteries.

2.DESIGNPROCEDURE
2.1EEGModuleDesign
ThefunctionoftheEEGmodulewastosuccessfullyacquirebrainwavessignals,sufficientlyamplify
thesignalandfilteroutextraneousnoise.Thisisanessentialcomponentoftheprojectasthissignal
willbeusedtodeterminetheawarenessofthesubject.DisposableAg/AgClelectrodeswereusedonthe
scalpandplacedontherightandleftsideoftheforehead(E.3).Anadditionalelectrodewasplacedon
thenecktoactasaground.5.1kresistorswerealsoplacedinserieswiththeelectrodesinorderto
protecttheuserfromthecircuit[6].
Toinitiallyamplifythesignal,instrumentationamplifierswereused.Aninstrumentationamplifierisa
specifictypeofdifferentialamplifierusedtomeasuresmallvoltagedifferentialsoftheinputswhile
attenuatingcommoninputs[7].Instrumentationamplifiersaremoreadvantageoustouseover
operationalamplifiersastheyarespecificallydesignedtohavelowDCoffset,lowdrift,lownoise,and
highcommonmoderejectionratio.TheAD620BNZinstrumentationamplifierfromAnalogDevices
waschosenbecauseitwasratedhighintheseareas.
Highpassandlowpassfilterswereusedtoattenuateundesirablenoise.Noisethatwasofmostconcern
wasDCoffsetsand60Hznoise.DCoffsetscanoccurduetoshiftingoftheelectrodewiresorthe
dipolepresentintheeye[6].60Hznoiseisdueprimarilytopowerlines.Bothactiveandpassivehigh
passfilterswereusedtofilteroutDCoffsets.Theadvantageswefoundtousingactivefilterswerethat
theyhavesharpercutoffs,arelesssubjecttofeedback,actasabuffertothecircuitandalsoprovedto
respondquickertospontaneousDCoffsets.Passivehighpassfiltersweremadeusingonlyresistorsand
capacitors,whileactivehighfiltersweremadeusingoperationalamplifiersinadditiontoresistorsand
capacitors.Forthelowpassfilter,weusedtheMF6CN50,whichisanactive6thorderlowpassfilter
designedbyNationalSemiconductor.
2.2SignalProcessingModuleDesign
vii

ThemainobjectivesofthesignalprocessingmodulearetodeterminethefrequencyoftheEEGsignal,
classifythatfrequencyasaspecificawarenesslevel,andthenoutputbasedontheusersawareness
state.Themodulehasoneinputandfouroutputs.ThesingleinputisananalogACvoltagesignal
suppliedbytheEEGcircuit.Thisinputsignalshouldhaveanamplitudebetween0and5V,zeroDC
offset,andbeproperlyfilteredtoonlyincludefrequenciesbetween1and40Hz.Uponreachingthe
signalprocessingmodule,theinputsignalwillpassthroughahalfwaverectifiertoeliminatenegative
voltagesinthesignal.Thismodulehastwodigitaloutputsignalstothewirelessmodule,
Transmitter_PowerandSleep_Indicator,andanothertwodigitaloutputsignalstothebuzzercircuit,
Buzzer0andBuzzer1.Theseoutputsdependonthecurrentandpreviousawarenessstatesoftheuser.

TheusersawarenesslevelisbasedonthefrequencyoftheEEGsignal.Ifthefrequencyisgreaterthan
12Hz,theuserishighlyalert.Ifthefrequencyisbetween8Hzand12Hz,theuserhasalow
awareness.Andfinally,ifthefrequencyislessthan8Hz,theuserissleeping.Usingtheabove
mentionedfrequencybasedawarenessdivisions,thesignalprocessingmoduledeterminesthefrequency
oftheinputsignal,andthenassignsanawarenesslevelbasedonthatfrequency.Subsequently,the
userspreviousandcurrentawarenesslevelsarecompared,andthemoduleoutputsbasedonthat
comparison.Thatis,ifthepreviousawarenesslevelishigherthanthecurrentawarenesslevel,a
decreaseinawarenesslevelhasoccurred,andthemodulewilloutputahighTransmitter_Poweroutput
(topowerupthetransmitter)andalowSleep_Indicatoroutput(tosignaladownwardtransition).
Conversely,ifthepreviousawarenesslevelislowerthanthecurrentawarenesslevel,anincreasein
awarenesstakesplace,andthemodulewilloutputahighsignalsforboththeTransmitter_Powerand
Sleep_Indicatoroutputs.Ifthecurrentandpreviousawarenessstatesareequal,bothoftheseoutputs
willbelow.AsfarastheBuzzer0andBuzzer1outputsareconcerned,aslongasthenewawareness
stateisnotsleeping,bothoftheseoutputswillbelow.However,ifthestatetransitionstosleep,the
modulewilloutput01forBuzzer1andBuzzer0,respectively.Ifthenewstatecontinuestobesleeping
after1.5s,theseoutputsignalswillswitchto10.Ifsleepingpersistsforanother1.5s,Buzzer0and
Buzzer1willtransitionsothatbothoutputsarehighsignals.Thesehighoutputsignalswillcontinuefor
bothBuzzer0andBuzzer1untilthenewstateisnotsleeping.
Inorderforourdevicetoproperlyfunctionasasleepdetector,itisimperativeforthefrequencyanalysis
oftheEEGsignaltobeaccurate.Afterresearchingthepossibleoptionsforthistask(analogcircuits,
microcontrollers,digitalsignalprocessingchips),wedecidedthatbasedonthefunctionality,lowcost,
andrelativelylowcomplexity,thePIC16F877Awouldbebestsuitedforourproject.Afterselectingthe
PICasourfrequencyanalysistool,wewentthroughaseriesofpossiblealgorithmsbeforefindingthe
mostaccuratecodefordeterminingtheEEGinputsfrequency.Inourfirstalgorithm,theaveragevalue
oftheEEGsignalwascomputedover256ms.Thenthenumberoftimesthesignalcrossesthataverage
valuewascountedoverthenext500ms.Thefrequencyofthesignalcouldthenbecalculatedaccording
totheequation:
Frequency =

Number of Zero Crossings


2 * Time Interval

(2.2.1)

wheretheNumberofZeroCrossingsisequaltothecountoftransitionsacrosstheaveragevalue,and
TimeIntervalisequaltotheamountoftimethetransitionsarecounted.Andsince,TimeIntervalis
equalto500ms,theequationreducesto:
Frequency=NumberofZeroCrossings.
viii

(2.2.2)

However,wefoundvoltagespikesintheEEGsignalresultedinanaveragevaluethatwasgreaterthana
majorityoftheinputwaveform.Thishighaverageresultedinfictitiouslylowfrequencyreadings.
Sincethisalgorithmcouldnotprovideanaccuratefrequencyreading,wedevelopedanewalgorithm.
Inoursecondalgorithm,thenumberpositivepeaksintheinputsignalwerecounted.Thatis,the
numberoftimestheinputsattime(t)and(t+2)werelessthantheinputattime(t+1)weretallied.The
frequencyofthesignalwasthendescribedbytheequation:
Frequency=2*NumberofPositivePeaks

(2.2.3)

wherethepeaksaresummedover500ms.However,noiseatlowfrequenciesledtoadditionalpeaksin
theinputsignal.Theseextrapeaksresultedinfictitiouslyhighfrequencyreadings.Again,sinceour
algorithmcouldnotcorrectlyprovidethefrequencyoftheinputsignal,wedevelopedanewalgorithm.
Inourthird,andfinal,algorithm,thenumberoftransitionstozerothatoccurredintheinputsignalare
counted.Thatis,thenumberoftimestheinputsignalgoesfromapositivevaluetoazerovalueare
addedup.Thefrequencyoftheinputisthendescribedbytheequation
Frequency=2*NumberofZeroTransitions

(2.2.4)

wherethenumberoffallingedgesarecountedover500ms.Thisalgorithmisabletoprovide
consistentlyaccuratefrequencyanalysis,andconducttheanalysiswiththesecondallottedinthedesign
specifications,andthus,weselectedtouseitasthecodeforourdevice.
2.3BuzzerModule
Themainobjectiveofthebuzzermoduleistoalertasleepinguser.Aslistedinthedesign
specifications,thebuzzercircuitmusthavethreedistinctalarmvolumelevelsinwhichthemodule
transitionsthrough(with1.5sseparatingintensitylevels)everytimetheuserfallsasleep.Wedecided
theeasiestwaytoprovidefourdifferentvolumelevelswouldbethroughtheuseofasimplevoltage
divider.Connectingdifferentsectionsofthevoltagedividerasinputstoa4:1multiplexer,fourdifferent
voltagelevels,rangingfrom0to5V,couldbeusedtosupplythebuzzer.Withtheproperselectinput
bitsfromthesignalprocessingunit,thebuzzercircuitcouldeasilybehaveasdesired.
Whentheuserisawake,theselectbitsare00andthe0V(grounded)inputisselectedtosupplythe
buzzer.Assuch,thebuzzerissilent.Followingtheoccurrenceofsleep,theselectbitstransitionto01
for1.5s,andthebuzzersoundsatitslowestvolume.After1.5s,theselectbitschangeto10forthe
next1.5s,andthebuzzersoundswithmediumintensity.Finally,theselectbitsshiftto11,andthe
buzzersoundsatitshighestvolumeuntiltheselectbitsarechanged.
2.4WirelessModule
Thewirelessmodulesmainobjectiveistotransmitasleepindicatordatabitandaclockflagdatabitto
theLEDlogiccircuitfromthePICintheheadsetunit.Themoduleshouldhavearangeof6to10feet
(aboutthemaximumrangeadrivercouldbeseparatedfromthebasealarmunitinacarortruck).The
datashouldbetransmitterandreceiverspecific,withnodatalossindatacommunication,easyto
control,andcanbepoweredbyaconsumerpowersupplyunit.
ix

WewereofferedtheuseoftheHP3seriestransmitterreceiverpair.Itoperatesonthe900MHzband,
usesFM/FSKmodulation,andhasamaximumrangeof1000feet.IthasabuiltinSAWfilterforoutof
bandrejection,receivesignalstrength(RSSI)andpowerdown(PDN)lines.Ituses2.8to13VDCand
onlyneedsminimalexternalcomponents.Ithasanoptionof8channelsinparallelmodeor100
channelsinserialmode.Afterlookingindepthintoitsdesign,wedecidedtomakeuseofthedata
outputandtheRSSIoutputtorelaythesleepindicatordatabitandtheclockflagdatabit,respectively.
Sincewewereusingthepowerdownlinestorelayclocksignals,theLM555timerwasusedtogenerate
microseconddelayssothatsleepindicatorandclockflagsignalsaresynchronizedperfectly.A
MAX232chipisalsousedtoprovidelevelvoltageregulationfordatacomingoutofthereceiver.
2.5LEDAwarenessIndicatorModule
TheLEDmodulecircuitisusedtodriveanLEDbarthatchangescolorbasedonuserawareness.This
moduleshouldreceivewirelesslyaninputfromthesignalprocessingPIC.Also,theoutputofthis
modulecontrolstheaudiomodule.Theinputintothismoduleshouldbestableandtheoutputshouldbe
abletodriveatleast3LEDs.Intheory,thecombinationoftheclockflagandsleepindicatorbitsshould
changethecoloroftheLEDfromyellowtoorangetored.Visualcueswillthenalerttheuseroftheir
awarenessstatus(yellowcorrespondingtothehigheststateandredthelowest).Thelogic
implementationisbasedonKMaps.
Weimplementedthisdesignbyusingacombinationof4gates.ThegatesusedareORgates,AND
gates,NANDgatesandDFlipFlops.Therespectivechipsare74F08PCquad2InputANDgate,
SN74LS74ANdualDtypepositiveedgetriggeredflipflopswithpresetandclear,SN74F00quad2
inputpositiveNANDgates,andSN74LS3Quad2inputpositiveORgates.TheLEDusedisthe
HLMP4000bicolorLEDlamps,whichfeaturesthreeleadswithacommoncathodeandadiffused
widevisibilitylens.

2.6AudioModule
Theaudiomodulewasinitiallynotincludedinthefirstdesign.Itwasaddedonbecauseourfurther
researchshowedthataudiostimuliplaysanimportantroleinalertingauserfromsleep.Theaudiocues
implementedinourdesignincludeastartupmelody,awarningmelody,andadangersiren.Inspiredby
theworkingsoftheTheremin,thedesignwasimplementedbyusingavariablefrequencyoscillator.
Thisvariableoscillatorwasimplementedthroughtheuseofamicrocontrollerwithvariousdelays
betweenhighandlowoutputs.Themicrocontrolleroutputisthenamplified(gainof200)to
produceaudioviaaspeaker.
ThisdesignwasimplementedusingaPIC16F877AfromMICROCHIP,a5MHzoscillator,andan
LM386N,alowvoltageaudiopoweramplifier.ItreceivesinputfromtheLEDlogicmodule,and
outputsa0.1KHzand2KHzvariablefrequencymelodyoncue.
2.7PowerSupplyModule
Themainfunctionalityofthepowersupplydesignwastoproducestablevoltageregulationfrom
portablepowersupplysourceslikeAAorAAAbatteriesorfrom9voltbatteries.Thismoduleprovides
+5Vand6Vtotheheadsetunit,and+5Vtothebasealarmunit.
x

ByusingtheLM317T3TerminalAdjustableRegulatorfromNationalSemiconductor,manyofour
requirementswerefulfilledeasily.LM317Thasaguaranteedoutputof1.5A,currentlimitconstantwith
temperature,andtheoutputisprotectedfromshortcircuit.ByusingtwoLM317T+5Vpowersupplies
werecreatedontheheadsetandbasealarmunit.Lateron,sincetheopampsrequirea6Vleadrelative
toground,theLM79053TerminalNegativeRegulatorfromNationalSemiconductorwasaddedto
regulate6Vtotheheadsetunit.ThisdevicealsohasthesamesafetyfeaturesastheLM317T.

xi

3.DESIGNDETAILS
3.1EEGModule
ThepurposeoftheEEGwastoamplifythebrainwavesignalwithin1Vppinordertobeprocessedby
thePIC.Becausebrainwavesmeasuredonthescalpareontheorderof10uV,wechosetoamplifybya
gainofapproximately122,000[6].Eachinstrumentationamplifierhasamaxgainof10,000,thuswe
chosetooperatetwoinstrumentationamplifiersinseries.Thegainoneachinstrumentationamplifieris
determinedbyadjustingthevalueofaresisteracrosspins1and8onthechipascanbeseeninFigure
B.2.Equations3.1.1and3.1.2showhowthegainiscalculatedviatheresistorvalue.Becausethetwo
instrumentationamplifiersareplacedinseries,thetotalgainisthecalculatedbytheproductofeach
individualamplifiergain.Equation3.1.3showsthetotalgain.
G

49.4k
1
Rg[]

Rg[]
G1
G2

(3.1.1)

49.4[k ]
G 1

(3.1.2)

49.4k
1 4941
10

49.4k
1 24.656
3.3k || 5.1k

Gtotal G1 G 2 (4941)(24.656) 121,825

(3.1.3)

Passivehighpassfilterswereplaceddirectlybeforetheinputintothefirstinstrumentationamplifier.
Thesepassivehighpassfilterswerebuiltusingresistorsandcapacitorsandhadacutofffrequencyof
0.34Hz(FigB.1).ThepurposeofthesefilterswastoeliminateanyDCoffsetbeforeamplification.
TheequationusedtodeterminetheresistorandcapacitancevaluesisshowninEquation3.1.4.Two
active2ndorderhighpassfilterswereuseddirectlyaftertheoutputofeachinstrumentationamplifier.
Theseactivehighpassfilterswerebuiltusingoperationalamplifiersinadditiontoresistorsand
capacitorsandhadacutoffof2.34Hz(FigB.1).ThepurposeofthesefilterswastoeliminateDCoffset
thathadbeenimproperlyamplifiedbytheinstrumentationamplifier.Theequationusedtodetermine
theresistorandcapacitorvaluesforthisfilterisshowninEquation3.1.5.
1
2 R[]C[ F ]
1
.48Hz
2 (3.3M )(0.1 F )
f [ Hz ]

f [ Hz ]

1
2 R1R 2C1C 2
2.43Hz
xii

1
2 (680k )(680k )(0.1 F )(0.1 F )

(3.1.4)

(3.1.5)

Anactive6thorderlowpassfilterwasplaceddirectlybeforeinputintothePICA/D.Thislowpass
filterwasanMF6CN50,anICbuiltbyNationalSemiconductor.Thecutofffrequencywasdetermined
byadjustinganinternalclockviathevalueofaresistorandcapacitoracrosspins11to9and9to
ground,respectively(FigB.2).Thepurposeofthisfilterwastoattenuateanyhighfrequencynoise
withinthesignal,specificallynoisedueto60Hzpowerlineinterference.Thecutofffrequencyofthe
lowpassfilterwas39.44Hz.Equation3.1.6showshowthecutofffrequencywascalculated.
f [ Hz ]

1
(50)(1.69)( R[]C[ F ])
39.44 Hz

(3.1.6)
1
(50)(1.69)(30k )(.01 F )

Attheendofconditioning,thesignalshouldbeanamplifiedsignalofgain121,825withafrequency
rangeofapproximately2.34to39.44Hz.Thisisacceptableaswearelookingforthetransitionsofa
signalat8Hzand12Hz.
3.2SignalProcessingModule
ThesignalprocessingmoduleconsistsofaFOXF1100Eoscillator,aMicrochip40pinDIP
PIC16F877A,andvariousresistorsandrectifiersprovidingcurrentandvoltageprotection,respectively,
forthePIC.ThecompleteschematicforthemodulecanbeviewedinFigureB.3.A+5Vinputthrough
a1Kresistorisprovidedtopin1.Thishighinputvoltage(withcurrentlimitedbytheresistor)
preventsthememoryofthePICfrombeingcleared.TheanalogEEGsignalisprovidedasaninputto
pin2.ThePICoutputsBuzzer1,andBuzzer0,Transmitter_Power,andSleep_Indicatorareassigned
topins34,35,37,and38,respectively.Theoscillatorhasa20MHzfrequencyofoscillation.1N5822
SchottkydiodesareusedforthetwoVddinputsandEEGsignalinput(pins11,32,and2,respectively)
inordertoprotectthePICfromnegativevoltage.The220resistorsinserieswiththePICinputsand
outputsareusedtoguaranteethePICdoesnotsourceorsinkmorethan25mA.Theresistorvalueis
basedonthefollowingcalculation:
Vmax=Imax*R
5V=(25mA)*R

R=200

(3.2.1)

wherethe200resultexistsastheminimumresistancevalue.
Themaindetailinvolvedinthedesignofthesignalprocessingmoduleexistsastheprogrammingofthe
PIC.TheflowchartshowingthelogicbehindthePICprogramcanbeseeninFigureC.1.Thecode
usedtoprogramthePICcanbeviewinAppendixH.
ThePIChasaninternalA/DconverterthatweusedtoconverttheanalogEEGsignalintoadigital
signalforfrequencyanalysis.TheADCconvertstheanaloginputintoa10bitdigitalsample.Weset
theADCtosampleatarateof500samplespersecond.Wechosetheratetobe500samplespersecond
becauseitwasaconvenientchoiceforthePICcodeandbecausesucharatewouldbemorethan
adequatetosatisfytheNyquistcriterion.Thatis,sincetheEEGsignalofinteresthasabandwidthof40
Hz,theNyquistcriteriondictatesthatthesamplingrateshouldbe80Hzorhighertoavoidaliasing.
SincetheaccuracyofthefrequencyanalysisofthePICisasignificantfactorinthefunctionalityofour
xiii

device,wedecidedmakingthesamplingratesignificantlyhigherthantheminimumrate(toincrease
accuracy)wouldbethebestplan.
UsingtheADCsamples,thenumberoftimestheinputtransitionsfrompositivetozeroiscountedover
a500mstimeinterval.ThePICthenassignstheawarenessstateandcomparestheoldandnew
awarenesslevels.Thisprocesstakesoldmicrosecondsduetothehighfrequencyoftheexternal
oscillator.ThePICthenoutputsbasedonthecurrentandpreviousawarenessstates.Thisprocesshasa
maximumdelayof100ms.Therefore,oneentirecycletakesonlyabout600msavaluethatiswell
belowthedesignspecificationof1second.
3.3BuzzerModule
ThebuzzermoduleconsistsoftwoMCP320B2MallorySonalert6VDCpiezobuzzers,three1K
resistors,andaPhillipsSemiconductorHCT40524:1multiplexor.Thecompleteschematicforthe
buzzermodulecanbeseeninFigureB.4.Thethree1Kresistorsareplacedinserieswith+5Vvoltage
sourcetosetupasimplevoltagedivider.Thenodebeforethefirstresistor,thenodeafterthefirst
resistor,thenodeafterthesecondresistor,andthegroundednodeareconnectedtopins4,5,2,and1,
respectively(ormuxinputs3,2,1,and0,respectively).Theoutputofthemultiplexeristhenconnected
tothebuzzers.Thepossiblevoltagelevelsavailabletothebuzzeraredescribedbythefollowing
equation:
Vin=Vtotal*(Req/RT)

(3.3.1)

yielding5V,3.33V,1.67V,and0Vastheinputvoltagestomuxinputs3,2,1,and0,respectively.
Sincethevolumeofthebuzzerdependsonthevoltageavailable,thissetupallowsthismoduletohave3
distinctalarmvolumesandasilentstate.

3.4WirelessModule
OurwirelessmodulewasbuiltwiththereadilyavailableHP3LinxTransmitter/ReceiverRFpair.This
designwasfairlystraightforwardafterconsultingapplicationnotesfromtheLinxHP3documentation.
OtherICcomponentsincludeinthisdesignistheMAX232componentandtheLM555component.
HowthesecomponentsareconnectedcanbeseenfromtheschematicsinfigureB.5.Basically,thePIC
intheheadsetunitcontrolsthepowerdownlineofthetransmitteraswellasthedataline.Wheneveran
instructionismadetochangethestatusoftheLEDbytransmittingaloworhighsignalthroughthedata
line,thetransmitterwillneedtobepoweredup.Onthereceiverside,twooutputsareconsidered
essential;theRSSIline,andthedataline.TheRSSIlinetransmitstheclockflagsignalandthedataline
transmitsthesleepindicatorbit.Thepowerdownlinerequiresatleast3Vtopoweronthetransmitter
andhasaturnontimeof10ms.Whenthetransmitteristurnedoff,thereceiverhasaninternalhighpull
onthedataline.Onthereceiverside,ahighorlowvalueofthedatapinisobtainedrelativelytothe
powersupply(+5V).ThisiscreatedbyusingaMAX232component.TheMAX232componentis
basicallyaninverterconnectedtoaVccof5V.Bypassingitthroughtwice,alevelvoltageof510Vis
obtained.
Asmentionedbefore,thetransmitterhasadelayofabout10ms.Duringthisdelay,thetransmitter
encountersnoiseduringtransmission.Therefore,aresistorcapacitorIC(LM555)isusedtomakesure
theLEDlogiccircuitreceivesbothsleepindicatorbitandtheclockflagsignal(RSSI)bitatthesame
xiv

timeandthenoiseisbypassed.TheequationgoverningthedelaygeneratedbytheLM555ICisas
follows.
T=1.1RAC

(3.4.1)

Inthiscase,aresistorvalueof10kandacapacitorvalueof1Fwasusedtogenerateadelayof
approximately11ms.Thisbypassesthenoisecreatedduringthepowerupofthetransmitter.Theoutput
voltageis2/3oftheVccvoltage.Thetimingintervalisindependentofvoltagesupply.Application
designisobtainedcourtesyofNationalSemiconductor.
TheoutputofLM555goestotheclockflagpinontheDflipflopintheLEDmodule,andthesleep
indicatorbitgoestotherespondinggateinputsontheLEDmodule.Aflowdiagramofthewhole
processcanbeseenfromfigureC.1andC.2.
TheLinxHP3serieschipusesanFSKtransmissionschemetosenddataovertheairwaves.Therewasa
verydetailedtalkaboutantennadesignandplacementgivenintheLinxdocumentation.However,for
theshortdistancesthatwewereplanningontransmitting(lessthan10ft.)wecouldusealmostany
antennawewantedto.Intheendweendedupusinganexternalantennaonthebasealarmunitand
noneontheheadsetunit.Transmissionworkedflawlessly.
3.5LEDAwarenessIndicatorModule
TheLEDmoduledesignwassimpletodesign.BycontrollingtheinputstotheLED,andaccurate
timing,thewholeprocesscanbesimplifiedtoa2statediagram.Weimplementedthisdesignbyusinga
combinationof4gateICs.ThegatesusedareORgates,ANDgates,NANDgatesandDFlipFlops.The
respectivechipsare74F08PCquad2InputAndGate,SN74LS74ANdualdtypepositiveedge
triggeredflipflopswithpresetandclear,SN74F00quad2inputpositiveNANDgates,andSN74LS3
Quad2inputpositiveORgates.TheLEDusedistheHLMP4000bicolorLEDlamps.Itfeaturesthree
leadswithacommoncathodeandcomeswithadiffusedwidevisibilitylens.Aschematiccanbeseenin
figureB.6.Thecircuitrequiresonlya+5Vpowersupply.
Forourdesign,3colorsareusedtoindicateuserawareness:
Red
Sleeping
Yellow
Normal/Highawareness
Orange
Lowawareness
Table3.5.1Colorsindicatinguserawareness.LEDhasthreeleadswithoneascommoncathode.
Maintainingahighonredandyellowleadscreatesthecolororange.
ThelogicbehindtheLEDcolorchangesisasfollows:
Action(Sleepindicator)
PreviousColor
FollowingColor
High
Yellow
Yellow
High
Orange
Yellow
High
Red
Orange
Low
Yellow
Orange
Low
Orange
Red
Low
Red
Red
Table3.5.2SleepindicatormoderationofLEDcolorsbasedonprevioususerstate
xv

TosignifychangeofLEDstatus,theclockflagsignal(whichiscontrolledbythepoweronofthe
transmitter)changestohigh,thentoalow,thepositiveedgetriggeredDflipflopswilltransmitthenew
statetoitsoutputs,andthusalteringthecoloroftheLED.
Thus,theKmapequationgeneratedisasfollows.
Red
RY+AY+RA
Yellow
R+A
Table3.5.3KMapequationforRedandYellowleadsoftheLED.Rbeingthepreviouspintothe
redLEDleadandYbeingthepreviouspintotheyellowLEDlead.Aisthesleepindicatorbit.
TheLEDleadsrequireavoltageof1.7Vtobeturnedhigh(andbrightnessimprovesasvoltage
increases)andbelow1.7Visconsideredlow(offstate).ThebrightnessoftheLEDgeneratedoverallis
quitegoodandveryvisible.
3.6AudioModule
TheaudioModuledesignusesfrequencychangesanddelayswiththegeneratedsquarewaveformsfrom
thePICtogeneratesoundsofthe0.1KHzto2KHzrange.Bymanipulatingthesevalues,pitch,lengthof
toneandqualityoftonecanbechangedtocreatesimplemelodies.Thecomponentsusedinthismodule
includethePIC16F877A,a5MHzoscillator,andaLM386Nlowvoltageaudiopoweramplifier.The
schematicscanbeseeninfigureB.7.inappendixBalongwithothercomponents.
BygeneratingsquarewaveformsusingthePIC,3melodieswereproduced.Thisincludedastartup
melodywhichdisplayedacontinuousincreaseinfrequencyfollowedbyacontinuousdecrease,a
warningmelodywhichfeaturedvariousbeepsatdifferentfrequenciesseparatedbypredetermined
delays,andadangersirencreatedbyusingaloopedfrequencychangecomprisedof3frequencieswith
nodelays.
Frequency(kHz)

Time(ms)

0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0

5.000
3.333
2.500
2.000
1.667
1.429
1.250
1.111
1.000
0.909
0.833
0.769
0.714
0.667
0.625
0.588
0.556
0.526
0.500

Delay(us)

Delay/2(us)

5000.000
3333.333
2500.000
2000.000
1666.667
1428.571
1250.000
1111.111
1000.000
909.091
833.333
769.231
714.286
666.667
625.000
588.235
555.556
526.316
500.000

2500.000
1666.667
1250.000
1000.000
833.333
714.286
625.000
555.556
500.000
454.545
416.667
384.615
357.143
333.333
312.500
294.118
277.778
263.158
250.000

Table3.6.1:TranslationoffrequencyintodelaywhichisusedtogeneratewaveformsusingthePIC
xvi

3.7PowerSupplyModule
Thepowersupplymoduleuses2LM317TandanLM7905asitsprimarycomponent.TheseareTO220
packagelinearadjustablevoltageregulators.LM317TisconnectedtotworesistorsasshowninFigure
B.8inAppendixB.Theoverallfunctionalityofourpowersupplydesignistoregulatevoltagefrom7V
to12Vwhichcanbefoundinacartopowerupourdevice.
Theequationthatgovernstheoutputvoltageintermsofthecontrolresistorsandacquiescentcurrent
drawisshowninEquation3.1.1.
Vout=1.25(1+R2/R1)+Iadj(R2)

(3.7.1a)

AsseeninFigureB.8,thedividerresistorisactuallythecombinationofR1andR2.Thisallowsusto
adjusttheoutputvoltagetoexactly5.00voltsaboveground.Assuch,theresistorvaluesof300and
900wasused.
Thepowersupplytookanunregulated9voltDCsignalfromabatteryasinput.Itusedthissignalto
powerthevoltageregulatorsthattookthevoltagefrom7voltsto5.00volts.Duetothisvoltagedrop
acrosstheregulator,thepowernotsenttotheoutputterminalswasdissipatedasheatthroughthe
regulator.Ifthevoltagetopowerupthesecomponentsismarginallyhigher,heatsinkswillhavetobe
attachedtothemetalpinsbehindthesecomponentstodissipateheat.Theapplicationdesignisobtained
courtesyofNationalSemiconductor.
TheLM7905componentcircuitisstraightforwardindesignandrequiredlittleexternalcomponentsas
showninfigureB.9.ItispackagedinaT0220powerpackage.Thepowersupplytothecomponentisa
9VDCsignalfromabatteryflippedinpolarity.
Thetotalpowersupplyusedbythebasealarmunitandtheheadsetunitisabout2W.(TableG.2in
appendix)Thistranslatestoroughlyabout2hoursrunningona280mAH9Vbatteryor1015hours
runningon4AAAbatteriesratedat2000mAHintheworstcasescenario(dangersirenon).

xvii

4.DESIGNVERIFICATION
Wewentthroughaseriesofteststoensureourdevicewasworkingproperly.Sincelowawarenessand
sleepofausercannotbeinstantaneouslyachieved,weneededtofindanalternatemethodoftestingour
device.Wedecidedthebesttestingmethodwouldbetosupplyasinusoidalwaveformfromafunction
generatortotheinputoftheEEGcircuit.However,thelowestamplitudeoutputofthefunction
generatoris1mVandwerequiredasignalintherangeoftensofmicrovoltstoproperlysimulate
brainwaves.Tosolvethisproblem,weaddedanamplifierwithagainof1/100tothebeginningofthe
EEGcircuit.Withtheadditionalamplifierinplace,weinputtedthefunctiongeneratoroutputtothe
EEGcircuit,andmonitoredtheamplifiedoutputoftheEEGcircuitonanoscilloscope.Wethenfedthe
EEGoutputintothesingleprocessingcircuit.Varyingthefrequencyofthefunctiongeneratorsignal,
weobservedtheoutputsofthebuzzer,audio,andLEDawarenessindicatormodulestodeterminethe
leveloffunctionalityofthedevice.
4.1Testing
Eachofthemodulesmakingupourprojectwerefirsttestedindividuallytoensurecorrectfunctionality.
Thatis,eachmodulewastestedtoverifydesignspecificationsweremet.Then,moduleswereintegrated
togetherandtheresultingproductwastestedforfunctionality.Thetestsperformedoneachmoduleare
detailedbelow.
4.1.1EEGModule
FeaturestestedintheEEGmoduleincludethegainandCMRRoftheinstrumentationamplifiers,
frequencyresponsesoffilters,andoverallfunctionalityoftheEEGtoacquirebrainwavesignals.
Toexaminetheactualgainofthecircuit,theactualgainofeachinstrumentationamplifierwas
determinedbytakingtheratioofoutputvoltagetoinputvoltage(Eq.4.1.1.1).Usinga1mVppsine
waveasaninputintothefirstinstrumentationamplifierwiththeoreticalgainof4941,a4.93Vppsine
wavewasoutput(FigD.1).Thisresultsinanactualgainof4930whichisslightlylessthanthe
theoreticalvalue.Forthesecondinstrumentationamplifierwiththeoreticalgainof24.656,a0.1Vpp
sinewavewasinputanda2.75Vppsinewavewasoutput(FigD.2).Thisresultsinanactualgainof
27.5whichisslightlyhigherthanthetheoreticalvalue.Thesedeviationsfromthetheoreticalvalue
xviii

couldbearesultofinconsistenciesintheactualresistorvaluesorpossiblefluctuationsintheoutputof
thefunctiongenerator.Atanyrate,theactualgainoftheentirecircuitcanbecalculatedas135,575,
whichisstillsufficientforitspurpose.
G actual

V out
V in

(4.1.1.1)

TheCommonmoderejectionratio(CMRR)ofaninstrumentationamplifiermeasuresthetendencyof
thedevicetorejectinputsignalscommontobothinputleads[8].AhighCMRRdeterminesthe
effectivenessofaninstrumentationamplifierandisespeciallyimportantwhenmeasuringverysmall
voltagedifferentials.TheCMRRcanbecalculatedbyEquation4.1.1.2.
Ad
(4.1.1.2)

As
Ad=DifferentialGain,As=CommonmodeGain

CMRR 20glog 10

Totestthis,theinputsareshortedandtheoutputisdeterminesthecommonmodegain.Thedifferential
gainistheactualgainofeachamplifier.Forthefirstamplifierwithactualgainof4930,thecommon
modegainwasdeterminedas0.2.Thus,thecalculatedCMRRwas87.83dBwhichisaverygoodvalue
foranamplifierofsuchalargegain(Eq.4.1.1.3).Forthesecondamplifierwithactualgainof27.5,the
commonmodegainwasmuchlessthan0.001.TheCMRRismuchgreaterthan200dBwhichisvery
goodandexpectedbecausethegainismuchlower(Eq.4.1.1.4).Thus,theCMRRofthe
instrumentationamplifiersisabovesatisfactory.

4930

0.2

27.5
200dB ? 20glog 10

= 0.001
87.83dB 20glog 10

(4.1.1.3)
(4.1.1.4)

Thefrequencyresponsesofeachfilterwerecompiledbysweepingfrequenciesfrom0to100Hzwith1
Vppsinewaveswithstepsof0.1Hzbetweeneachpoint.Thesewerethencomparedtothesimulation
dataproducedinPSpice.
Thesimulatedandactualfrequencyresponsesofthepassivehighpassfilterwithcutoffof0.34Hzare
showninFiguresD.3andD.4,respectively.Itcanbeseenthatboththesimulationandactualdataare
verysimilar.Thesimulatedandactualfrequencyresponsesoftheactive2ndorderhighpassfilterwith
cutoffof2.34HzareshowninFiguresD.5andD.6,respectively.Itcanalsobeseenthatboththe
simulationandactualdataareverysimilaraswell.Thistestingshowsthatbothtypesofhighpass
filtersareworkingeffectivelyandwillsuccessfullycutofflowDCoffsetnoise.
Thesimulatedandactualfrequencyresponsesoftheactive6thorderlowpassfilterwithcutoff39.44Hz
areshowninFiguresD.7andD.8,respectively.Itcanbeseenthattheactualfrequencyresponseofthe
lowpassfilterismuchsharperthanthesimulatedresponse.Becausethelowpassfilterweusedwasan
IC,itdidnotexistonPSpice,thuswewerenotabletodoexactsimulation.Instead,webuiltanactive
6thorderfilterinPSpiceusingoperationalamplifiers,resistorsandcapacitors.Thisisthereasonthe
simulatedandactualfrequencyresponsesdiffer,however,theactualresponseismoredesirable.This
xix

showsthatthelowpassfilterisworkingeffectivelyandwillsufficientlycutoffhighfrequencynoise
above39.44Hz.
Finally,theactivelowpassandhighpassfilterswereconnectedinseries.Asexpected,boththe
simulatedandactuallyfrequencyresponseattenuatefrequenciesbelow2.34Hzandabove39.44Hz(Fig
D.9andD.10).Again,weseethattheactualresponseismuchsharperandmoredesirablethanthe
simulatedresponse.
WheneverythingwasfinallyconnectedasseeninFigureB.2,theEEGsignalwastested.Asampleof
theEEGoutputcanbeseeninFigureD.11.Itcanbeseenthatsignalisapproximately27Hzandis734
mVpp.ThisiswithinourdesiredrangeandverifiestheEEGmoduleisworkingproperlyasawhole.
TotesttheabilityoftheEEGtodetectbrainwavesfromawaketodrowsytosleeping,theoscilloscope
wassetuptoreadforanextendedperiodoftime.Thetime/divisionwassetat50s/div,givingatotal
readtimeof500secondsor8.33minutes.ThescopedatawasimportedintoMatlabandtheaverage
frequencywascalculatedevery5secondsaccordingtohowthePICcalculatedfrequency.InFigure
D.12,itcanbeseenthatoverthetime,asthesubjectbecomesincreasinglydrowsy,thefrequencyof
brainwavesdecreases.Thus,iftheEEGwereconnectedtotherestofthemodulesthealarmwouldhave
beenturnedonandwaketheuser.
4.1.2SignalProcessingModule
ThedesignspecificationsforthesignalprocessingmoduledictatethattheTransmitter_Poweroutput
shouldbehighforalltransitionsinawarenesslevels,theSleep_Indicatoroutputshouldbehighfor
increasesinawarenesslevelsandlowfordecreasesinawarenesslevels,andthatbothoutputsshouldbe
lowifnotransitionoccurs.Also,thespecificationscallfortheBuzzer1andBuzzer0outputstobelow
forallstatesexpectthesleepstate,andduringthesleepstatetheseoutputsshouldprogressfrom01to
10andfinallyto11(changesseparatedby1.5seconds).
Sincetheawarenessleveloftheuserisbasedsolelyonthefrequencyoftheuser,varyingtheinput
frequencyisnecessarytotestthefunctionalityofthesignalprocessingmodule.Thefrequenciesof
interest,orthresholdfrequencies,are8Hzand12Hz.Thisisthecasesinceafrequencyofgreaterthan
12Hzisindicativeofhighawareness,between8and12Hzisindicativeoflowawareness,andlessthan
8Hzisindicativeofsleep.
Thefirsttestconductedonthesignalprocessingmoduleinvolvedprovidinga1VppsinusoidalAC
signalwithzeroDCoffsetdirectlytotheEEGsignalinputofthePIC.LEDswereplacedinserieswith
theresistorsconnectedtotheoutputsofthePIC.Assuch,ahighoutputwouldcausetheLEDtolight
up,whilealowoutputwouldelicitnochangeintheLED.Thefrequencyoftheinputsignalwasslowly
decreasedfrom20Hzto1HzandtheoutputsofthePICweremonitoredviatheLEDs.ThePIC
performedasexpectedexceptforanalternationinawarenessstateatthethresholdfrequencies.This
alternationwasobviousastheTransmitter_PowerandSleep_Indicatoroutputconstantlyswitchedfrom
hightolow.TheresultsofthistestcanbeseeninFigureD.13.Thisindecisionatthresholdfrequencies
persistedineachofthethreealgorithmsusedforthePIC.Thispersistencesuggeststhattheproblemis
notcoderelated,butismostlikelyduetonoisewithinthePIC.Thisnoisemaybeminimizedbyusinga
higherqualitymicroprocessor.However,thealternationinoutputvalues,from13.3Hzto11.6Hzand
from8.3Hzto7.2Hz,isnotnecessarilyabadoccurrenceitresultsininformingtheuserslightlybefore
thedangerousstatesoflowawarenessandsleeparereached.Also,thePICperformancewastestedwith
xx

differentinputvoltageamplitude.ThePICperformedinthesamemannerforinputsignalvoltage
amplitudesrangingfrom0.5Vppto8Vpp.Thisresultsuggeststhatthe1Vppsignalprovidedbythe
EEGmoduleisadequateforcorrectfunctionality.
ThesecondtestinvolvedprovidingthePICwiththeoutputoftheEEGmodule.Inthistest,theEEG
circuitwasprovidedwith0.001VppACsinusoidalsignalfromthefunctiongenerator.Thefrequency
oftheinputsignalwasthendecreasedslowlyandthePICoutputsweremonitoredviaLEDs.ThePIC
appearedtoperformwellathigherfrequencies,buthadsomeerroroneousoutputsatfrequenciesbelow
10Hz.Specifically,thePICdidnotsendanoutputreflectingadecreaseinawarenessuntilabout5Hz
(insteadof8Hz).BymonitoringthePICinputontheoscilloscope,wefoundthathighfrequencynoise
enterstheinputatlowerfrequencies.Thedifferenceinthequalityoftheinputbetweenhighandlow
frequenciescanbeseeninFiguresD.17andD.18,respectively.Itappearedthattheextrapeaksarising
fromthenoisewerefallingtozeroatpointsresultinginfictitiouslyhighfrequencyreadings.Wethen
increasedtheamplitudeoftheinputsignalto0.004Vppandtheextrazerotransitionswereeliminated.
ThePICthenperformedasthespecificationsdictate(expectforthealternationinoutputsaround
thresholdfrequenciesdiscussedabove).
4.1.3BuzzerModule
Thedesignspecificationsofthebuzzermodulecallforthreedistinctvolumelevelsandasilentstate
basedontheselectinputsfromthesignalprocessingmodule.Thefunctionalityofthismodulewas
testedinthreemanners.Inthefirsttest,allcombinationsofselectinputswereprovidedbydirect
connectionsto+5Vvoltagesourceand/orground.Thebuzzercircuitperformedasexpectedwith
silencefor00fortheselectinputs,lowestvolumefor01inputs,mediumvolumefor10inputs,and
highestvolumefor11inputs.Inthenexttest,thePICwasprovidedwitha1VppACsinusoidalinput
withafrequencybelow8Hz.Asdictatedinthedesignspecificationsthebuzzermodulewentthrougha
progressionoflow,medium,andhighvolumealarmsseparatedby1.5seconds.Asexpected,thebuzzer
modulecontinuedwiththehighestvolumealarmuntilthefrequencyoftheinputwasincreasedtoa
valuegreaterthan8Hz.Finally,thebuzzercircuitwastestedbyprovidinga.004VppACsinusoidal
signalwithafrequencybelow8HztotheEEGcircuit.Thebuzzercircuitperformedasexpectedgoing
throughtheprogressionofvolumesandremainingatthehighestvolumeuntiltheinputfrequencywas
increasedtogreaterthan8Hz.
4.1.4WirelessModule
ThemainconcernwithtestingofthewirelessmodulewastherangeaswellasthecorrectLEDcolor
change.Testingwasdoneinphasestoensureproperintegrationwiththesignalprocessingmoduleand
LEDawarenessindicatormodule.Theoscilloscopewasvaluabletoseethecorrectvoltagesanddelays
werebeinggeneratedintheRSSIandDATAlinesfromthereceiver.Thefunctiongeneratorwasusedto
poweruptheRSSIinsimulatingcontinuousonoffofthetransmitter.Frequencywassetat1Hz(1
actionpersecond)
Phase
1

Setup
WirelessPaironsameprotoboardsharingpower
supplywithMAX232chipconnected.Transmitter
powerlineanddatalinewascontrolledviaDIP
switches.
ConnectionwithLM555timerandLEDmodule
xxi

Results
Correctpowertransmission,
noisydataline.
Oscilloscopeshowed
expectedvoltages.
LEDchangedcolors

wasadded.RCvaluesonLM555wasadjusted
untilproperdelayof10mswasachieved/

correctlywhenDIP
switcheswerechanged
accordingly.
3
Transmitterwastransferredtoanotherprotoboard. Glitchescansometimesbe
Accuracyandrangewastestedbyhaving
seenbecauseDIPswitches
protoboardasfarasthelaboratoryallowed(1020 werenodebounced.
feet)
However,overalltheresults
weresatisfactory.
OscilloscopesnapshotscanbeseenofthephasesinAppendixDfromfigureD.19toD.24
4.1.5LEDAwarenessIndicatorModule
TheLEDawarenessIndicatorModulewaseasytotest.Allwehadtodowasinputthecorrectchange
usingDIPswitches.ThecircuitwaslaterintegratedwiththewirelessmoduleandtheAudiomodule.
Integrationwassimpleandflawless.Thehardestpartwasdebuggingwhensomewirescameoutloose.
Thiswasdonebycarefullyfollowingthelogicdiagramandtracinginputandoutputvalues.Overall,
therewaslittleprobleminimplementingthismodule.
4.1.6AudioModule
Theamplifiercircuitworkedflawlesslyfromtheapplicationnotes.Althoughwetestedaroundwith
changesinresistorvaluesandothercomponents,notmanychangescanbediscernedfromtheaudio
qualityfromthespeaker.Volumewassatisfactory.Thehardestpartoftestingtheaudiomodulewas
predictingtheoutputofthewaveformgenerated.Thiswasdonebytrialanderrorbyreprogrammingthe
PICmultipletimesuntilasatisfiedmelodywasproduced.
4.1.7PowerSupplyModule
WetestedthepowersupplymodulewiththeEEGcircuit.Initialattemptswerefoiledbecausethe
correctDCoffsetcannotbeobtainedwithourinitialdesignofhaving12V,6Vand0Vasthe+5,0and
5powersupplydifferential.Wedecidedtochangeandhaveatrue+5V,groundand5Vproduced
usingtwoseparatepowersupplies.Thisworkedforourneeds.Wefurthertestedtheregulationofthe
voltageregulatorsbyincreasingthepowersupplytothevoltageregulators.Voltageregulationremained
at5Vbutthecomponents(LM317T)gotveryhot.Othercomponentsremainedinworkingorder.
Withoutthevoltageregulatorsthesecomponentswouldhavebeencompletelydestroyedespeciallythe
PICduetohighcurrent.
Powerforeachindividualcomponentwasfoundbyconnectingrelatedcomponentstothepowersupply
andreadingoffthevoltageandcurrentvaluesandbyusingthefollowingequation:
Power=VoltagexCurrent.

(4.1.7.1)

4.2Conclusions
Overall,thetestresultsofprojectwereverysuccessful.Thebrainwavesignalsweresufficiently
amplifiedandfilteredtobereadcorrectlybythePIC.Thebuzzercircuitandbasealarmunitalso
indicatedwhenboththresholdswerecrossedaccuratelyviabuzzers,melodies,andtheLEDawareness
xxii

bar.Thereweresomediscrepancieswithfrequenciesnearthethresholds,howeverifthereisafalse
positiveatthethreshold,thatcanalsobeadvantageoustoalerttheuserheorsheisjuststartingtoget
drowsy.Thesediscrepancieswereduetothelackofabilityofthealgorithmtodealwithnoiseinthe
EEGsignal.Tomakeourproductmoremarketable,theEEGsignalorthealgorithmforthePICcould
beimproved.

5.COST
Thetotalcostofourproductisbasedonthepriceofthepartsusedandthelaborputintoconstructing
thedevice.Adetailedbreakdownofthecostrelatedtothepartsandlaborcanbefoundbelow.
5.1Parts
TableF.1showsthecostassociatedwitheachofthepartsusedinourdevice.Themoduleinwhich
eachpartisutilizedisalsoreflectedinthetable.ThepriceofthepartsusedintheEEGmodulesumsto
$15.77.Thecostofthesignalprocessingunitis$8.95.Thecheapestmodule,thebuzzercircuit,hasa
partscostofonly$6.33.Thewirelessmoduleisbyfarthemostexpensivemodulehasapricetotalof
$301.91.Themajorityofthatsizablecostisfromthewirelessreceiver/transmitterwhichhasapriceof
$300.ThepricesoftheLEDawarenessindicatormoduleandtheaudiomoduleare$9.97and$13.53,
respectively.Andfinally,thetotalcostofthepowersupplymoduleis$7.90.Therewerealso
miscellaneouscostsassociatedwithcircuitboardsandprojectenclosurestotalingto$33.94.Thetotal
costofallthepartsusedinourdevicesumsto$399.78.
5.2Labor
xxiii

Weestimateeachmemberofourgroupworkedonaverageabout10hoursperweekoverthe10weeks
spentontheproject.Thistimespentconductingresearchanddesigningthedeviceinbothindividual
andgroupsettings.Intotal,300hoursofworkwerecompletedduringthecreationofourproduct.We
alsoprojectasalaryof$30perhour($60,000peryear)foreachgroupmember.Usingtheabove
mentionedestimations,theresultingtotalcostoflaboris$22,500.
LaborCost=2.5xHourlySalaryxTotalWorkingHours

(5.1)

TotalCost=PartsCost+LaborCost

(5.2)

Thetotalcostofourprojectis$22,899.78accordingtoEquation5.2.

xxiv

6.ETHICALCONSIDERATIONS
6.1DesignEthics
Asawhole,thisdevicefunctionsinamannerthatcangreatlybenefitsocietythroughthe
preventionoftheinjuries,fatalities,andmonetarylossesthatstemfromfatigueinducedautomobile
accidents.Assuch,therearefewunethicalcircumstancesthatcouldresultfromtheuseofthisdevice.
Probablythegreatestdangeristhatthisdevicewillinstillasenseofoverconfidence.Thatis,people
maychoosetodriveinstatesoffatiguethattheywouldneverhavedaredtowithoutthisdevice.
Althoughourdeviceismeanttokeeppeopleawake,itcannotsubstituteforthephysiological
requirementofsleep.Consequentially,usersthatchosetodriveinstateofsignificantfatigue
(constantlyfallingasleep)willputboththemselvesandotherdriverssharingtheroadwiththeuserat
risk.Thatis,regardlessofthevolumeofthedevicessalarms,averyfatigueduserisunlikelytobe
wokenupinthefewsecondsbetweenthestartofsleepandwhenacrashoccurs.Also,ourproduct,like
allothertechnology,willinevitablyfailatsomepointduetoeitherusererrorordevicemalfunction.
Andsinceourproductservesasasafetydevice,failurewillputthetrustinguserinseriousdanger.

xxv

7.CONCLUSIONS
Overall,theprojectwasasuccessandalloftheobjectivesstatedinthedesignreviewweremet.
Specificgoalsachievedwereaclean,singlechannelEEGusingminimalcircuitrytokeepthedevice
portable,algorithmsadaptedspecificallyforEEGfrequencydetection,asequenceofbuzzerstoawake
theuser,wirelesscommunicationtoawirelessbasealarmunitwithLEDawarenessbar,andmelody
production.Wewerealsoabletomakethedevicecompletelyportable,operatingonlyonbattery
power.
Inadditionthesuccessofourproject,thereareareasthatcanbeimprovedupontoimprovetheoverall
qualityoftheproduct.Asexpected,theEEGsignalwasgreatlysubjecttonoiseduetoDCoffsetsand
highfrequencynoise.MorefilteringatdifferentplacesintheEEGcircuitcouldhaveimprovedthis;
however,thedrawbacksincludemorespaceneededonthecircuitboardaswellasgreaterpowerdrain.
Anotheralterationthatmayhavebeenabletoaidinthisproblemisaddingmoreelectrodes.MostEEGs
havemultiplechannelswithelectrodesplacedallaroundthehead.Thiscouldhaveledtoasharper
EEG;however,thiswouldaddcomplexitytocircuitandbemuchmoreofanannoyancetotheuser.
Overall,wearehappywiththesuccessoftheEEGmoduleallowingforaveryconvenientdesign.
AnotherchallengefacedwastheissueofthePICalternatingawarenesslevelsatthemeasurement
threshold.ThiswasanissuewithboththeEEGandfunctiongeneratorconnected.Sourcesofthis
problemcouldhavebeenanomaliesinthealgorithmornoiseinthereceivedsignal.Theseproblems
couldbepossiblyalleviatedbyimprovingthealgorithmorbeimprovingthesignalconditioninginthe
circuit.However,thisisnotthatbadofaproblembecauseiftheuserisapproachingthethreshold,heor
sheshouldbeawareofthis.
WewouldhavealsolikedtohavetranslatedtheentireprojectontoPCBs,howeverwedidnotforafew
reasons.Themainreasonwastheissueofmakingthedeviceportable.Itwaspresumedthattheways
thesignalwasconditionedintheEEGmayneedtochangewhenhookedupthebattery,whichwastrue.
Thiswouldhavebeenextremelydifficulttoadjustresistorandcapacitorvalueswhentheyneedtobe
soldered.
Ourcostwasrelativelyhigh;however,thiscouldbeveryeasilyreduced.Themajorityofthecostofour
projectwasthe300dollarwirelesstransmitterandreceiver.Forourwirelesstransmission,allwe
requireisthetransmissionofonebit.Becauseofthis,wecoulduseamuchmoreaffordablewireless
module,thusreducingtheexpenseofthedevice.
Anotherissuethatcouldbeeasilyimproveduponwasthebatterylife.Currentlyourdeviceisusing9V
batteriestopowerbothcircuitswhichwouldprovideforabout2hoursforbothunits.Thismaynotbe
longenoughforanentirelongdrive.Thiscouldeasilybeimproveduponbyusingfour1.5Vbatteries
inseriesinsteadofa9V.Also,becauseourcircuitusesvoltageregulators,itcanhandleany
combinationofbatteriessolongasthevoltageisabove5V.

xxvi

TheprojectprovedthatdesigninganEEGsleepdetectorisfeasibleandwithintherealmofpossibility
ofproduction.Withimprovementinafewcertainareas,themarketabilityoftheproductcanbe
increasedsignificantly.Thisproductcouldbeverybeneficialtosocietyandweareverypleasedtohave
achievedallofourobjectivesinthedesignprocess.

xxvii

REFERENCES
[1]

NYSDepartmentofMotorVehiclesTrafficSafetyCommittee,DrowsyDrivingandFatigue,
July2006,http://www.nysgtsc.state.ny.us/drowndx.htm.

[2]

RobertD.OgilvieandJohnR.Harsh,SleepOnset.NewYork:AmericanPsychological
Association,1994.

[3]

Mitsuaki Yamamoto,NightdaynightSleepWakefulnessMonitoringbyAmbulatory
IntegratedCircuitMemories.Boston:PsychiatryandClinicalNeurosciences,1999.

[4]SleepComputingCommitteeoftheJapaneseSocietyofSleepResearchSociety(JSSR),
ProposedsupplementsandamendmentstoAManualofStandardizedTerminology,
TechniquesandScoringSystemforSleepStagesofHumanSubjects,theRechtschaffen&
Kales(1968)standard,PsychiatryandClinicalNeurosciences(2001),55,305310.
[5] E.HuupponenIet.Al.,Automaticanalysisofelectroencephalogramsleepspindlefrequency
throughoutthenight,Med.Biol.Eng.Comput.,2003,41,727732.
[6]

Webster,JohnG.Bioinstrumentation.Hoboken,NJ:JohnWiley&Sons,Inc.1994.

[7]

InstrumentationAmplifier.NationalSemiconductor:LinearBrief.March1969,
http://www.national.com/ms/LB/LB1.pdf.

[8]

eCircuitCenter,CommonModeRejection(CMR).January2006,
http://www.ecircuitcenter.com/OpModels/CMR/Op3_CMR.htm.

xxviii

Potrebbero piacerti anche