Docsity

No Doze EEG Sleep Detector - Lecture Notes | ECE 445, Study Guides, Projects, Research of Electrical and Electronics Engineering

Partial preview of the text

Download No Doze EEG Sleep Detector - Lecture Notes | ECE 445 and more Study Guides, Projects, Research Electrical and Electronics Engineering in PDF only on Docsity!

No Doze EEG Sleep Detector

Created by: Benjamin Schneider David Mahr Kuang Tan ECE 445, SENIOR DESIGN PROJECT FALL 2006 TA: Hyesun Park December 5, 2006 Project No. 9

ABSTRACT

An appreciable difference exists between brainwaves of a person that is awake and a person that is on the verge of sleep. As a person transitions from alertness to sleep, the alpha rhythms of his/her brainwaves decrease in frequency, diminish in amplitude, and become more irregular in frequency. These brainwave changes can be sensed using an electroencephalogram (EEG). We developed a device that will recognize the shift from wakefulness to sleep, via recognition of the frequency of the EEG signal, and then relay that information wirelessly to an alarm system. The alarm system will visually display the awareness level of the user and provide audio alerts when the user is drowsy or has falling asleep. ii

    1. INTRODUCTION....................................................................................................................
    • 1.1 Purpose...............................................................................................................................
    • 1.2 Specifications......................................................................................................................
    • 1.3 Subprojects.........................................................................................................................
      • 1.3.5 LED Awareness Indicator Module............................................................................ 1.3.4 Wireless Communication Module........................Error: Reference source not found
      • 1.3.6 Audio Module............................................................................................................
      • 1.3.7 Power Supply Module...............................................................................................
    1. DESIGN PROCEDURE...........................................................................................................
    • 2.1 EEG Module Design...........................................................................................................
    • 2.2 Signal Processing Module Design......................................................................................
    • 2.3 Buzzer Module Design.......................................................................................................
    • 2.4 Wireless Module................................................................................................................
    • 2.5 LED Awareness Indicator Module Design.........................................................................
    • 2.6 Audio Module.....................................................................................................................
    • 2.7 Power Supply Design.........................................................................................................
    1. DESIGN DETAILS..................................................................................................................
    • 3.1 EEG Module.......................................................................................................................
    • 3.2 Signal Processing Module..................................................................................................
    • 3.3 Buzzer Module....................................................................................................................
    • 3.4 Wireless Module................................................................................................................
    • 3.5 LED Awareness Indicator Module...................................................................................
    • 3.6 Audio Module...................................................................................................................
    • 3.7 Power Supply....................................................................................................................
    • 4.1 Testing.............................................................................................................................. 4. DESIGN VERIFICATION.............................................. 13 Error: Reference source not found
      • 4.1.1 EEG Module
      • 4.1.2 Signal Processing Module.......................................................................................
      • 4.1.3 Buzzer Module........................................................................................................
      • 4.1.4 Wireless Module......................................................................................................
      • 4.1.5 LED Awareness Indicator Module..........................................................................
      • 4.1.6 Audio Module..........................................................................................................
      • 4.1.7 Power Supply Module.............................................................................................
    • 4.2 Conclusions.......................................................................................................................
    1. COST......................................................................................................................................
    • 5.1 Parts..................................................................................................................................
    • 5.2 Labor.................................................................................................................................
    1. ETHICAL CONSIDERATIONS............................................................................................
    • 6.1 Device Ethics....................................................................................................................
    1. CONCLUSIONS....................................................................................................................
    • REFERENCES.......................................................................................................................
  • APPENDIX A – BLOCK DIAGRAMS.................................................................................
  • APPENDIX B – SCHEMATICS............................................................................................
  • APPENDIX C – FLOW DIAGRAMS...................................................................................
  • APPENDIX D – SIMULATIONS & TEST DATA...............................................................
  • APPENDIX E – PICTURES..................................................................................................
  • APPENDIX F – PARTS AND COST....................................................................................
  • APPENDIX G – MISCELLANOUS......................................................................................
  • APPENDIX H – PIC CODE...................................................................................................
1. INTRODUCTION

An EEG collects brainwaves by measuring the voltage differentials across the scalp. These brainwaves vary in frequency and amplitude and fall into four main categories: alpha, beta, delta, and theta. The type of brainwave, which is based mainly on frequency, is indicative of a person’s level of awareness (see Table G.1). We created a device that monitors the frequency of a user’s brainwaves, and alarms the user (and using both visual and audio alerts) when the user’s brainwaves decrease in frequency to a point that is indicative of drowsiness or sleep. This process is accomplished through the use of an EEG, a signal processing module, a wireless transmission unit, and alarm circuits. The EEG provides the signal processing PIC with the brainwave signal. The PIC then calculates the EEG signal’s frequency, determines the user’s awareness level, and outputs accordingly. The PIC outputs are then relayed wirelessly to the audio and visual alarm units. 1.1 Purpose Our goal in creating this product was to develop a life saving device that will alert drivers that are drowsy or have fallen asleep. Fatigue exists as the direct cause of approximately hundred thousand crashes in the United States each year. Additionally, drowsiness is a major contributor to driver inattention: the cause of one million crashes annually, or one-sixth of all crashes. These automobile accidents result in fifteen hundred fatalities, seventy-one thousand injuries, and twelve and one half billion dollars in monetary losses [1]. Even with this magnitude of loss, no effective sleep detector for drivers is currently available on the market. We chose this project because a device that could prevent these tragic physical damages and financial losses associated with fatigue related automobile accidents would be very beneficial to the welfare of our society. 1.2 Specifications The main specification of our device is that the user must be alerted within one second of the occurrence of sleep. To accomplish this feat, several specifications were set for each module. The EEG module must amplify the microvolt brainwave signal to provide the signal processing PIC with an input signal of at least 1V peak-to-peak and a maximum of 10V peak-to-peak (0.5V – 5 V in amplitude). The EEG module must also eliminate any DC bias in the brainwave signal, and filter out any signal with a frequency outside the range of 1 to 40 Hz. Also, the EEG module must be supplied by +5V and -6V. The signal processing, buzzer, wireless, LED awareness indicator, and audio modules must be supplied by +5V. The PIC microcontrollers in the signal processing and audio modules must not source or sink more than 25mA. The buzzer circuit must have three distinct volume levels in which the module progresses through (separated by 1.5s). The RSSI signal of the wireless module has to be at least 3.85 V (for the LED circuit to function). Also, the communication between the transmitter and receiver in the wireless module must have a range of at least 6 ft.

1.3 Subprojects.........................................................................................................................

Our project is divided into several subprojects which each perform specific task (see Figure A.1):

2.1 EEG Module Design...........................................................................................................

The EEG module amplifies brainwaves via the differential voltage measured on the scalp by electrodes on the forehead. The EEG circuit should amplify the brainwave signal to at least 1 V peak-to-peak and sufficiently filter out frequencies 2.38 to 39.38 Hz. A favorable SNR ratio also needs to be maintained throughout the amplification process. v

2. DESIGN PROCEDURE

4.1.1 EEG Module

The function of the EEG module was to successfully acquire brainwaves signals, sufficiently amplify the signal and filter out extraneous noise. This is an essential component of the project as this signal will be used to determine the awareness of the subject. Disposable Ag/AgCl electrodes were used on the scalp and placed on the right and left side of the forehead (E.3). An additional electrode was placed on the neck to act as a ground. 5.1kΩ resistors were also placed in series with the electrodes in order to protect the user from the circuit [6]. To initially amplify the signal, instrumentation amplifiers were used. An instrumentation amplifier is a specific type of differential amplifier used to measure small voltage differentials of the inputs while attenuating common inputs [7]. Instrumentation amplifiers are more advantageous to use over operational amplifiers as they are specifically designed to have low DC offset, low drift, low noise, and high common-mode rejection ratio. The AD620BNZ instrumentation amplifier from Analog Devices was chosen because it was rated high in these areas. High-pass and low-pass filters were used to attenuate undesirable noise. Noise that was of most concern was DC offsets and 60 Hz noise. DC offsets can occur due to shifting of the electrode wires or the dipole present in the eye [6]. 60 Hz noise is due primarily to power lines. Both active and passive high- pass filters were used to filter out DC offsets. The advantages we found to using active filters were that they have sharper cut-offs, are less subject to feedback, act as a buffer to the circuit and also proved to respond quicker to spontaneous DC offsets. Passive high-pass filters were made using only resistors and capacitors, while active high-filters were made using operational amplifiers in addition to resistors and capacitors. For the low-pass filter, we used the MF6CN-50, which is an active 6th^ order low-pass filter designed by National Semiconductor. 2.2 Signal Processing Module Design The main objectives of the signal processing module are to determine the frequency of the EEG signal, classify that frequency as a specific awareness level, and then output based on the user’s awareness state. The module has one input and four outputs. The single input is an analog AC voltage signal supplied by the EEG circuit. This input signal should have an amplitude between 0 and 5V, zero DC offset, and be properly filtered to only include frequencies between 1 and 40 Hz. Upon reaching the signal processing module, the input signal will pass through a half-wave rectifier to eliminate negative voltages in the signal. This module has two digital output signals to the wireless module, Transmitter_Power and Sleep_Indicator, and another two digital output signals to the buzzer circuit, Buzzer0 and Buzzer1. These outputs depend on the current and previous awareness states of the user. The user’s awareness level is based on the frequency of the EEG signal. If the frequency is greater than 12 Hz, the user is highly alert. If the frequency is between 8 Hz and 12 Hz, the user has a low awareness. And finally, if the frequency is less than 8 Hz, the user is sleeping. Using the above mentioned frequency based awareness divisions, the signal processing module determines the frequency of the input signal, and then assigns an awareness level based on that frequency. Subsequently, the user’s previous and current awareness levels are compared, and the module outputs based on that comparison. That is, if the previous awareness level is higher than the current awareness level, a decrease in awareness level has occurred, and the module will output a high Transmitter_Power output (to power up the transmitter) and a low Sleep_Indicator output (to signal a downward transition). Conversely, if the previous awareness level is lower than the current awareness level, an increase in awareness takes place, and the module will output a high signals for both the Transmitter_Power and vii

Sleep_Indicator outputs. If the current and previous awareness states are equal, both of these outputs will be low. As far as the Buzzer0 and Buzzer1 outputs are concerned, as long as the new awareness state is not sleeping, both of these outputs will be low. However, if the state transitions to sleep, the module will output ‘01’ for Buzzer1 and Buzzer0, respectively. If the new state continues to be sleeping after 1.5s, these output signals will switch to ’10’. If sleeping persists for another 1.5s, Buzzer0 and Buzzer1 will transition so that both outputs are high signals. These high output signals will continue for both Buzzer0 and Buzzer1 until the new state is not sleeping. In order for our device to properly function as a sleep detector, it is imperative for the frequency analysis of the EEG signal to be accurate. After researching the possible options for this task (analog circuits, microcontrollers, digital signal processing chips), we decided that based on the functionality, low cost, and relatively low complexity, the PIC16F877A would be best suited for our project. After selecting the PIC as our frequency analysis tool, we went through a series of possible algorithms before finding the most accurate code for determining the EEG input’s frequency. In our first algorithm, the average value of the EEG signal was computed over 256 ms. Then the number of times the signal crosses that average value was counted over the next 500 ms. The frequency of the signal could then be calculated according to the equation: Number of Zero Crossings Frequency = 2 * Time Interval

where the ‘Number of Zero Crossings’ is equal to the count of transitions across the average value, and ‘Time Interval’ is equal to the amount of time the transitions are counted. And since, ‘Time Interval’ is equal to 500 ms, the equation reduces to: Frequency = Number of Zero Crossings. (2.2.2) However, we found voltage spikes in the EEG signal resulted in an average value that was greater than a majority of the input waveform. This high average resulted in fictitiously low frequency readings. Since this algorithm could not provide an accurate frequency reading, we developed a new algorithm. In our second algorithm, the number positive peaks in the input signal were counted. That is, the number of times the inputs at time (t) and (t+2) were less than the input at time (t+1) were tallied. The frequency of the signal was then described by the equation: Frequency = 2 * Number of Positive Peaks (2.2.3) where the peaks are summed over 500 ms. However, noise at low frequencies led to additional peaks in the input signal. These extra peaks resulted in fictitiously high frequency readings. Again, since our algorithm could not correctly provide the frequency of the input signal, we developed a new algorithm. In our third, and final, algorithm, the number of transitions to zero that occurred in the input signal are counted. That is, the number of times the input signal goes from a positive value to a zero value are added up. The frequency of the input is then described by the equation Frequency = 2 * Number of Zero Transitions (2.2.4) where the number of falling edges are counted over 500 ms. This algorithm is able to provide consistently accurate frequency analysis, and conduct the analysis with the second allotted in the design specifications, and thus, we selected to use it as the code for our device. viii

2.6 Audio Module.....................................................................................................................

The audio module was initially not included in the first design. It was added on because our further research showed that audio stimuli plays an important role in alerting a user from sleep. The audio cues implemented in our design include a start up melody, a warning melody, and a danger siren. Inspired by the workings of the Theremin, the design was implemented by using a variable frequency oscillator. This variable oscillator was implemented through the use of a microcontroller with various delays between “high” and “low” outputs. The microcontroller output is then amplified (gain of 200) to produce audio via a speaker. This design was implemented using a PIC16F877A from MICROCHIP, a 5MHz oscillator, and an LM386N, a low voltage audio power amplifier. It receives input from the LED logic module, and outputs a 0.1KHz and 2KHz variable frequency melody on cue.

2.7 Power Supply Design.........................................................................................................

The main functionality of the power supply design was to produce stable voltage regulation from portable power supply sources like AA or AAA batteries or from 9volt batteries. This module provides +5V and -6V to the head set unit, and +5V to the base alarm unit. By using the LM 317T 3-Terminal Adjustable Regulator from National Semiconductor, many of our requirements were fulfilled easily. LM317T has a guaranteed output of 1.5A, current limit constant with temperature, and the output is protected from short circuit. By using two LM317T +5V power supplies were created on the headset and base alarm unit. Later on, since the op-amps require a -6V lead relative to ground, the LM7905 3-Terminal Negative Regulator from National Semiconductor was added to regulate -6V to the headset unit. This device also has the same safety features as the LM317T. x

3. DESIGN DETAILS

3.1 EEG Module.......................................................................................................................

The purpose of the EEG was to amplify the brainwave signal within 1 Vpp in order to be processed by the PIC. Because brainwaves measured on the scalp are on the order of 10 uV, we chose to amplify by a gain of approximately 122,000 [6]. Each instrumentation amplifier has a max gain of 10,000, thus we chose to operate two instrumentation amplifiers in series. The gain on each instrumentation amplifier is determined by adjusting the value of a resister across pins 1 and 8 on the chip as can be seen in Figure B.2. Equations 3.1.1 and 3.1.2 show how the gain is calculated via the resistor value. Because the two instrumentation amplifiers are placed in series, the total gain is the calculated by the product of each individual amplifier gain. Equation 3.1.3 shows the total gain.

1 g [ ] k G R

49.4[ ]
[ ]

g k R G

1

k G

2

k G k k

GtotalG 1  G 2 (4941)(24.656) 121,825 (^) (3.1.3) Passive high-pass filters were placed directly before the input into the first instrumentation amplifier. These passive high-pass filters were built using resistors and capacitors and had a cutoff frequency of 0.34 Hz (Fig B.1). The purpose of these filters was to eliminate any DC offset before amplification. The equation used to determine the resistor and capacitance values is shown in Equation 3.1.4. Two active 2nd^ order high-pass filters were used directly after the output of each instrumentation amplifier. These active high-pass filters were built using operational amplifiers in addition to resistors and capacitors and had a cutoff of 2.34 Hz (Fig B.1). The purpose of these filters was to eliminate DC offset that had been improperly amplified by the instrumentation amplifier. The equation used to determine the resistor and capacitor values for this filter is shown in Equation 3.1.5. 1 [ ] 2 [ ] [ ] f HzR C F

HzMF

1 2 1 2

[ ]

f HzR R C C

Hzk kFF

xi

Using the ADC samples, the number of times the input transitions from positive to zero is counted over a 500 ms time interval. The PIC then assigns the awareness state and compares the old and new awareness levels. This process takes old microseconds due to the high frequency of the external oscillator. The PIC then outputs based on the current and previous awareness states. This process has a maximum delay of 100 ms. Therefore, one entire cycle takes only about 600 ms – a value that is well below the design specification of 1 second.

3.3 Buzzer Module....................................................................................................................

The buzzer module consists of two MCP320B2 Mallory Sonalert 6VDC piezo-buzzers, three 1KΩ resistors, and a Phillips Semiconductor HCT4052 4:1 multiplexor. The complete schematic for the buzzer module can be seen in Figure B.4. The three 1KΩ resistors are placed in series with +5V voltage source to set up a simple voltage divider. The node before the first resistor, the node after the first resistor, the node after the second resistor, and the grounded node are connected to pins 4, 5, 2, and 1, respectively (or mux inputs 3, 2, 1, and 0, respectively). The output of the multiplexer is then connected to the buzzers. The possible voltage levels available to the buzzer are described by the following equation: Vin = Vtotal * (Req/RT) (3.3.1) yielding 5V, 3.33V, 1.67V, and 0V as the input voltages to mux inputs 3, 2, 1, and 0, respectively. Since the volume of the buzzer depends on the voltage available, this setup allows this module to have 3 distinct alarm volumes and a silent state.

3.4 Wireless Module................................................................................................................

Our wireless module was built with the readily available HP3 Linx Transmitter/Receiver RF pair. This design was fairly straightforward after consulting application notes from the Linx HP3 documentation. Other IC components include in this design is the MAX232 component and the LM555 component. How these components are connected can be seen from the schematics in figure B.5. Basically, the PIC in the headset unit controls the power down line of the transmitter as well as the data line. Whenever an instruction is made to change the status of the LED by transmitting a low or high signal through the data line, the transmitter will need to be powered up. On the receiver side, two outputs are considered essential; the RSSI line, and the data line. The RSSI line transmits the clock flag signal and the data line transmits the sleep indicator bit. The power down line requires at least 3V to power on the transmitter and has a turn on time of 10ms. When the transmitter is turned off, the receiver has an internal high pull on the data line. On the receiver side, a high or low value of the data pin is obtained relatively to the power supply (+5V). This is created by using a MAX232 component. The MAX232 component is basically an inverter connected to a Vcc of 5V. By passing it through twice, a level voltage of 5-10V is obtained. As mentioned before, the transmitter has a delay of about 10ms. During this delay, the transmitter encounters noise during transmission. Therefore, a resistor-capacitor IC (LM555) is used to make sure the LED logic circuit receives both sleep indicator bit and the clock flag signal (RSSI) bit at the same time and the noise is bypassed. The equation governing the delay generated by the LM555 IC is as follows. T = 1.1 RA C (3.4.1) In this case, a resistor value of 10kΩ and a capacitor value of 1μF was used to generate a delay of approximately 11ms. This bypasses the noise created during the power up of the transmitter. The output xiii

voltage is 2/3 of the Vcc voltage. The timing interval is independent of voltage supply. Application design is obtained courtesy of National Semiconductor. The output of LM555 goes to the clock flag pin on the D-flipflop in the LED module, and the sleep indicator bit goes to the responding gate inputs on the LED module. A flow diagram of the whole process can be seen from figure C.1 and C.2. The Linx HP3 series chip uses an FSK transmission scheme to send data over the airwaves. There was a very detailed talk about antenna design and placement given in the Linx documentation. However, for the short distances that we were planning on transmitting (less than 10 ft.) we could use almost any antenna we wanted to. In the end we ended up using an external antenna on the base alarm unit and none on the headset unit. Transmission worked flawlessly. 3.5 LED Awareness Indicator Module The LED module design was simple to design. By controlling the inputs to the LED, and accurate timing, the whole process can be simplified to a 2 state diagram. We implemented this design by using a combination of 4 gate ICs. The gates used are OR gates, AND gates, NAND gates and D-FlipFlops. The respective chips are 74F08PC quad 2-Input And Gate, SN74LS74AN dual d-type positive-edge- triggered flip-flops with preset and clear, SN74F00 quad 2-input positive-NAND gates, and SN74LS Quad 2-input positive-OR gates. The LED used is the HLMP-4000 bi-color LED lamps. It features three leads with a common cathode and comes with a diffused wide visibility lens. A schematic can be seen in figure B.6. The circuit requires only a +5V power supply. For our design, 3 colors are used to indicate user awareness: Red Sleeping Yellow Normal/ High awareness Orange Low awareness Table 3.5.1 – Colors indicating user awareness. LED has three leads with one as common cathode. Maintaining a high on red and yellow leads creates the color orange. The logic behind the LED color changes is as follows: Action (Sleep indicator) Previous Color Following Color High Yellow Yellow High Orange Yellow High Red Orange Low Yellow Orange Low Orange Red Low Red Red Table 3.5.2 – Sleep indicator moderation of LED colors based on previous user state To signify change of LED status, the clock flag signal (which is controlled by the power on of the transmitter) changes to high, then to a low, the positive edge triggered D-flipflops will transmit the new state to its outputs, and thus altering the color of the LED. Thus, the K-map equation generated is as follows. Red RY’ + A’Y + RA’ Yellow R’ + A Table 3.5.3 – K-Map equation for Red and Yellow leads of the LED. ‘R’ being the previous pin to the red LED lead and ‘Y’ being the previous pin to the yellow LED lead. ‘A’ is the sleep indicator bit. xiv

As seen in Figure B.8, the divider resistor is actually the combination of R 1 and R 2. This allows us to adjust the output voltage to exactly 5.00 volts above ground. As such, the resistor values of 300 Ω and 900Ω was used. The power supply took an unregulated 9-volt DC signal from a battery as input. It used this signal to power the voltage regulators that took the voltage from 7 volts to 5.00 volts. Due to this voltage drop across the regulator, the power not sent to the output terminals was dissipated as heat through the regulator. If the voltage to power up these components is marginally higher, heat sinks will have to be attached to the metal pins behind these components to dissipate heat. The application design is obtained courtesy of National Semiconductor. The LM7905 component circuit is straightforward in design and required little external components as shown in figure B.9. It is packaged in a T0-220 power package. The power supply to the component is a 9V DC signal from a battery flipped in polarity. The total power supply used by the base alarm unit and the headset unit is about 2W. (Table G.2 in appendix) This translates to roughly about 2 hours running on a 280mAH 9V battery or 10-15 hours running on 4 AAA batteries rated at 2000mAH in the worst case scenario (danger siren on).

4. DESIGN VERIFICATION xvi

We went through a series of tests to ensure our device was working properly. Since low awareness and sleep of a user cannot be instantaneously achieved, we needed to find an alternate method of testing our device. We decided the best testing method would be to supply a sinusoidal waveform from a function generator to the input of the EEG circuit. However, the lowest amplitude output of the function generator is 1mV and we required a signal in the range of tens of microvolts to properly simulate brainwaves. To solve this problem, we added an amplifier with a gain of 1/100 to the beginning of the EEG circuit. With the additional amplifier in place, we inputted the function generator output to the EEG circuit, and monitored the amplified output of the EEG circuit on an oscilloscope. We then fed the EEG output into the single processing circuit. Varying the frequency of the function generator signal, we observed the outputs of the buzzer, audio, and LED awareness indicator modules to determine the level of functionality of the device. 4.1 Testing Each of the modules making up our project were first tested individually to ensure correct functionality. That is, each module was tested to verify design specifications were met. Then, modules were integrated together and the resulting product was tested for functionality. The tests performed on each module are detailed below. 4.1.1 EEG Module Features tested in the EEG module include the gain and CMRR of the instrumentation amplifiers, frequency responses of filters, and overall functionality of the EEG to acquire brainwave signals. To examine the actual gain of the circuit, the actual gain of each instrumentation amplifier was determined by taking the ratio of output voltage to input voltage (Eq. 4.1.1.1). Using a 1 mVpp sine wave as an input into the first instrumentation amplifier with theoretical gain of 4941, a 4.93 Vpp sine wave was output (Fig D.1). This results in an actual gain of 4930 which is slightly less than the theoretical value. For the second instrumentation amplifier with theoretical gain of 24.656, a 0.1 Vpp sine wave was input and a 2.75 Vpp sine wave was output (Fig D.2). This results in an actual gain of 27.5 which is slightly higher than the theoretical value. These deviations from the theoretical value could be a result of inconsistencies in the actual resistor values or possible fluctuations in the output of the function generator. At any rate, the actual gain of the entire circuit can be calculated as 135,575, which is still sufficient for its purpose. in out actual V

V
G  (4.1.1.1)

The Common-mode rejection ratio (CMRR) of an instrumentation amplifier measures the tendency of the device to reject input signals common to both input leads [8]. A high CMRR determines the effectiveness of an instrumentation amplifier and is especially important when measuring very small voltage differentials. The CMRR can be calculated by Equation 4.1.1.2. 20 log 10 d s

A
CMRR
A

       

Ad =Differential Gain, As =Common-mode Gain To test this, the inputs are shorted and the output is determines the common-mode gain. The differential gain is the actual gain of each amplifier. For the first amplifier with actual gain of 4930, the common- mode gain was determined as 0.2. Thus, the calculated CMRR was 87.83dB which is a very good value xvii

The design specifications for the signal processing module dictate that the Transmitter_Power output should be high for all transitions in awareness levels, the Sleep_Indicator output should be high for increases in awareness levels and low for decreases in awareness levels, and that both outputs should be low if no transition occurs. Also, the specifications call for the Buzzer1 and Buzzer0 outputs to be low for all states expect the sleep state, and during the sleep state these outputs should progress from ‘01’ to ‘10’ and finally to ‘11’ (changes separated by 1.5 seconds). Since the awareness level of the user is based solely on the frequency of the user, varying the input frequency is necessary to test the functionality of the signal processing module. The frequencies of interest, or threshold frequencies, are 8 Hz and 12 Hz. This is the case since a frequency of greater than 12 Hz is indicative of high awareness, between 8 and 12 Hz is indicative of low awareness, and less than 8 Hz is indicative of sleep. The first test conducted on the signal processing module involved providing a 1Vpp sinusoidal AC signal with zero DC offset directly to the EEG signal input of the PIC. LEDs were placed in series with the resistors connected to the outputs of the PIC. As such, a high output would cause the LED to light up, while a low output would elicit no change in the LED. The frequency of the input signal was slowly decreased from 20 Hz to 1 Hz and the outputs of the PIC were monitored via the LEDs. The PIC performed as expected except for an alternation in awareness state at the threshold frequencies. This alternation was obvious as the Transmitter_Power and Sleep_Indicator output constantly switched from high to low. The results of this test can be seen in Figure D.13. This indecision at threshold frequencies persisted in each of the three algorithms used for the PIC. This persistence suggests that the problem is not code related, but is most likely due to noise within the PIC. This noise may be minimized by using a higher quality microprocessor. However, the alternation in output values, from 13.3 Hz to 11.6 Hz and from 8.3 Hz to 7.2 Hz, is not necessarily a bad occurrence it results in informing the user slightly before the dangerous states of low awareness and sleep are reached. Also, the PIC performance was tested with different input voltage amplitude. The PIC performed in the same manner for input signal voltage amplitudes ranging from 0.5 Vpp to 8 Vpp. This result suggests that the 1 Vpp signal provided by the EEG module is adequate for correct functionality. The second test involved providing the PIC with the output of the EEG module. In this test, the EEG circuit was provided with 0.001 Vpp AC sinusoidal signal from the function generator. The frequency of the input signal was then decreased slowly and the PIC outputs were monitored via LEDs. The PIC appeared to perform well at higher frequencies, but had some erroroneous outputs at frequencies below 10 Hz. Specifically, the PIC did not send an output reflecting a decrease in awareness until about 5 Hz (instead of 8 Hz). By monitoring the PIC input on the oscilloscope, we found that high frequency noise enters the input at lower frequencies. The difference in the quality of the input between high and low frequencies can be seen in Figures D.17 and D.18, respectively. It appeared that the extra peaks arising from the noise were falling to zero at points resulting in fictitiously high frequency readings. We then increased the amplitude of the input signal to 0.004 Vpp and the extra zero transitions were eliminated. The PIC then performed as the specifications dictate (expect for the alternation in outputs around threshold frequencies discussed above). 4.1.3 Buzzer Module The design specifications of the buzzer module call for three distinct volume levels and a silent state based on the select inputs from the signal processing module. The functionality of this module was tested in three manners. In the first test, all combinations of select inputs were provided by direct connections to +5V voltage source and/or ground. The buzzer circuit performed as expected with silence for ‘00’ for the select inputs, lowest volume for ‘01’ inputs, medium volume for ‘10’ inputs, and highest volume for ‘11’ inputs. In the next test, the PIC was provided with a 1 Vpp AC sinusoidal input xix

with a frequency below 8 Hz. As dictated in the design specifications the buzzer module went through a progression of low, medium, and high volume alarms separated by 1.5 seconds. As expected, the buzzer module continued with the highest volume alarm until the frequency of the input was increased to a value greater than 8 Hz. Finally, the buzzer circuit was tested by providing a .004Vpp AC sinusoidal signal with a frequency below 8 Hz to the EEG circuit. The buzzer circuit performed as expected going through the progression of volumes and remaining at the highest volume until the input frequency was increased to greater than 8 Hz. 4.1.4 Wireless Module The main concern with testing of the wireless module was the range as well as the correct LED color change. Testing was done in phases to ensure proper integration with the signal processing module and LED awareness indicator module. The oscilloscope was valuable to see the correct voltages and delays were being generated in the RSSI and DATA lines from the receiver. The function generator was used to power up the RSSI in simulating continuous on-off of the transmitter. Frequency was set at 1Hz ( action per second) Phase Setup Results 1 Wireless Pair on same protoboard sharing power supply with MAX232 chip connected. Transmitter power line and data line was controlled via DIP switches. Correct power transmission, noisy data line. Oscilloscope showed expected voltages. 2 Connection with LM555 timer and LED module was added. RC values on LM555 was adjusted until proper delay of 10ms was achieved/ LED changed colors correctly when DIP switches were changed accordingly. 3 Transmitter was transferred to another protoboard. Accuracy and range was tested by having protoboard as far as the laboratory allowed (10- feet) Glitches can sometimes be seen because DIP switches were no debounced. However, overall the results were satisfactory. Oscilloscope snapshots can be seen of the phases in Appendix D from figure D.19 to D. 4.1.5 LED Awareness Indicator Module The LED awareness Indicator Module was easy to test. All we had to do was input the correct change using DIP switches. The circuit was later integrated with the wireless module and the Audio module. Integration was simple and flawless. The hardest part was debugging when some wires came out loose. This was done by carefully following the logic diagram and tracing input and output values. Overall, there was little problem in implementing this module. 4.1.6 Audio Module The amplifier circuit worked flawlessly from the application notes. Although we tested around with changes in resistor values and other components, not many changes can be discerned from the audio quality from the speaker. Volume was satisfactory. The hardest part of testing the audio module was predicting the output of the waveform generated. This was done by trial and error by reprogramming the PIC multiple times until a satisfied melody was produced.

4.1.7 Power Supply Module.............................................................................................

xx