Introduction To Information Engineering (2)

Transcription

Introduction to InformationEngineeringStephen Roberts

Lecture 1A gentle introduction

Aims To provide you with an overview of what B4and information engineering in general isconcerned with To make explicit links between informationengineering and the core syllabus especiallyA1, A2 and A3 To give you some sense of how centralinformation engineering is to the engineer’scareer and to our every day lives.

Course OutcomesAt the end of this 4 lecture course you should be able to deconstruct overall data capture / analysis / control system intocomponents and understand how they interactappreciate the role of the computer as a general purpose information processingtoolunderstand the role of the operating system and how both sensors and actuatorscan be interfaced to a computer at the hardware and software levelunderstand the role of probability as the mathematical tool for modellinguncertainty in sensors, and how to use Bayes rule as a means to combine sensormeasurements or prior informationunderstand the consequences of sampling and ZOH, and how to discretizecontinuous controllersbe able to analyse the components of a fast-sampled feedback system both inisolation and in the context of the complete system

The Information Engineering DomainInference and AnalysisEstimationData ProcessingModelling and ControlOperating SystemData AcquisitionOutput HardwareSensorsActuatorsReal World

The Role of Feedback Note the presence of a feedback loop in the previousarchitecture. -C(s)G(s)H(s) The control system block diagrams you manipulate in A3 arepowerful mathematical abstractions for devising controlstrategies for systems To actually instantiate/embed this control system in a realvehicle, the controller design and analysis, is only part of thestory. Information engineering (inc B4) is much more thancontrol theory.

What is C(s) -C(s)G(s)H(s)C(s)A controller that is implemented in all likelihood on acomputerIssues: What does the software of the controller look like? What speed must it run at? Computers are discrete devices but the world is continuous so how does onelink the two? Does using a discrete controller have stability implications? What design tools are available for the discrete domain? Do familiar continuous domain analysis tools have discrete time duals?

What is H? -CGHHA transfer function between a sensed plant output and thequantity we wish to controlIssues: How does one sample the plant output ? How does one transmit measurements to the CPU running the controller? How does one guarantee that measurements will always be processed ? What does one do if the sensed output is not what we wish to control e.g sensingcolor but wanting to control flow rate? How does one deal with noisy sensor data? How does one fuse multiple measurements?

Information Systems Exemplar The “Segway” robot shown here is a container ofmany of the central concerns of the informationengineer (and as it happens, electrical engineers) Sensing (accelerometers, gyro) Actuation Control (varying payload) Computing––––IO from sensorsOutput to actuatorsControllers in softwareEstimation of state by processing sensor data

Note: Duplication ofelectronics (safety) Requires interfacing ofsensors and motors tocomputation Requires control to beimplemented on acomputer Control laws are nontrivial : to stop you haveto first speed up! Requires interpretationof sensor data Requires an internalmodel

Info Eng. Components of the Segway Sensors - 5 Corriolis (interesting) gyrosHow do you combine theinformation from 5 noisy sensorsin a principled way? (B4 )

Computation Hardware Data Acquisition : The PIC16F87x Flashmicrocontrollers process sensor data from theinertial monitoring unit and communicateinformation to the control module. Control Module is a 100 MIPS Digital Signal ProcessorTMS320C2000 from Texas Instruments. Communication is via CAN and I2C bus Two boards acting in duplicate for safety Some interesting stories on redundancyhere .

Exemplar II – a 3D laser System Issues – synchronisation of disparate data streams Estimation of system latencies

3D Reconstruction

Compelling Cross Discipline ProblemsBuilding climate controlVery uncertain PlantLarge unknown lagsEngine ManagementAbnormality detectionMachine LearningMedical imagingImprecise sensor dataDeformable structureComplex 3D reconstructionDiagnosis from measurements

And Some MoreNetwork analysisNational GridComplicated non-linear coupleddynamicsCar designComplex optimisation taskActive suspensionTraction control, slip estimationPlant identification

Lecture II –The Role of the Computer IO sensor interfaces––––Serial portsEthernetPCIFirewire Microcontrollers– PICs– embedded systems,– pic diagram ref segway OS– device drivers Processes and IPC (inter process communication)

Motivation If we are to design a complete informationengineering system we may need to considerof how data is or should be marshalled Data transfer technology is ubiquitous and 5*Engineers should be able to say somethingsensible about every day equipment!

Sensor/Actuator Interfacing How to get data from sensor to processor? Common choices––––Direct to bus (PCI)External serial protocols RS232, firewire, USBCAN bus (controller area network)All need hardware/software to transport dataVehicle controlFlight surface control andanomaly detectionSeismic sensing networks

Straight to PC BusExample Engberg PCI-DAS6035 16 channels of 16-bit A/D board two 12-bit analog outputs 8 digital I/O lines, two 16-bit counterInstrumentation RigAnalog/digital dataControl signalHigh power amplifierPCI BUSPCI Bus (Peripheral Component Interface Bus) 33Mhz Clock Generally 32 bits wide (specification allows for 64 bits) Allows plug and play – BIOS configures interrupts /address space Allows burst mode transfersOffline analysis and inference

Inter-Device Serial ProtocolsCan be very simple to implement- at its simplest one wire for Tx one for Rx and one for Gnd between two devices- varying electrical and data protocols dictate complexity and performanceSlow speed RS232, RS485, RS422 – the COM Ports on your PC,long distance, simple hardware, simple data protocolUSB (universal serial bus) faster now ubiquitous, short distances,12 Mbits/s or 480Mbits/s (USBII)Firewire (a.k.a IEEE 1394, iLink) very fast, short distance800 Mbits/sCAN bus – very robust, multiple devices, slow, an industrialfavourite. Very common in cars (invented by BMW)

RS232/RS422 Very common found on almost every non-laptop PC(“COM ports”) Generally slow data rates 115kBaud. Asynchronous – noclock Sends / receives data in packets serially At its most basic, RS232 needs only 3 signal wires Tx/Rxand Gnd (pins 2,3 and 5 on a 9 pin connector) RS422 is a differential signal – instead of raising and lowingone wire at a time TXA goes up while TXB goes down Depending on Baud rate can transmit many 10s of meters Data protocol described using a triplet : [Data packet size][Parity Bit][NumStopBits] 8N1 and 8N2is common – 8 data bits, no parity bitwith one or two stop bits. Voltage levels for RS232 and RS422 are typically large /12V is common, but you can get away with 0 and 5V muchof the time. Note RS232 and RS422 are both electrical specifications ofsimple serial protocols A special chip called a UART Universal AsynchronousReceive Transmit is used to manage the serial linkand produce bytes of data from the serial streamThis is 8E1 (even parity s.t #ones is even)Image from www.best-microcontroller-projects.com

The Microcontroller Include hardware for common IO tasks––––PWM (Pulse width modulation)A2D D2ASerial Ports (TTL not usually RS232 etc)Digital IO When deployed, typically only runs one program burnt intoEEPROM. (ie no OS just a while(1) ) On board RAM Self contained – little external interfacing required Can sometimes be programmed with high level languageslike C using manufacturer’s compilers Very cheap (almost free!)

PIC’s PICS (Programmable Intelligent Computers) are very common brand ofmicrocontrollers and you’ll find them everywhere Typically slow clock rates ( 40MHz) Very cheap (from a few pence) Easy to program very few instructions small number of pins very easy to interface Typically little on board RAM (perhaps a few K of data space) Ideal for dedicated processing unit for a single device for exampleinterpreting keyboard interaction.Image ex -wikepedia

Example PIC16F87 (used in Segway)Typical applications of uControllers Household appliances (washing machines) Keyboards Printers Engine management systems Any application that is IO intensive but requireslittle number crunching

Digital Signal Processors (DSP) MAC (multiply and accumulate instruction) (recent PICS have MAC)Hardware support for loopingBlindingly fast at common sig-processing operationsOften not optimised for fast logic operationsTexas Instruments have a very popular range of DSP’s called the TMS320 seriesDSP’s come in native integer and floating point varieties (in contrast withuControllers which are almost always just integer based)Around 8 Billion market for DSPs in 2006These chips and the algorithms they support are truly important! Mobile phones Digital TV boxes Satellite comms CD players/ MP3 players (Segway robots )The algorithms that support these applications are the domain of the informationengineer.

Why is MAC so Important? In B4 and C4 (if you take it) you’ll learn that the continuous transferfunctions you are now familiar with (e.g C(s)) are in reality almost alwaysimplemented in discrete form on a computing device. If C(s) is a continuous function you’ll soon learn how to map this to adiscrete time controller C’(z) where z is the discrete time analogue of s The upshot of all of this is that time and time again we’ll come acrossexpressions like:Constant “filter” coefficientsOutput nowPrevious outputsCurrent inputPrevious inputsAt each cycle a number of multiply and accumulates have to occurMany DSP can implement the above in a single clock cycle .

Discrete Filter Design Digital filters are ubiquitous and many sophisticated tools exist to designfitlers with required frequency characterstics. For example a notch filter toremove contamination at a given frequency ion of nyquist frequency0.70.80.9100.10.20.30.40.50.6Fraction of nyquist frequency0.70.80.9110050Phase (degrees)More on this later in B4Magnitude (dB)-500-50-100-150

Micro Processors Close approximation to what you’ll find inyour PC – general purpose computationdevices No onboard IO like serial ports A2D etc Often large word size Little speed optimised hardware althoughrecent x86’s have made in-roads Covered in A2

From Hardware to main()ThreadThreadMultiple Running programs writtenby users/3rd partiesUserProcessComplicated program which abstractshardware and provides process control“firmware” which glues motherboardtogether, sets up interrupts andeventually loads OSAdditional executionstreamsUserProcessUserProcessOperating SystemBIOS – Basic input / output systemHardisk, keyboard, graphics cardPlay with WinXP Profiler .Hardware

The Role of the Operating System Provides a hardware abstraction layer (HAL)– Provides an application programmers interface (API) for all kinds ofhardware – e.g all keyboards look the same to programmers, all fileson disk can be accessed in the same way (not a function ofmanufacturer)– Vendors of hardware write drivers which plug into one side of the HALAPI and the writers of processes use the HAL APIUser ProcessOSHALDriverhardwareHAL API is a set of function likeWriteFile(), ReadFile, GetMouse()

Interlude: Units of Execution Processes A process is a fundamental conceptto computing. It represents a single instance of arunning computer program – asequence of serially executinginstructions. A process is allocated memorywhich is not (generally) seen byother processes The times at which processes arerun are scheduled by the operatingsystem

Interlude: Units of Execution - Threads Threads are independent threads of execution within asingle process. Thread scheduling by the OS gives the appearance ofconcurrent execution All threads within a given process can see (read andwrite) the same memory – that owned by the process. For example a process might have a user interfacethread (drawing, handling button presses) acomputation thread and a sensor IO thread. Operating systems provide system calls that start newthreads from thread[0] (the thread started by the OSwhen a process is started.)

The Role of the Operating System Provides a mechanism for scheduling /interleaving the execution of processes– Gives the appearance of concurrent processexecution on a serial processor– Manages the context switching betweenprocesses. (switching relevant data in and out ofprocessor registers)– Running processes “see” uninterrupted executionand need not (usually) be written to yieldexecution to siblings.

The Role of the Operating System Provides Memory Management– Running processes can request allocation ofmemory at run time– The physical memory is abstracted away fromrunning processes– Memory may be a combination of physical RAMand disk space

Handling Interrupts More often than not interrupts are interceptedby the OS and mapped to calls into a relevantdevice driver For example a UART may raise an interrupt whenits Rx buffer is 50% full:– The interrupt calls a function in the serial port driver.– The driver extracts data from the hardware and placesit a software buffer(array) provided by the OS– Processes granted access to the serial port read fromthis abstracted serial port when “reading” from theserial port.

Interprocess CommunicationImage GrabbingProducerCommunication mechanismImageUnderstandingConsumerWe need to consider how data could be shared between producer and consumer

Shared MemoryProcess AProcess BShared Memory Processes can make special system calls to the operating system which return a chunkof memory that can be shared between processes. The OS also provides a mechanism by which a process can ask to have alreadyallocated shared memory inserted into its own address space (Process B needs to beable to ask to see the shared memory segment already created by Process A)Q: What happens if the producer writes as the consumer tries to read?

The need for SynchronisationwriteShared MemoryreadwriteThe consumer was reading as the producer executed the secondwrite. The result is corrupted data.We need someway to synchronise the processes to protect resources

Binary SemaphoresInitialise a semaphore (which is a signalbetween threads or processes) to the numberof times a protected resource can be shared(1)Call when access to the resource isrequired.This blocks (halts) execution untilcompletion.When s 0 is detected next linemust complete before thread is rescheduled –it must be “atomic” (functionality provided byOS)Call when finished with resource

Binary Semaphore ExampleProcess A (Producer)Process B (Consumer)Read and writes are toshared memory Between P & S privacy is guaranteed. OS needs to provide Semaphore functionality and a mechanism to allow bothprocesses to share the semaphore S

Lecture III The role of probabilityTheory Sensor models The Role of Bayes’ rule– Recursive estimation– Tracking– Plant models– Filtering

Revision of ProbabilityProduct RuleMarginalisationIf a & b are continuousIf a & b are discreteIf you can remember and use these two rules then so much iswithin your reach .(including exams!)

Probabilistic Models We can think of sensor measurements, z, assamples from a conditional distribution(conditioned on the state of the world, x)Laser range finder (theodolite)True distance xMeasured distance z x random noisep(z x)x

Sensor Models Cont – Gaussian Noisep(z x)Here we have elected to model noise as samples from a Gaussian which is avery common practicep(z x) explains the measurement in terms of the underlying state

Estimating x from p(z x)DataEstimationEnginePrior BeliefsEstimate

Maximum LikelihoodN.B Multivariate Gaussian Understood?Find a value of x(state) that best explains z (data)

Maximum LikelihoodWe are given a value for z and view p(z x) f(x,z) as a function of xp(z x)xmlxML does not incorporate prior knowledgeC4B Mobile Robots

Incorporating Prior KnowledgeWhat if we knew something abut the state of the worldbefore we took the measurement – could we incorporate thatinformation?p(x)We can use a probability distributionover x to capture our prior belief in thevalue of xSo how can we combine p(z x) and p(x) to yield p(x z) ?

Bayes’ RuleAA \BA “joint distribution”BA “conditional distribution”A “marginal distribution”

Should we bother with Bayes?Yes, you should be. Bayes’ rule lies at the very heart ofswathes of information engineering: Medical imaging Tracking Estimation Sensor processing signal recovery Machine learningBayes’ Rule lets you invert conditionals expressingp(a b) in terms of p(b a)

Consider Our Laser Examplep(z x)

Apply Bayes’ RuleThe x which maximises p(x z) is called the “maximuma posteriori” estimate

Maximum A Posteriori EstimationNote denominator is nota function of x – it is a normaliserM.A.P does incorporate prior knowledge

Example Cont MeanVariance

How does the mean change?Old (prior) meanDifference between measurement and prior

Visually Remember - the variance of posterior is smallerthan the prior – why? because the measurement addsinformation. This notion will be formalised later in the course

Discrete Time Recursive BayesianEstimationSubscript is timeSequence of data (measurements)We want the conditional distributionState at time k(think position)Sequence of measurements upuntil time k (think - list of ranges)Question: Can we iteratively calculate this – ie every time a newmeasurement comes in update our estimate? – (Answer :yes, see next slide)posteriorpriormeasurementWe are looking for a distribution over state at time k given all measurements up until time k

Recursive (online) Bayes’

Key ResultAt time kExplains data at time kas function of x at time kC4B Mobile RobotsAt time k-1

Incorporating Plant ModelsWe should have used a k subscript on x to indicate that we are referringto x at time kNow the last term on the numerator looks like a prediction.Previous stateFUncertain Plant Modelcontrolnew state

Incorporating Plant UncertaintyProbabilistic plant modelLast estimateHere we have used the assumptions that given the state at k-1 and control at time k, the state at time k isindependent of the observations The state at time k-1 is independent of the control at time k (which isin the future)

Applications The previous few slides have indicated the existence of a probabilisticframework which can handle uncertainty in measurements and plant models Note that at no point were we restricted by the form of the p.d.f’s or whatthe physical interpretation of x,z or u might be. x: rate of inflation, z: the price of a car, u: intervention from the world bank x: strain on a beam, z: measured voltage x: car velocity, z police radar time of flight x: sheet metal thickness, z:X-Ray energy, u: roller pressure x: tumour state, z: PET scan, u:motion of patients head during scanProbabilistic methods are a natural way to handle uncertainty in measurement and state evolution.The techniques they give rise find application across all domains of engineering

The Role of the GaussianIt is common to find that the functional form of the pdfs in the previous slides is that ofa Gaussian. Of course we may have distribution over a vector (for example position andvelocity). In which case we shall be dealing with the multidimensional Normaldistribution.A “joint” distribution over x and y

The structure of Σ.You can read the marginal distribution varianceoff the diagonals of the covariance of the joint

The Gaussian is a common functionalformIf Gaussians are used in the pdfs of the recursive Bayesformulation and in the equations we derived for propagatingplant uncertainty one ends up with something called aKalman Filter (covered in detail in C4)The Kalman filter is a very common tool in estimationapplications. For example in car navigation systems Hawkeye Economic models. Hospital delivery systems Port automation

Camera 2 (observer)State VectorHawkeyeFlight ParametersCamera 1 (observer)Image coordinatesSequential Images from a single camera

Extracting the Observations Is a hard information engineering problem initself!Again it turns out that solutions to this problem areunderpinned by probability theory! More of this kindof problem (and solutions) in B4 and C4

Lecture IV Computer Based FeedbackControl and Actuation You are already familiar with continuous time control systemsr(t)e(t) -controllerD(s)u(t)1sensorsplantG(s)y(t)

In Practice: Using A Digital Computer We implement the controller in software running on a digital conputer We need to convert twixt digital and analog r(t)Sample &ADCe(kt) r(kt)-controllerDu(kt)DAC &Holdu(t)Sample &ADCplantG(s)1sensorsDigital, sampled system The signals e(kT) u(kT) and r(kT) are “discrete” T is the sample period,k is an integer A discrete signal is constant over the sample periodNotation: for a discrete signal y, constant T: y(kT) y(k) yky(t)

Discrete Signalsy(t)sampley(kT)The quantity y(kT) is a discrete sampled signalT is the sample period (assumed constant)k is an integerA discrete signal is representative of the continuous signalover the sample period Think of y(kT) as a number. Its precision is dictated by the precision of thesampling hardware (e.g 8 or 16 bits)

How do we implement a discrete timecontroller?Imagine we have been given the desired controller transferfunction D(s) , how might we construct a discrete timeversion?Writing D(s) as a quotientof two polynomials in sLast step renormalises by dividing both sides by ao

Approximating the derivative operator You know from A1 that So we could substitute these discrete derivative approximationsinto

Examplecontrol at time k is function ofprevious control and previous andcurrent input

Example ContinuedNote how easy this is to implement.In general requires variables to be storedacross iterationsNote how the constants are dependent onsample time. If we keep sample time constantcomputation is simplified even further.Are we free to choose any T (even if we keep it constant)?We can imagine that the answer is no – why?

The Effect of Sample and Holdx(t)x(kT)Zero order hold introduces a lag of T/2Or equivalently a phase lag of

Impact of sample on Closed LoopStabilityUnit circle[-1]Phase lag can rotate Nyquist diagram toencircle [-1,0]causing instability (from A3)IncreasingD(jw)G(jw)

Example Using SimulinkContinuous ControllerDiscrete controller

Simulation Results80 Hz1.5Blue: continuoussystem response10Red: sampledsystem responseGood 60.811.21.41.61.8200.20.40.60.811.21.41.61.8220 Hz10.501.510 HzSample rate1.510.505 Hz4instability20-200.20.40.60.811.21.41.61.82time (s)As sample rate falls performance degrades – dynamics of plant dictatesample rate and ultimately speed of controller iteration

Summary If you sample fast enough a digital controller can be afine approximation to continuous system. General rule of thumb is to sample at more than 30times plant band width. If you can’t sample this fast then you need to knowmore information engineering and come to theComputer Controlled Systems Lectures .

Course Conclusion This was a very brief tour over just some of the areas that concern andinterest information engineers and the domains that informationengineering has a role to play In places we have given a few samples of the kind of mathematics youshall see more of in B4 and if you get hooked C4A and C4B Hopefully you’ll now be aware that B4 is not just the “control paper”although it does contain a wholesome amount of that importantinformation engineering topic. Hopefully you’ll have had your interest piqued and have the sense that ifyou are going to a financier or an engineer that at some point needs toprocess data (so that’s pretty much all of them) then informationengineering has a great deal to offer you! After all, it brought you Google

Introduction to Information Engineering Stephen Roberts. Lecture 1 A gentle introduction. Aims To provide you with an overview of what B4 and information engineering in general is concerned with To make explicit links between information engineering and the core syllabus especially . Data tra