emv detector final report

39
Final Report EMERGENCY VEHICLE DETECTOR ECE4007 Senior Design Project Section L03, EMV Detection Team Ehren Bendler Tyler Evans Jose Crespo Richard Yee

Upload: sivar22

Post on 09-Apr-2015

144 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: EMV Detector Final Report

Final Report

EMERGENCY VEHICLE DETECTOR

ECE4007 Senior Design Project

Section L03, EMV Detection Team

Ehren BendlerTyler EvansJose CrespoRichard Yee

Submitted

December 9, 2008

Page 2: EMV Detector Final Report

TABLE OF CONTENTS

EXECUTIVE SUMMARY..........................................................................................................iii

1. INTRODUCTION.................................................................................................................1

1.1 Objective..........................................................................................................................1

1.2 Motivation........................................................................................................................1

1.3 Background......................................................................................................................2

2. PROJECT DESCRIPTION AND GOALS.........................................................................3

3. TECHNICAL SPECIFICATIONS......................................................................................4

4. DESIGN APPROACH AND DETAILS..............................................................................5

4.1 Design Approach.............................................................................................................5

4.2 Codes and Standards........................................................................................................8

4.3 Constraints, Alternatives, and Tradeoffs.........................................................................9

5. SCHEDULE, TASKS, AND MILESTONES....................................................................10

6. PROJECT DEMONSTRATION.......................................................................................12

7. MARKETING AND COST ANALYSIS...........................................................................13

7.1 Marketing Analysis........................................................................................................13

7.2 Cost Analysis.................................................................................................................14

8. SUMMARY AND CONCLUSIONS..................................................................................14

9. REFERENCES....................................................................................................................16

Appendix A: EMV Detector MATLAB Source Code..............................................................18

Appendix B: PSoC LED Controller Source Code....................................................................22

EMV Detection (ECE4007L03) ii

Page 3: EMV Detector Final Report

EXECUTIVE SUMMARY

The Emergency Vehicle (EMV) Detector is an automated device that alerts car drivers

when an emergency vehicle is approaching. The system consists of a microphone attached to the

outside of a car, an LED, speakers, and a low-power computer. The detector receives audio

input through the microphone, digitizes the signal using the computer, and detects patterns that

indicate an EMV siren using the computer’s software-implemented filters and DSP algorithms.

Upon detection, the device turns off the car’s radio, flashes a warning LED, and plays an audio

message warning the driver that an EMV is approaching.

A car’s audio and sound isolation may prevent a driver from hearing an EMV siren and

pulling over in time. By quickly notifying drivers of approaching EMVs, the EMV Detector will

save lives and money by reducing EMV collisions and improving EMV response times. The

device will be sold to car owners to install in current cars and car manufacturers to install in new

cars. Unlike other designs, which require transmitters to be placed in EMVs, this design is

strictly a client-side product, which reduces cost and increases usability.

Currently, the prototype of the EMV Detector can recognize all types of sirens (wail,

yelp, piercer, and hi-lo) 4db above ambient noise at a maximum Doppler shift of velocity 60

mph. The detection algorithms were implemented in MATLAB on a small general-purpose

computer. In the future, to save on cost and size, the code would be ported to C or C++ and

integrated with a vehicle's existing computer. In addition, the system could be extended to

determine the directionality of an approaching EMV by incorporating multiple microphones.

The total estimated cost of the prototype, including labor, equipment, fringe benefits, and

overhead, is $51,605.46.

EMV Detection (ECE4007L03) iii

Page 4: EMV Detector Final Report

EMERGENCY VEHICLE DETECTOR

1. INTRODUCTION

The EMV Detector consists of a microphone attached to the outside of a car that will be

monitoring sound at all times. The device detects patterns that indicate that the audio signal

contains an EMV siren using software-implemented filters and DSP algorithms. Upon detection,

the device turns off the vehicle’s radio, flashes an LED, and plays a message alerting the driver

that an EMV is approaching. Once the EMV has safely passed, the radio is turned back on, and a

message stating that it is safe to return to the road is played.

1.1 Objective

Emergency medical vehicle collisions are estimated to occur approximately 12,000 times

and cost millions in liability claims in a given year [1]. The EMV Detector is designed to be

placed in any vehicle, alert the driver of an oncoming EMV, and will work as a standalone

product. A microphone is placed outside of the car and connected to a low-power computer

inside the vehicle. The system is placed on the dashboard and will be powered by the car in the

final design. Once the microphone picks up audio of an EMV siren, a visual signal using an

LED will be displayed along with an audio message to warn the driver that an EMV is

approaching.

1.2 Motivation

The EMV Detector will greatly reduce the chance of accidents caused by motorists who

are unaware that an EMV is approaching. For auditory signals to be detected by the human ear,

EMV Detection (ECE4007L03) iv

Page 5: EMV Detector Final Report

that sound must be 8-12dB above background noise. When traveling in a car with the radio

turned off and the windows up, the noise inside the car is measured to be an average of 70dB.

Sirens are regulated to be approximately 120dB at 10 meters to avoid permanent damage to the

human ear. With the motorist at a speed of 56 mph and the EMV at 75 mph, the motorist needs

50 meters to have a 6-second response time. At these speeds, the siren sound level is 74dB,

which is not loud enough to warn the driver when taking into account noise inside of a car [2].

The detector proposed will also be able to enhance the response time to EMVs, which can save

lives. This product is designed to be placed in any motorist’s vehicle without causing excessive

clutter. Currently, there are patents such as patent 6,788,101 that propose a receiver-and-

transmitter system in which the EMV will contain a transmitter that sends a signal to a receiver

in the consumer’s vehicle. The proposed EMV Detector will be a client-end product and will not

require a transmitter for the EMV, which reduces cost and increases possibility of its use.

1.3 Background

At the current time, there are no commercially available products that match the full

description of the proposed design to detect EMVs. There is a patent that fits the description of

the proposed design, but it is implemented in a different way. United States patent 6,778,101

proposes the use of a transmitter in an EMV and a receiver in the consumer’s vehicle [3]. The

design has not been released in the market, and the proposed design differs in the implementation

of the detection of the EMV for the consumer. There are both audio detection and vehicle

detection systems, but no comprehensive system is used to detect EMVs.

EMV Detection (ECE4007L03) v

Page 6: EMV Detector Final Report

Audio Detection

Digital signal processing is one of the main commercially available applications in audio

detection. A recent development in audio detection is the use of the audio identification system

Waveprint [4]. Waveprint can detect an audio signal that has been degraded by using a

temporal-ordering-based processing system, and is “more accurate than the previous state-of-the-

art system while being more efficient and flexible in memory usage and computation.”

MATLAB is another program that is widely used in the field of audio processing. The design of

FIR, IIR, and fast Fourier transform processes is possible with the use of MATLAB. These

filters can be used to detect and manipulate the desired signal.

Vehicle Detection

Magnetic sensor technology is the most widely used technology for vehicle detection. By

detecting a vehicle’s disturbance of the earth’s magnetic field, these sensors can detect vehicles

and perform multiple functions such as traffic monitoring, gate opening, and vehicle location.

Another method for vehicle detection is the use of laser detection systems. These systems use

lasers to scan the roadway and create a 3D image of the vehicle [5]. This image is then analyzed

to find which vehicle it is. Both magnetic sensor and laser detection systems for vehicle

detection would require a transmitter to send confirmation of detection to a receiver in the

consumer’s vehicle for application in an EMV detection system.

2. PROJECT DESCRIPTION AND GOALS

The main goal of the EMV Detector is to increase the amount of time that a driver has to

react to a nearby EMV by warning the driver with audio and visual stimuli. When the system

EMV Detection (ECE4007L03) vi

Page 7: EMV Detector Final Report

detects a siren, it cuts power to the radio, lights an LED, and plays an audio message warning the

driver of the approaching EMV. After the EMV passes, power is restored to the radio and the

LED is turned off. In order to increase the likelihood of the widespread adoption of the system,

it will be small, require minimal user effort to install, and cost $175.

Features of the EMV Detector:

Increased response time for vehicle operator

Small in size

Easy to install

Costs $175

Audible and visible warnings

3. TECHNICAL SPECIFICATIONS

To achieve the goals of the project, the team has outlined a set of specifications, which

are shown in Table 1.

Normal human hearing requires a sound to be 8dB above the ambient noise in order to be

detected, and the sound insulation of a normal vehicle causes a 20dB insertion loss [2]. By

mounting the microphone outside the vehicle and designing a sensitive detection algorithm, the

EMV Detection (ECE4007L03) vii

Table 1. Specifications for the EMV Detector

Desired ActualDetection level 5dB over ambient noise 4dB over ambient noise

Refresh time 2 seconds 2 secondsSize (L x W x H) 6 in x 6 in x 1 in 12 in x12 in x3 in

Page 8: EMV Detector Final Report

EMV Detector can provide a significant improvement in safety. The refresh time needs to be

low in order to make the device useful. Ideally, all processing would be done in real time, but it

is extremely difficult to get that level of performance from a computer that can fit within the

desired size. Another problem is that the current algorithm used for siren detection becomes too

sensitive to incidental noises such as other vehicles passing and horns if the refresh time is less

than 2 seconds. The size constraint was chosen so that the EMV Detector could be placed in the

vehicle in such a way as to be easy to install and unobtrusive to the operator once it is in place,

but the current prototype does not meet this specification. The EMV Detector is expected to

meet this specification in the future once the motherboard and storage device used in the

computer are available in smaller sizes for a price that fits in the budget.

4. DESIGN APPROACH AND DETAILS

4.1 Design Approach

The chief problem in the project is distinguishing sirens from the background noise that is

prevalent when a vehicle is in motion. During research, the team discovered that there are four

types of sirens that are used in EMVs; these are called the wail, yelp, piercer, and hi-lo. Graphs

of the frequency vs. time of each of these sirens are shown in Figure 1. Dark areas on the graphs

are where the magnitude of signal is the strongest, which is a good hint as to what frequencies to

look at in order to detect a siren.

As implemented, the EMV Detector has three components: a microphone to gather audio

input, a computer based on an Intel Atom 330 processor which does the processing, and a small

board based on the Cypress CY8C29466 PSoC which handles the LED and relay circuits. A

diagram showing the general layout of the system can be seen in Figure 2.

EMV Detection (ECE4007L03) viii

Page 9: EMV Detector Final Report

EMV Detection (ECE4007L03) ix

Wail (725-1600 Hz, 12 CPM)

time (sec)

fre

qu

en

cy (

Hz)

0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

500

1000

1500

2000Yelp (500-3000 Hz, 180 CPM)

time (sec)

fre

qu

en

cy (

Hz)

0.5 1 1.5 2 2.5 30

500

1000

1500

2000

2500

3000

Piercer (725-1600 Hz, 800 CPM)

time (sec)

fre

qu

en

cy (

Hz)

0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.20

500

1000

1500

2000Hi-Lo (550-650 Hz, 60 CPM)

time (sec)

fre

qu

en

cy (

Hz)

0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

200

400

600

800

1000

Figure 1. Frequency vs. time for the four types of sirens.

Figure 2. EMV Detector system diagram.

Page 10: EMV Detector Final Report

The detection algorithm is written in MATLAB and runs on the computer. The detection code

works by running a fast Fourier transform on the audio input once every second and then

searching for the peak magnitude in the sample. If the frequency of the peak is within the range

that is defined for any type of siren, the software notes it and takes another sample. If the second

sample also comes back with a siren detection, then the software is confident that an EMV is

present, and it triggers the audio output and sends a signal to the external board telling it that

there is a siren. Once a siren has not been detected for 3 seconds, the software is confident that

the EMV has left the area and tells the vehicle operator that it is safe to resume driving. The

audio output was generated by the AT&T Text-to-Speech demonstration website. A higher-level

look at the program flow can be seen in Figure 3, and the MATLAB detection code can be found

in Appendix A.

EMV Detection (ECE4007L03) x

Figure 3. EMV Detector program flow.

Page 11: EMV Detector Final Report

The output board prototype is a Cypress PSoC Evaluation board, which provides a socket

for the Cypress CY8C29466 PSoC chip and provides an RS-232 port for communications, a 5-

pin programming interface, four LEDs, a small breadboard, and a 2-line LCD. The board is

programmed using Cypress’ PSoC Designer software, which makes it easy to assign input and

output pins and internal logic blocks on the chip and also provides a comprehensive C API for

interacting with the logic and executing simple programs on the PSoC. In the EMV Detector

system, the board begins by waiting to receive a signal over the RS-232 connection to the main

computer. Once the signal is received, the board lights an LED, drives the G6E-134P-US relay

to shunt the radio power to ground, and writes a short message on the LCD. When the board

receives a signal from the computer that the EMV has passed, the LED is turned off, the relay

switches back to its normal state of routing power to the radio, and the message on the LCD is

erased. It should be noted that the LCD is not intended to be part of the final product, but it was

used on the prototype to enable easier debugging. The source code of the program running on

the PSoC can be found in Appendix B.

4.2 Codes and Standards

RS-232 standard is “an asynchronous serial communication method.” The standard set

for data rates was set as 20 Kbps, but current devices have maximum speeds as high as 1.5 Mbps

with a maximum cable length of 50 feet or cable length equal to a capacitance of 2500 pF [6].

The TRS connector, also known as an “audio jack,” is used for audio applications. The

TRS connector consists of two to five conductors depending on which application the connector

is used. There are several standard sizes, but the most commonly used standard for microphones

is the 3.5mm standard [7].

EMV Detection (ECE4007L03) xi

Page 12: EMV Detector Final Report

4.3 Constraints, Alternatives, and Tradeoffs

Microphone

There are many different types of microphones that could be used for audio detection.

Due to budgetary concerns, some of them could not be used in this design. For example,

microphones specifically designed for the outdoors were one of the options considered but not

used due to economic restrictions. These outdoor microphones are designed for long periods of

unattended use and come with protection against corrosion and wind. This shield against

corrosion and wind would be practical for use outside of a car, where the microphone is subject

to the open air at high speeds. The use of microphone arrays to capture EMV sirens was another

possible alternative. The multiplexing of the inputs of multiple microphones placed strategically

in an area can be used in audio detection and location. However, due to budgetary constraints

and time constraints regarding the placement of these microphones to maximize efficiency, the

use of microphone arrays was not possible.

Audio Detection and Processing

Active noise control is an alternative option in the detection of acoustic signals. Ambient

noise data received by a microphone is converted into a digital signal through the use of an ADC.

This signal is then input to a DSP processor and converted into an inverse signal that is outputted

to a speaker to negate ambient noise. This technique is useful for operations where an audio

signal must be obtained from a noisy environment [8].

An alternative in processing of the audio signal is the use of a dedicated digital signal

processor which is specifically designed to handle DSP tasks. These processors are most

frequently used in processes that are continuous such as input audio signals. These processors

EMV Detection (ECE4007L03) xii

Page 13: EMV Detector Final Report

are expensive and also require the soldering of the processor to a printed circuit board which

contains the other electronics that are necessary in the design of our project [9].

The addition of directional detection of the EMV siren is an alternative that can be

implemented to add functionality and complexity to the project. Microphone arrays would be

used to determine the approaching direction of the EMV in relation to the vehicle. Extra

algorithms would be implemented to account for this addition. Budgetary and time concerns

would be taken into account to decide if this is a viable option to be implemented in the design.

5. SCHEDULE, TASKS, AND MILESTONES

The project timeline included three major milestones: the acquisition of parts, the

implementation of hardware and software, and the integration of hardware and software. As

seen in Figure 4, the team’s first task after writing the proposal was to begin gathering items

needed to implement the design. Jose found Atlanta siren sounds online, Richard found a voice

generator for the audio warning, and Ehren decided on what parts to use. The acquisition of

parts took two weeks longer than expected because the original power supply was incompatible

and a new one had to be ordered. This delay cut into the amount of time for testing at the end,

but the remaining time turned out to be sufficient.

EMV Detection (ECE4007L03) xiii

Page 14: EMV Detector Final Report

Figure 4. Project schedule.

Page 15: EMV Detector Final Report

While waiting for parts, the team as a whole began analyzing siren properties and

discussing methods of detection. Once all of the parts had arrived, Tyler, Jose, and Richard

spent two weeks coding the detection algorithms in MATLAB, while Ehren configured the

hardware and coded the LED controller. Then the hardware and software were integrated, Ehren

wired a relay circuit for switching off the car's radio, and the team devoted the rest of the time to

testing and debugging the device using both unaltered and Doppler-shifted siren sounds in

combination with music and recorded background noise. Richard created the Doppler-shifted

siren sounds, and Ehren and Tyler recorded the background noise.

The most difficult and most important task of the project was developing the detection

algorithms, which involved looking for distinct characteristics in the sirens and experimenting

with different frequency ranges to achieve an optimal level of sensitivity. The second most

difficult task was devising a way to cut off power to the car’s radio. This problem was solved

with the addition of a relay circuit. All other tasks were relatively straightforward.

6. PROJECT DEMONSTRATION

The EMV Detector was demonstrated in a controlled indoor setting. The device was

connected to an LED to simulate a radio’s power supply and to an additional LED for EMV

notification. A siren recording was played near the microphone of the EMV detector. The device

is functional if it cut power to the “radio” LED, illuminates the warning LED, and plays an audio

message alerting the driver of EMVs.

The next feature that was tested was the device’s ability to filter out ambient driving

noise while still detecting the siren sound. This was done by playing a recording of ambient

driving noise along with a siren. The siren was played through speakers connected to one laptop,

Page 16: EMV Detector Final Report

and the ambient driving noise was played through speakers connected to another laptop. The

ambient driving noise by itself got no response from the device, while the ambient driving noise

with the siren turned off the “radio” LED, illuminated the warning LED, and played the audio

message. In this step, an SPL meter was used to measure the volume level of the ambient noise

and then the siren volume level when the siren was detected. This varying of volume was used to

determine that the minimum noise level above ambient noise that a siren could be detected is

4db.

Another feature that was tested was the device’s ability to correctly detect Doppler

shifted siren signals. Repeated tests were conducted by playing recordings of sirens with varying

Doppler effects and a varying volume on inputs. There was one flaw in the algorithm, however.

When a certain siren was being played, the detector would incorrectly give an “all clear” signal

right after it had given a correct “emergency vehicle approaching signal,” even though the siren

was still being played. This happened because our audio message was picked up by the

microphone and caused our algorithm to fail. This situation would not happen in a real

application since the microphone would be placed outside of the car.

7. MARKETING AND COST ANALYSIS

7.1 Marketing Analysis

The EMV Detector is a major safety improvement for vehicles. Ambulances are thirteen

times more likely to have accidents than consumer vehicles and are five times more likely to

cause an injury [10]. The device requires only installation in consumer vehicles and not the

EMVs. The device is low-power and can easily be powered by the vehicle’s battery. There are

similar products on the market, but they require a radio transmitter to be installed in the EMVs

Page 17: EMV Detector Final Report

and a receiver in consumer vehicles [11]. The EMV Detector will give drivers more time to

recognize and respond to approaching EMVs, greatly reducing the chances of a collision.

7.2 Cost Analysis

The EMV Detector can be developed and prototyped for a total cost of $51,605.46.

Equipment costs are $159.37, and labor costs are $32,900. The project costs are located in Table

2.

The labor costs were calculated using an average wage of $50/hour. The fringe benefits

were calculated as 25 percent of the total labor cost, and the total overhead was calculated as 25

percent of the labor, equipment, and fringe benefits costs.

8. SUMMARY AND CONCLUSIONS

The EMV Detector met or exceeded most of its desired specifications. The only feature

that could not be included was the ability to distinguish between different types of EMVs, since

Table 2. Project Costs

PROJECT ELEMENTLABOR HOURS

LABOR COST

EQUIPMENT COST

TOTAL ELEMENT COST

Device Construction         DSP processor 100 $5,000.00 $104.12   Microphone connection 20 $1,000.00 $19.80    A/V output 50 $2,500.00  $35.45  DSP software development 300 $15,000.00 $0.00 $15,000.00Class lecture and meetings 188 $9,400.00 $0.00 $9,400.00TOTAL LABOR 658 $32,900.00    TOTAL EQUIPMENT     $159.37  FRINGE BENEFITS       $8,225.00TOTAL OVERHEAD       $10,321.09PROJECT TOTAL       $51,605.46

Page 18: EMV Detector Final Report

there is no standard for what siren patterns are used in each department and, therefore, no way of

implementing this feature through siren analysis alone. However, this feature is more

ornamental than practical and does not affect the main functionality of the device. One possible

approach to implement this feature in the future is through visual detection of an EMV's flashing

lights.

The current version of the device is primarily software-based. The next stage of this

project should focus on optimizing the hardware and installing it in an actual vehicle. The bulk

of the size and cost of the current device comes from the general-purpose computer used to run

the software. By porting the MATLAB code to C or C++ and integrating it with a vehicle's

existing computer, the size and cost could be significantly reduced. In addition, multiple

microphones could be incorporated to determine the directionality of the EMV, increasing

convenience for the driver.

Additional testing and optimization of the detection algorithms should also be performed.

During testing of the current version of the project, the device's accuracy was occasionally

affected by various noises in the external environment. Either a frequency near a siren frequency

would create a false positive, or a frequency slightly louder than the siren frequency would create

a false negative. Further investigation of the sirens' frequency properties and more precise

algorithms are needed to ensure stability.

The EMV Detector is currently the only known device of its kind that employs siren

detection rather than a transmitter-receiver system. With a few modifications, there lies potential

for a reliable and inexpensive product that can prevent accidents and save lives.

Page 19: EMV Detector Final Report

9. REFERENCES

[1] J. Clawson, R. Martin, G. Cady, R. Maio, “The Wake Effect: Emergency Vehicle-

Related Collisions, ” [Online],[cited 2008 Sep 9], Available:

http://www.emergencydispatch.org/articles/wakeeffect1.htm

[2] M. Miller, R. Beaton, “The Alarming Sounds of Science,” [Online],[cited 2008 Sep 14],

Available: http://www.frontiernet.net/~mkmiller/Prof/Ergo/sound.htm

[3] T. Turbeville, J. Majka, “Emergency Vehicle Detection System,” U.S. Patent 6,778,101,

November 27, 2002.

[4] M. Covell, S. Baluja, “Known-audio detection using WAVEPRINT: Spectrogram

fingerprinting by wavelet hashing, ” [Online],[cited 2008 Sep 9], Available:

http://www.esprockets.com/papers/detection_CB.pdf

[5] OSI LaserScan, “OSI LaserScan - Laser Detection Sensors and Vehicle Detection

Systems for Toll and Traffic Management, ” [Online],[cited 2008 Sep 8], Available:

http://www.roadtraffic-technology.com/contractors/detection/osi/

[6] Lammert Bias, “RS232 Specifications and standard, ” [Online],[cited 2008 Sep 9],

Available: http://www.lammertbies.nl/comm/info/RS-232_specs.html

Page 20: EMV Detector Final Report

[7] International Textbook Company, International Library of Technology: A Series of

Textbooks for Persons Engaged in the Engineering Professions and Trades, Or for Those

who Desire Information Concerning Them, London, England: International Textbook

Company, pp. 36-38 , 1907.

[8] M. Onishi, Y. Nakamura, T. Inoue, and A. Takahashi, “Active Noise Control System,”

U.S. Patent 7,340,064, 27 May, 2006.

[9] S. Smith, “The Digital Signal Processor Market, ” [Online],[cited 2008 Sep 9],

Available: http://www.dspguide.com/ch28/7.htm

[10] D. Long, “Facts on Emergency Vehicle Driving,” www.lmnc.org, para. 6, 2007. [Online].

Available: http://www.lmnc.org/media/document/1/emgncyvehicledriving.pdf. [Accessed

Sept. 12, 2008].

[11] T. A. Turbeville and J. R. Majka, “Emergency vehicle notification system,” U. S. Patent

7,397,356, 8 July, 2008.

Page 21: EMV Detector Final Report

Appendix A: EMV Detector MATLAB Source Code

Page 22: EMV Detector Final Report

%Audio input code By Nathir A Rawashdeh, March 2007%Detection code by EMV Detection group, September-December 2008 %%% User Parametersduration = 1; % How many seconds of acquisition per plot refresh?Fs = 8000; % Acquisition sample rate in Hz (try 8000)sirenProb = 0;notSirenProb = 0;% ------------------------------------------------------- %uncomment the next 2 lines when led controller is connecteds = serial('COM1','BaudRate',19200,'Terminator','CR');fopen(s);%%% Initialization & configuration of sound cardAI = analoginput('winsound');addchannel(AI, 1);set (AI, 'SampleRate', Fs);set(AI, 'SamplesPerTrigger', duration*Fs); away = wavread('Away.wav'); approach = wavread('Approaching.wav'); AppSound = 0; AwaySound = 1;%%% Loop to get data and display it% this "try" helps the program end% properly when "ctr+c" is hittry count = 0; % count how many time the while was executed while 1 % increment loop counter count = count +1; % calculate elapsed time ET = duration * count; % start acquisition and retrieve data start(AI); data = getdata(AI); % Results: update a FFT magnitude plot xfft = abs(fft(data)); mag = 20*log10(xfft); % Convert to dB mag = mag(1:end/2); % duscard the redundant half figure(1010), plot([1:length(mag)]./duration,mag) title(['FFT Magnitude ; Seconds Elapsed = ' num2str(ET) ]) xlabel('Hz'), ylabel('dB'), grid on, axis([0 2000 -60 60]) average = mean(mag(350:2000))+12;

Page 23: EMV Detector Final Report

[maximus, maxIndex] = max(mag(490:2000)); maxIndex+490; [maxhilo, maxIndexhilo] = max(mag(1400:2000)); maxIndexhilo+1400; %Wail conditionals wail(1) = all((mag(700:750)> average)); wail(2) = all((mag(750:800)> average)); wail(3) = all((mag(800:850)> average)); wail(4) = all((mag(850:900)> average)); wail(5) = all((mag(900:950)> average)); wail(6) = all((mag(950:1000)> average)); wail(7) = all((mag(1000:1050)> average)); wail(8) = all((mag(1050:1100)> average)); wail(9) = all((mag(1100:1150)> average)); wail(11) = all((mag(1150:1200)> average)); wail(12) = all((mag(1200:1250)> average)); wail(13) = all((mag(1250:1300)> average)); wail(14) = all((mag(1300:1350)> average)); wail(15) = all((mag(1350:1400)> average)); wail(16) = all((mag(1400:1450)> average)); wail(17) = all((mag(1450:1500)> average)); wail(18) = all((mag(1500:1550)> average)); wail(19) = all((mag(1550:1600)> average)); wail(20) = all((mag(1600:1650)> average)); wail(21) = all((mag(1650:1700)> average)); wail(22) = all((mag(1700:1750)> average)); wail(23) = all((mag(1750:1800)> average)); %Wail type siren detection if any(wail) %if any conditionals above are true sirenProb = sirenProb+1; notSirenProb = 0; wailstuff = 1; %Hi-Lo type siren elseif (((max(mag(495:548))== maximus) || (max(mag(645:710))== maximus )) && ((max(mag(495:548))>= 0.8*maximus) || (max(mag(645:710))>= 0.8*maximus )) && ((max(mag(1500:1510)) == maxhilo) || (max(mag(1615:1635)) == maxhilo))) % if freq between 495 and 548 or between 645 and 710 sirenProb = sirenProb + 1 ; % siren detected increase sirenProb notSirenProb = 0; % reset notSirenProb highlo = 1; %piercer & yelp type siren elseif (max(mag(840:1110))== maximus) % max amplitude at freq between 960 and 1096 sirenProb = sirenProb + 1 ; % if piercer or yelp detected increase sirenProb notSirenProb = 0; % siren detected so reset notSirenProb pierceryelp = 1;

Page 24: EMV Detector Final Report

elseif sirenProb > 3 notSirenProb = notSirenProb+1 ; % no siren was detected so increase notSirenProb if siren had been detected for 3 seconds or more else sirenProb = 0 ; % no siren detected so reset sirenProb end; % if a siren is not detected for 3 seconds reset sirenProb if notSirenProb > 3 pierceryelp = 0; highlo = 0; wailstuff = 0; sirenProb = 0; end; % if a siren is detected for 2 seconds in a row set siren flag if sirenProb >=2 siren = 1 ; else siren = 0; end; fprintf(s,'%d\n',siren); %uncomment above when led connected if (AppSound == 0 && siren == 1) wavplay(approach,16000,'async'); AppSound = 1; AwaySound = 0; end if (AwaySound == 0 && siren == 0) wavplay(away, 16000,'async'); AwaySound = 1; AppSound = 0; end endcatch disp('--> coninuous loop was manually interrupted')end %%% Termination - uncomment fclose and following when led connecteddisp('--> Deleting Analog Input Object')fclose(s)delete(s)clear sstop(AI)delete(AI)

Page 25: EMV Detector Final Report

Appendix B: PSoC LED Controller Source Code

Page 26: EMV Detector Final Report

//----------------------------------------------------------------------------// C main line//----------------------------------------------------------------------------#include <stdlib.h>#include <m8c.h> // part specific constants and macros#include "PSoCAPI.h" // PSoC API definitions for all User Modules

void main(){ char * strPtr;

int num=0;

UART_CmdReset(); UART_IntCntl(UART_ENABLE_RX_INT); //prep RS-232 interface

LCD_Start(); //Enable the various I/O blocks and get them ready to receive commandsLED_1_Start();Relay_1_Start();Relay_2_Start();UART_Start(UART_PARITY_NONE);

M8C_EnableGInt ;LCD_Position(0,2);LCD_PrCString("Waiting for");LCD_Position(1,5);LCD_PrCString("Input");

while(1){if(UART_bCmdCheck()){ //wait for command

LCD_Position(0,0);LCD_PrCString(" ");LCD_Position(1,0);LCD_PrCString(" ");strPtr = UART_szGetRestOfParams();num = atoi(strPtr);

if(num){ //when a 1 is received from host PC, trigger warnings and turn off radio

LED_1_On();Relay_1_On();Relay_2_On();LCD_Position(0,0);LCD_PrCString("EMV Approaching");LCD_Position(1,0);LCD_PrCString("Pull Over Soon");

Page 27: EMV Detector Final Report

}else{ //when receiving a 0 from computer, make sure the warnings are off

LED_1_Off();Relay_1_Off();Relay_2_Off();LCD_Position(0,0);LCD_PrCString("No EMVs");LCD_Position(1,0);LCD_PrCString("Detected");

}UART_CmdReset(); //clear command buffer to prep for next run}

}}