LabVIEW Signal Processing [With Contains an Evaluation Version of LabVIEW 4.1] 0139724494, 9780139724497

Everything you need to make the most of LabVIEW's powerful signal processing analysis tools.-- Covers both classica

616 115 72MB

English Pages 688 [683] Year 1998

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

LabVIEW Signal Processing [With Contains an Evaluation Version of LabVIEW 4.1]
 0139724494, 9780139724497

Table of contents :
Contents......Page 12
Preface......Page 22
Introduction......Page 38
Sampling Signals......Page 50
Quantization......Page 51
Sampling Considerations......Page 53
Why Do You Need Antialiasing Filters?......Page 57
Why Use Decibels?......Page 58
Activity 1-1......Page 60
Overview of the Analysis Library......Page 62
Real-World Application: Particle Impact Noise Detection (PIND) Testing of Pressure Sensors used in the Space Shuttle Main Engine......Page 68
Normalized Frequency......Page 84
Activity 2-1......Page 88
Wave and Pattern Vls......Page 90
Activity 2-2......Page 92
Activity 2-3......Page 95
Activity 2-4......Page 97
Real-World Application: Signal Processing in Industrial Testing......Page 105
The Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT)......Page 110
Frequency Spacing and Symmetry of the DFT/FFT......Page 115
Activity 3-1......Page 123
The Power Spectrum......Page 127
Activity 3-2......Page 131
Real-World Application: The Statistical Properties of Acoustical Fields in a Reverberation Room......Page 138
About Spectral Leakage and Smoothing Windows......Page 146
Characteristics of Different Types of Window Functions......Page 150
Activity 4-1......Page 160
Activity 4-2......Page 162
Activity 4-3......Page 165
Activity 4-4......Page 167
Real-World Application: Extracting Features from CTFM Sonar......Page 173
The Measurement Vls......Page 182
Calculating the Frequency Spectrum of a Signal......Page 183
Activity 5-1......Page 184
Coherent Gain (CG) and Equivalent Noise Bandwidth (ENBW)......Page 186
Activity 5-2......Page 191
Harmonic Distortion......Page 194
Activity 5-3......Page 198
Real-World Application: Periodic Signal Analyzer......Page 207
Real-World Application: Voltage Fluctuation on High Voltage Network......Page 212
Ideal Filters......Page 220
Practical (Nonideal) Filters......Page 222
Advantages of Digital Filters over Analog Filters......Page 225
IIR and FIR Filters......Page 226
Infinite Impulse Response Filters......Page 229
Activity 6-1......Page 237
Activity 6-2......Page 240
Activity 6-3......Page 244
The Transient Response of IIR Filters......Page 246
Activity 6-4......Page 249
Finite Impulse Response Filters......Page 251
Activity 6-5......Page 253
Digital Filter Design Toolkit......Page 256
Real-World Application: LabVIEW Exercise to Model and Analyze ECG/EKG Data......Page 262
About Curve Fitting......Page 276
Activity 7-1......Page 280
Activity 7-2......Page 282
Activity 7-3......Page 285
General Least Square Linear Fit......Page 287
Activity 7-4......Page 290
Activity 7-5......Page 294
Nonlinear Levenberg-Marquardt Fit......Page 297
Activity 7-6......Page 299
Fitting a Curve to Gaussian (Normal) Data Points......Page 303
Activity 7-7......Page 306
Real-World Application: LabVIEW Signal Processing in Biomechanics......Page 313
Linear Systems and Matrix Analysis......Page 326
Activity 8-1......Page 335
Activity 8-2......Page 341
Basic Matrix Operations and Eigenvalue-Eigenvector Problems......Page 344
Activity 8-3......Page 351
Activity 8-4......Page 354
Activity 8-5......Page 356
Matrix Inverse and Solving Systems of Linear Equations......Page 359
Activity 8-6......Page 362
Activity 8-7......Page 364
Matrix Factorization......Page 365
Activity 8-8......Page 367
Activity 8-9......Page 370
Real-World Application: Joint Time Frequency Analysis of Electromyographic Signals for Investigating Neuromuscular Coordination......Page 374
Real-World Application: The Science ToolBox®......Page 388
Probability and Statistics......Page 398
Statistics......Page 400
Activity 9-1......Page 410
Probability......Page 415
Activity 9-2......Page 421
Real-World Application: Signal Processing of Biomedical Data Using PC......Page 427
Linear, Time-Invariant Control Systems......Page 440
Activity 10-1......Page 449
Activity 10-2......Page 453
Frequency Domain Analysis......Page 457
Activity 10-3......Page 459
Nyquist Plot......Page 464
Root-Locus......Page 465
Activity 10-4......Page 467
Linear State Feedback......Page 471
Activity 10-5......Page 474
Real-World Application: Development of Full Order Observers and State Feedback Control for the Inverted Pendulum......Page 484
Review of Digital Filters......Page 500
The Digital Filter Design Toolkit......Page 502
Designing IIR Filters......Page 509
Activity 11-1......Page 514
Designing FIR Filters......Page 521
Activity 11-2......Page 525
Analyzing Your Filter Design......Page 533
Activity 11-3......Page 538
Format of Filter Coefficient Text Files......Page 544
Real-World Application: A Virtual Sound-Level Meter......Page 550
Organization of the G Math Toolkit......Page 560
Parser VIs......Page 561
Activity 12-1......Page 569
Activity 12-2......Page 572
Solving Differential Equations......Page 576
Activity 12-3......Page 580
Activity 12-4......Page 586
Activity 12-5......Page 590
Activity 12-6......Page 591
Activity 12-7......Page 594
Real-World Application: Using LabVIEW and the G Math Toolkit to Develop a User-Configurable Telemetry Program......Page 598
Real-World Application: An Interactive Instrumentation System for Wafer Emissivity Estimation......Page 608
Appendix A: Mathematical Background......Page 614
Appendix B: Error Codes......Page 620
Appendix C: Frequently Asked Questions......Page 632
Appendix D: References......Page 636
Appendix E: National Instruments Contact Information, Resources, and Toolkits......Page 640
Glossary......Page 662
C......Page 663
D......Page 664
H......Page 665
L......Page 666
N......Page 667
P......Page 668
R......Page 669
S......Page 670
V......Page 671
Z......Page 672
C......Page 674
D......Page 675
E......Page 676
G......Page 677
K......Page 678
M......Page 679
P......Page 680
S......Page 681
U......Page 682
Z......Page 683

Citation preview

There are two options for using LabVIEW Evaluation software in combination with this book: The LabVIEW Online Evaluation gives you the opportunity to explore the latest version of LabVIEW at your convenience without downloading or installing any software. (link to http://digital.ni.com/demo.nsf/websearch/ CE34B1339DE04F2086256E930074129F?OpenDocument&node=1381_US) To run any of the pre-built LabVIEW VIs included with this textbook, download a free trial version of LabVIEW to install on your machine. (link to http://www.ni.com/downloads/)

This page intentionally left blank

"I have always been impressed by Lab VIEW'S ease of use and friendly interface. It is exciting to know that Lab VIEW is supporting signal processing applications. LabVIEW Signal Processing makes your entry into Lab VIEW even easier through its simple, illustrative examples and clear descriptions. I highly recommend it for students in both academia and industry at all levels as the ideal introduction to LabVIEW." —Prof. Alan C. Bovik, Professor of Electrical and Computer Engineering, University of Texas at Austin "LabVIEW analysis provides built-in functionality that engineers and scientists have not even considered possible...and LabVIEW Signal Processing shows how to do it! The authors communicate a very complicated topic— very effectively. LabVIEW Signal Processing is much easier to understand than most books or texts that address these subjects. Value is added for the reader in extensive theory that one can understand as well as in how to do things in LabVIEW." —Lisa K. Wells, Author of Lab VIEW for Everyone "Between the first and last page of LabVIEW Signal Processing, I found a lot of material that improved my knowledge about topics such as signal theory in general, filter design, statistics, and, most importantly, about realworld applications. The examples in the real-world applications are given by LabVIEW users, and they show how the Analysis Library can be used in practical applications." —Prof. Jing Zhou, Dean and Professor, School of Civil Engineering and Architecture, Dalian University of Technology, Dalian, P.R. China "LabVIEW Signal Processing is not only a great refresher in signal processing for engineers, but it also serves as an excellent tutorial for nontechnical programmers who want to become more knowledgeable in the fundamentals of signal processing and advanced analysis. It combines well-written text with easy-to-follow examples to clearly explain traditionally difficult concepts while demonstrating how to maximize the power of LabVIEW in developing signal processing applications." —Jim Baker, Porter Technical Inc., Lexington Park, Maryland

"The theoretical concepts of signal processing are difficult for students and professionals without formal engineering training to understand. Most books on the subject are written in a style which makes it difficult to utilize the concepts in everyday real situations. The authors of LabVIEW Signal Processing have presented the material in a simple, straightforward way, thus making it easy to understand and utilize the program VIs associated with LabVIEW/BridgeVIEW. "The book is well-organized and the background sections provide the reader with the basic concepts and tools necessary for each chapter. The unique aspects of signal processing, starting with the basics and building to the more difficult, are clearly defined in each chapter. Care has been taken to reinforce the reader's knowledge base by providing many program examples. The CD-ROM accompanying the book will be of great help to researchers." —Robert M. Wise, Research Supervisor, University of Maryland, School of Medicine "LabVIEW Signal Processing provides a good discussion of digital signal processing with real world applications in LabVIEW that the reader can use as a basis for future experimentation. The authors have carefully chosen a lot of activities which show the reader how to use LabVIEW VIs for solving interesting problems. This book reflects the real power of the graphical programming paradigm for signal processing applications." —Prof. Norbert Dahmen, Fachhochschule Niederrhein (University of Applied Sciences), Krefeld, Germany

LabVIEW

Signal Processing

ISBN 0-13-972449-4

9780139»724497»

NATIONAL INSTRUMENTS-

VIRTUAL INSTRUMENTATION SERIES

Lisa K. Wells Jeffrey Travis

LobVIEW For Everyone

Mahesh L. Chugani

Abhay R. Samant

LabVIEW Signal Processing Rahman Jamal

Herbert Pichlik

LabVIEW Applications Barry Paton

Sensors, Transducers & LabVIEW

Michael Cerna

LabVIEW

Signal Processing Mahesh L. Chugani Abhay R. Samant Michael Cerna The CD that accompanied this book has been replaced by a web site that can be found at the following address: http://authors.phptr.com/aod/ Note that all references to the CD in the book now pertain to the web site.

Prentice Hall PTR, Upper Saddle River, NJ 07458 http://www.phptr.com

Library of Congress Cataloging-in-Publication Data Chugani, Mahesh. LabVIEW signal processing / Mahesh Chugani, Abhay R. Samant, and Michael Cerna. p. cm. — (Virtual instrumentation series) Includes index. ISBN 0-13-972449-4 (pbk.) 1. Signal processing—Digital techniques—Computer programs. 2. LabVIEW. 3. Computer graphics. I. Samant, Abhay R. II. Cerna, Michael. III. Title. IV. Series. TK5012.9.C485 1998 621.382'2—DC21 98-14696 CIP Editorial/Production Supervision: James D. Gwyn Acquisitions Editor: Bernard Goodwin Editorial Assistant: Diane Spina Marketing Manager: Kaylie Smith Manufacturing Manager: Alan Fischer Cover Design: Talar Agasyon Cover Design Direction: Jerry Votta Series Design: Gail Cocker-Bogusz © 1998 Prentice Hall PTR Prentice-Hall, Inc. A Pearson Education Company Upper Saddle River, NJ 07458

Prentice Hall books are widely used by corporations and government agencies for training, marketing, and resale. The publisher offers discounts on this book when ordered in bulk quantities. For more information, contact Corporate Sales Department, Prentice Hall PTR One Lake Street Upper Saddle River, NJ 07458 Phone: 800-382-3419; FAX: 201-236-7141 E-mail (Internet): [email protected]

All rights reserved. No part of this book may be reproduced, in any form or by any means, without permission in writing from the publisher. Printed in the United States of America 10987654 ISBN 0-13-972449-4

4th Printing

Prentice-Hall International (UK) Limited,London Prentice-Hall of Australia Pty. Limited, Sydney Prentice-Hall Canada Inc., Toronto Prentice-Hall Hispanoamericana, S.A., Mexico Prentice-Hall of India Private Limited, New Delhi Prentice-Hall of Japan, Inc., Tokyo Pearson Education Asia Pte. Ltd., Singapore Editora Prentice-Hall do Brasil, Ltda., Rio de Janeiro

To Aai and Bhai, the source of my inspiration —Abhay To Clara, the love of my life —Mahesh To Trad, with all my love and respect —Michael

This page intentionally left blank

Contents

Preface Introduction

xvii xxxiii

1 Background

1

Sampling Signals Quantization Sampling Considerations Why Do You Need Antialiasing Filters? Why Use Decibels?

1

2 4 8 9 vii

LabVIEW Signal Processing

viii Activity 1-1

11

Overview of the Analysis Library

13

Real-World Application

Particle Impact Noise Detection (FIND) Testing of Pressure Sensors used in the Space Shuttle Main Engine

19

2 Signal Generation

35

Normalized Frequency Activity 2-1

Wave and Pattern Vis

Activity 2-2 Activity 2-4

Activity 2-4

35 39 41 43 46 48

Real-World Application

Signal Processing in Industrial Testing

56

3 Signal Processing

61

The Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT) Frequency Spacing and Symmetry of the DFT/FFT

.61

Activity 3-1

74

66

Contents

ix

The Power Spectrum

78

Activity 3-2

82

Real-World Application

The Statistical Properties of Acoustical Fields in a Reverberation Room

89

4 Windowing

97

About Spectral Leakage and Smoothing Windows Windowing Applications Characteristics of Different Types of Window Functions

101

Activity 4-1

111

Activity 4-2

113

Activity 4-3 Activity 4-4

116 118

Real-World Application Extracting Features from CTFM Sonar

97 101

124

5 Measurement

133

The Measurement Vis Calculating the Frequency Spectrum of a Signal Activity

5-1

133 134 135

LabVIEW Signal Processing

X

Coherent Gain (CG) and Equivalent Noise Bandwidth (ENBW)

137

Activity 5-2

142

Harmonic Distortion

145 149

5-3 Activity 5-3

Real-World Application

Periodic Signal Analyzer

158

Real-World Application

Voltage Fluctuation on High Voltage Network

163

6 Digital Filtering

171

What Is Filtering? Ideal Filters Practical (Nonideal) Filters Advantages of Digital Filters over Analog Filters IIR and FIR Filters Infinite Impulse Response Filters

171 171 173 176 177

Activity 6-5

180 188 191 195 197 200 202 204

Digital Filter Design Toolkit

207

Activity 6-1 Activity 6-2

Activity 6-2

The Transient Response of IIR Filters

Activity 6-4

Finite Impulse Response Filters

Contents

xi

Real-World Application

LabVIEW Exercise to Model and Analyze ECG/EKG Data

.213

7 Curve Fitting

227

About Curve Fitting

227 231 233 236

Activity 7-1

Activity 7-2 Activity 7-3

General Least Square Linear Fit

238 241 245

Nonlinear Levenberg-Marquardt Fit

248 250

Activity 7-4 Activity 7-5 Activity 7-6

Fitting a Curve to Gaussian (Normal) Data Points Activity 7-7

254 257

Real-World Application

LabVIEW Signal Processing in Biomechanics

!64

8 Linear Algebra

277

Linear Systems and Matrix Analysis Activity 8-1 Activity 8-2

277 286 292

Basic Matrix Operations and Eigenvalue-Eigenvector Problems

295

LabVIEW Signal Processing

xii

Activity 8-5

302 305 307

Matrix Inverse and Solving Systems of Linear Equations

310

Activity 8-6

313

Activity 8-7

315

Matrix Factorization

316

Activity 8-8

318

Activity 8-9

321

Activity 8-3 Activity 8-4

Real-World Application

Joint Time Frequency Analysis of Electromyographic Signals for Investigating Neuromuscular Coordination Real-World Application The Science ToolBox ®

325

339

9

Probability and Statistics

349

Probability and Statistics Statistics

.349

Activity 9-1

,361

Probability

.366

Activity 9-2

372

.351

Contents

xiii Real-World Application

Signal Processing of Biomedical Data Using PC

378

10

Control Systems

391

Linear, Time-Invariant Control Systems Activity 10-1 Activity 10-2

Frequency Domain Analysis Activity 10-3

NyquistPlot Root-Locus

Activity 10-4

Linear State Feedback Activity 10-5

391 400 404 408 410 415 416 418 422 425

Real-World Application

Development of Full Order Observers and State Feedback Control for the Inverted Pendulum

435

11 Digital Filter Design Toolkit

451

Review of Digital Filters The Digital Filter Design Toolkit

451 453

xiv

LabVIEW Signal Processing

Designing IIR Filters

Activity 11-1

Designing FIR Filters

Activity 11-2

Analyzing Your Filter Design

Activity 11-3

Format of Filter Coefficient Text Files

460 465 472 476 484 489 495

Real-World Application

A Virtual Sound-Level Meter

501

12 G Math Toolkit

511

Organization of the G Math Toolkit Parser VIs

511

Activity 12-1

520

Activity 12-2

523

Solving Differential Equations

527

Activity 12-3

531

Activity 12-4 Activity 12-5

537

Activity 12-6 Activity 12-7

512

541 542 545

Real-World Application

Using LabVIEW and the G Math Toolkit to Develop a User-Configurable Telemetry Program

549

Contents

XV

Real-World Application

An Interactive Instrumentation System for Wafer Emissivity Estimation Appendix A

Mathematical Background

565

Appendix B

Error Codes

571

Appendix C

Frequently Asked Questions

583

Appendix D

References

587

Appendix E

National Instruments Contact Information, Resources,

and Toolkits

591

Glossary

613

Index

625

559

This page intentionally left blank

Preface: Good Stuff to Know before You Get Started

What Is LabVIEW? LabVIEW, or Laboratory Virtual Instrumentation Engineering Workbench, is a graphical programming environment based on the concept of data flow programming. This programming paradigm has been widely adopted by industry, academia, and research laboratories around the world as the standard for data acquisition and instrument control software. LabVIEW was aboard the mid-October 1993 Columbia space shuttle mission as part of a Macintosh-based research project which helps astronauts study space motion sickness. LabVIEW was used to analyze data received from the Mars Pathfinder. Researchers at the University of Maryland used LabVIEW to develop an applicaxvii

LabVIEW Signal Processing

xviii

tion software that resident physicians could use to perform cardiothoracic research. These and other success stories (visit our Web site at www.natinst.com for many more user solutions) show how a powerful software like LabVIEW can transform your computer into a virtual instrument which can then be used in any test and measurement application.

As shown in the above figure, there are three important components involved in test and measurement applications, namely, data acquisition, data analysis, and data visualization. LabVIEW features an easy-to-use graphical programming environment which covers these vital components. The data flow programming paradigm behind LabVIEW is different from the sequential nature of traditional programming languages. It cuts down the time spent in developing an application, thereby allowing scientists and engineers to better utilize their resources.

What Is Data Analysis? Data is essentially a set of numbers. You can acquire data in a number of ways. For example, the modem connected to your computer may receive a data stream consisting of only O's and 1 's. A basketball fan may create a data set containing the number

Preface

XIX

of points scored by his favorite player. An engineer may acquire signal data from an oscilloscope connected to the instrument that is being tested. In each of these cases, the data by itself does not reveal any important information. For example, the figure below on the left shows a bit stream received by your modem.

Before Analysis After Analysis

This bit stream by itself looks quite lifeless as it simply consists of O's and 1's. As shown above on the right, simple analysis on the data reveals that the bit stream actually transforms to the most beautiful word in the English language, "LOVE." As a second example, an engineer may acquire the signal (shown below on the left) from a data acquisition device.

Before Analysis

After Analysis

The signal by itself does not reveal any information. However, analysis on such a signal tells the engineer that the signal actually received is the sum of two sine waves of frequencies 48 Hz

LabVIEW Signal Processing

xx

and 110 Hz. These and other examples show that raw data does not always immediately convey useful information. Data analysis is required to transform the raw data, remove noise disturbances, correct for data corrupted by faulty equipment, or compensate for environmental effects, such as temperature and humidity.

LabVIEW's Analysis Capabilities The Lab VIEW Full Development System features the Analysis Library. The functions in this library are called Virtual Instruments (Vis). This library is also a part of BrigeVIEW, which is the graphical programming language for industrial automation applications. These Vis allow you to use classical digital signal processing and numerical analysis related algorithms without writing a single line of code. The LabVIEW block diagram approach and the extensive set of analysis Vis simplify the development of analysis applications. These Vis are arranged in subgroups, some of which are listed below: Signal Generation contains Vis for generating signals such as a sine wave, a square wave, a chirp signal, and white noise. Digital Signal Processing contains Vis for computing the Fast Fourier Transform (FFT), auto-correlation, cross correlation, power spectrum, and other functions. Windows contains Vis for implementing windows such as the Harming, Hamming, Blackman, exponential, and the flat top window. Curve Fitting contains Vis for performing a linear fit, an exponential fit, a general polynomial fit, and the general least square fit. Linear Algebra contains Vis for performing basic matrix operations, matrix inversion, and eigenvalues and eigenvector calculations.

Preface

xxi

In addition to the Analysis Library, there are a number of specialized toolkits developed by National Instruments. These toolkits are aimed at making new technologies in the area of signal processing, controls, and numerical analysis easy to learn and use. Some of these toolkits are the Digital Filter Design Toolkit, the Wavelet and Filter Bank Design Toolkit, the G Math Toolkit, and the Control and Simulation Software for Lab VIEW.

Objectives of This Book This book is written for students, scientists, researchers, and practicing engineers who are interested in learning how to use the Lab VIEW Analysis Vis in practical applications. It is also intended for Lab VIEW customers who want to choose intelligently between several similar options available for solving a problem, or for those who may need help interpreting their analysis results. Although the title of the book is LabVIEW Signal Processing, we have devoted several chapters to areas outside classical Digital Signal Processing (DSP) theory. One chapter covers the basics of Control System theory and also discusses some of the Vis in the Control and Simulation Software package. The chapter on curve fitting discusses different curve fitting algorithms such as linear fit and exponential fit. The chapter on linear algebra presents detailed material on the solution of general linear equations, eigenvalues and eigenvectors, singular value decomposition, QR decomposition, and Cholesky decomposition. In addition, this book includes an overview of specialized analysis toolkits devoted to specific application areas such as interactive design of digital filters (the Digital Filter Design Toolkit) and solution of mathematical problems (the G Math Toolkit). In each chapter of the book, we have included numerous activities which are aimed at practical usage of the Analysis Vis in realworld applications. Through these activities, you will learn to Build an arbitrary waveform generator by entering formulas directly on the front panel

xxii

LabVIEW Signal Processing

Avoid aliasing by properly choosing the sampling frequency Separate two signals very close in frequency but widely differing in amplitudes Predict the cost of producing a certain quantity of a product Remove noise from an electrocardiogram Determine stability of systems and design linear state feedback control systems In addition, this book covers the basic fundamentals necessary for understanding and interpreting your analysis results. General guidelines are provided to help you choose among several options that are available for selecting an appropriate data window, curve fitting algorithm, or filtering technique. This book is intended for readers who have taken an introductory course in digital signal processing and control systems. Familiarity with simple concepts such as signal representation in the time and frequency domains, Fourier transforms, different forms of system representation, and matrix and vector data types will be useful. However, a brief review of the basic concepts is provided in each chapter as a refresher. It is assumed that the reader is familiar with programming in Lab VIEW or at least knows how to read and understand LabVIEW's block diagram approach to graphical programming. It is not the purpose of this book to teach Lab VIEW, or discuss the algorithms of each and every VI in full detail. It is application oriented and does not go into the details of the graphical programming language. A very good reference for programming using Lab VIEW is the book LabVIEW For Everyone by Lisa Wells and Jeffrey Travis, which is also published by Prentice Hall. This book covers in detail all the aspects that you should know to create efficient LabVIEW programs.

Preface

xxj jj

Organization The book is organized into 12 chapters. These chapters have a special structure to facilitate learning: Overview, goals, and key terms describe the main ideas covered in the chapter. Activities at the end of each section reinforce the information presented in the discussion. Wrap It Up! summarizes important concepts and skills taught in the chapter. Additional activities at the end of each chapter give you more practice with the material that you have learned. Real-World Applications exposes you to solutions of practical problems using the analysis capabilities of LabVIEW. Here is a brief description of the type of discussion in each chapter: In Chapter 1, you will learn about sampling an analog signal, aliasing, and the need for antialiasing filters. It will provide the background in basic digital signal processing and discuss some simple concepts. Chapter 2 covers the theory behind some of the signal generation Vis. These Vis are used to generate signals such as a sine wave, a square wave, and others. It discusses the concept of normalized frequency and shows you how to build a simple function generator. In Chapter 3, you will learn the basics of transforming a signal from the time domain into the frequency domain. You will learn about the Discrete Fourier Transform (DFT), the Fast Fourier Transform (FFT), and the power spectrum, and how they are different from one another. Chapter 4 teaches different windowing techniques and how they affect the spectral characteristics of a signal. You will learn about the differences between various types of windows in the Analysis Library and the applications for which they are commonly used.

xxiv

LobVIEW Signal Processing

Chapter 5 shows you how to use the Vis in the Measurement subpalette to perform various signal processing operations such as calculating the amplitude and phase spectrum of a time-domain signal and determining the total harmonic distortion present in a signal. Chapter 6 introduces you to the world of digital filters. You will learn about the characteristics of different types of filters and how to use them in practical filtering applications. In Chapter 7, you will learn about the analysis Vis that are used to fit curves to data points. In particular, you will learn about the General Least Squares Linear Fit VI and the nonlinear LevenbergMarquardt Fit VI. Chapter 8 will expose to you the basic theory behind the Linear Algebra Vis in the Analysis Library and show you how to use them in different applications. Besides the simple matrix operations, you will learn about eigenvalues and eigenvectors, and the singular value decomposition. In Chapter 9, we will cover some of the fundamental concepts in probability and statistics such as the mean or average, variance, histogram, and the Normal distribution function. In Chapter 10, you will familiarize yourself with the theory behind the design and analysis of linear, time-invariant systems. You will learn to use tools for designing linear state feedback systems and graphically analyzing a control system. In Chapter 11, you will learn how to use the Digital Filter Design (DFD) Toolkit to design filters to meet required specifications. You will also see how to use the DFD Toolkit to analyze your filter design in terms of its frequency response, impulse and step responses, and its pole-zero plot. Chapter 12 covers the G Math Toolkit which is intended for use by scientists, engineers, and mathematicians to solve mathematical problems in a simple, quick, and efficient manner. You will learn about different types of parser Vis and about solving differential equations using the differential equation Vis. You will find a glossary, index, and appendices at the end of the book. In Appendix A, we provide the mathematical background which will be useful while reading the material in some of the chapters. Appendix B gives you a brief description about the er-

Preface

XXV

ror codes that you might encounter while running the Vis. Appendix C answers some of the frequently asked questions. In Appendix D, we list some of the references that might aid you in further understanding the theory discussed in this book. Information about how to contact National Instruments, and the various resources and toolkits available, can be found in Appendix E.

Conventions Used in This Book The following table describes the conventions used in this book: bold

Bold text denotes VI names, function names, menus, and menu items. In addition, bold text denotes VI input and output parameters, controls, and indicators. For example, "Select the Sine Wave VI from the Analysis » Signal Generation subpalette."

italic

Italic text denotes emphasis, or an introduction to a key term or concept. For example, "A matrix is orthogonal if its columns are orthonormal."

Courier

Courier type denotes text or characters that you enter using the keyboard, Lab VIEW library names, and folder or directory names. For example, "Save the VI in the library Activities . lib." Note. This icon marks information to which you should pay special attention.

Watch out! This icon flags a common pitfall or special information that you should be aware of in order to keep out of trouble. Tips and Hints. This icon calls your attention to useful tips and hints on how to do something efficiently.

LabVIEW Signal Processing

xxvi

Your Very Own Software Disk The CD-ROM included with this book contains an evaluation version of LabVIEW, additional software for the toolkits discussed in this book, activities, and solutions to the activities. The CD-ROM also contains software associated with the real-world applications in Chapters 5 (Measurement), 6 (Digital Filtering), 8 (Linear Algebra) and 10 (Control Systems). If you do not have the full version of LabVIEW already installed on your computer, you can use the evaluation version to work through all the activities in Chapters 1-9. The CD-ROM contains only a portion of the Control and Simulation Software for LabVIEW, the Digital

Preface

xxvii

Filter Design Toolkit, and the G Math Toolkit needed to work through the activities in Chapters 10,11, and 12 respectively. The folder structure on the CD-ROM is as follows: Activities and Solutions Activities.lib Solutions.lib Additional Software Digital Filter Design Toolkit Controls.lib GMath.llb LabVIEW Real-World Applications

How to Install the Software: 1. Install the LabVIEW evaluation software on your computer. To install this software, run the setup.exe program from the LabVIEW folder on the CD-ROM. Follow the instructions on the screen. If you already have the full version of LabVIEW installed, you do not need to install the evaluation version. 2. Create an Addons folder in your LabVIEW Vi . lib directory, if it does not already exist. 3. Copy Controls . lib and GMath. lib from the Additional Software folder on the CD-ROM to the Addons directory. 4. Copy the Digital Filter Design Toolkit folder from the Additional Software folder on the CD-ROM to your hard drive. 5. Copy the Real-World Applications folder from the CD-ROM to your LabVIEW folder. This folder contains software corresponding to the real-world applications in Chapters 5, 6, 8 and 10. 6. Copy the contents of the Activities and Solutions folder from the CD-ROM to your LabVIEW folder. This folder contains the libraries Activi-

LabVIEW Signal Processing

XXVIII

ties . lib and Solutions . lib. While performing the activities in this book, you will open and/or save Vis in Activities . lib. The solutions to the activities can be found in Solutions . lib. You will have to change the access permissions for both these libraries. To do so, follow the instructions below: a) Right click on either Activities . lib or Solutions . lib. b) Select Properties, then select General. c) Deselect the Read-only attribute. 7. Repeat Steps 6a, 6b, and 6c for the libraries Controls, lib and GMath.llb in the Vi.lib » Addons folder.

feaetffe contents of the rea> Signal Generation subpalette) VI.

54

LabVIEW Signal Processing

4. Open and run the Two Channel Oscilloscope VI from the Examples » Apps » Demos.llb library in your LabVIEW folder. The front panel is as shown:

This VI uses some of the Vis from the Signal Generation library to simulate waveforms that can be seen on the front panel of the oscilloscope. It simulates a noisy sine wave on channel B and a noisy square wave on channel A. a) The Channel control selects which waveform to display. Change the Channel control to its different settings (A, B, A & B) and observe the displayed waveform (s).

Signal Generation

55 b) The Position controls (Time Base and Volts/Div) are used to adjust the scaling in the x and y axes respectively. Modify these controls and observe the corresponding changes in the displayed waveform (s). c) The Trigger controls (Source, Slope and Level) select the triggering mode.

i) Leave the Source control on CH B and change the Slope control between POS (positive) and NEG (negative). Observe the changes in the left edge of the display. ii) Leave the Source control on CH B and change the Level control between positive and negative values. Again, observe the left edge of the display.

d) From the menu bar, select Project » This VI's sub Vis » Channel A and/or B (demo).vi. From the menu bar of the Channel A and/or B (demo).vi select Windows » Show Diagram. The block diagram shows how the noisy signals are generated using the Vis in the Signal Generation subpalette. e) When you finish, close the VI.

This activity can only be done with the LabVIEW full development

system.

56

Real World Applications

Signal Processing in Industrial Testing Using Lab VIEW™ Graham Douglas Systems Engineer–Controls

Delco Defense Systems Operations The Challenge To design and implement a stabilization test for armament systems. The Solution The LabView Analysis Vis and National Instruments' plug-in boards are used to build the system which would perform the stabilization test.

Figure 2-5 Rate stabilized 25-mm cannon industrial testing

Introduction Delco Defense Systems Operations develops armament systems like the two-axis stabilized Bushmaster cannon shown on the vehicle above. Stabilization keeps the gun pointing in inertial space as the vehicle traverses rough terrain. All these systems undergo a rigorous series of tests at the end of assembly to ascertain their correct functioning. A test of major importance is the rate stabilization frequency response, also known as Bode testing. In exercising a stabilized axis, LabVIEW is first used to drive the system with sinusoidal excitation and then to analyze the results. Swept sine wave testing has several advantages over pseudorandom noise in nonlinear systems. Each discrete frequency can have its own input amplitude, low enough to stimulate the system without running afoul of nonlinearities, yet high

Real World Applications

57

enough to have sufficient quantization from output sensor A/D and D/A converters.

Signal Processing and Analysis Figure 2-6 shows the use of the Sine PatternVI in conjunction with the AO Continuous ReGenVI to generate the Stimulus. Notice also that the amplitudes are increased as Ibe system response falls off at the higher frequencies. National Instruments' computer plug-in boards are used to generate the stimulus and gather the response. The MIQ-16L

Figure 2-6 Stimulus generation

Real World Applications

58

Figure 2-7 Extracting the response/stimulus

board can output a continuous signal while using Direct Memory Access (DMA) to gather the system's response. Finally we arrive at the most interesting part from a signal processing view—the extraction of magnitude and phase for use in the Bode chart. The current frequency enters the sequence frame at the bottom and is used by a formula node to provide a table of test cycles versus frequency. At higher frequencies the system response is falling off and more cycles are used to extract the output in the presence of industrial noise. The AI Waveform Input Scan block has channels zero and one identified as signal sources. A good workhorse, the Index Array block is used to split the 2D array into a ID array of singles. These arrays are operated on by the Cross Power Spectrum.vi which develops the cross-

Real World Applications

59

power spectrum. The upper output of this VI is in volts/rms squared while the lower output is the phase difference between the two inputs. The gunner's method of controlling the rate stabilized gun is by moving a handle while observing the target fcoagh a telescopic sight mounted on the same structure as the weapon, Remember that in the generation of the stimulus a DC component was added to the sine wave. The real-world necessity for adding this component was to avoid velocity reversals and the attendant coulomb friction nonlinearities. So, if we follow the signal labeled "Input to handle" we see that the DC component is removed by using the Mean.vi. The remainder of She magnitude of signal extraction is straightforward. The indexed output of the Cross Power Spectrum VI is divided by the square of the RMS handle input to provide the ratio of gyro output to handle input. The array of magnitude and phase outputs leave the sequence on the For Loop for processing into a logarithmic Bode chart. The chart is archived and several figures of merit, gain and phase margin, are presented to the operator for pass/fail comparison. • Contact Information

Graham Douglas

Systems Engineer-Controls Delco Defense Systems Operations 7410HollisterAv,Goleta,CA93117 805-961-7078 Fax:805-961-7242 Email: [email protected]

Overview In this chapter, you will learn the basics of transforming a signal from the time domain into the frequency domain.

GOALS

Learn about the Discrete Fourier Transform (OFF) and the Fast Fourier Transform (FIT). Determine the frequency spacing between the samples of the FFT (that is, the relationship between the sampling frequency fs, number of samples N, and the frequency spacing Af). Familiarize yourself with the power spectrum and how it differs from both the DFT and the FFT. Understand how to interpret the information in the frequency domain for the DFT/FFT and the power spectrum, for both even and odd N.

KEY TERMS

time domain frequency domain Fourier Transform sampling frequency

frequency spacing power spectrum zero padding

60

Signal aProcessing 3

The Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FIT) The samples of a signal obtained from a DAQ board constitute the time-domain representation of the signal. This representation gives the amplitudes of the signal at the instants of time during which it had been sampled. However, in many cases you want to know the frequency content of a signal rather than the amplitudes of the individual samples. The representation of a signal in terms of its individual frequency components is known as the frequency-domain representation of the signal. The frequencydomain representation could give more insight about the signal and the system from which it was generated. The algorithm used to transform samples of the data from the time domain into the frequency domain is known as the Discrete Fourier Transform or DFT. The DFT establishes the relationship between the samples of a signal in the time domain and their rep61

LabVIEW Signal Processing

62

resentation in the frequency domain. The DFT is widely used in the fields of spectral analysis, applied mechanics, acoustics, medical imaging, numerical analysis, instrumentation, and telecommunications. Suppose you have obtained N samples of a signal from a DAQ board. If you apply the DFT to N samples of this time-domain representation of the signal, the result is also of length N samples, but the information it contains is of the frequency-domain representation. Figure 3-1 shows both the time domain & frequency domain representations of 32 samples of a sine wave. The relationship between the N samples in the time domain and the N samples in the frequency domain is explained below.

time-domain representation

frequency-domain representation

Figure 3-1 Time domain and frequency domain representations of a sampled signal

If the signal is sampled at a sampling rate of fs Hz, then the time interval between the samples (that is, the sampling interval) is At, where

The sample signals are denoted by x[i], 0 < i < N - 1 (that is, you have a total of N samples). When the discrete Fourier transform, given by

is applied to these N samples, the resulting output (X[k], 0 For example, the actual polynomial in case (i) is given by

y = fl0 + ait + a2t2 + ... where the a,- are the curve parameters to be determined. To determine these parameters, it is necessary to solve a linear system of equations Va = y, where V is a matrix, a = [a0, alr ...], and y is the population vector. For each of these four representations, you can generate the matrix V, where the (f,;)th element of this matrix is given by

vi,j = ty'M) Such a matrix V is referred to as the Vandermonde matrix. For example, if you are using the polynomial

LabVIEW Signal Processing

288

representation (z) above, the Vandermonde matrix will look like

where £,• "year."

is the z'th element of the vector

Block Diagram

3. Open the block diagram for this VI and complete it as shown above, and discussed in the following steps.

Linear Algebra

289 Matrix Condition Number VI (Functions » Analysis » Linear Algebra » Advanced Linear Algebra subpalette). In this activity, this VI computes the matrix condition number. Determinant VI (Functions » Analysis » Linear Algebra subpalette). In this activity, this VI computes the matrix determinant. Matrix Rank VI (Functions » Analysis » Linear Algebra » Advanced Linear Algebra subpalette). In this activity, this VI computes the matrix rank. Bundle function (Functions » Cluster subpalette) In this activity, this function assembles the population array and the year array to plot the population array against the year array.

290

Lab VIEW Signal Processing

4. The subdiagrams in Case V, (t-1900)J, (t-1940)J, and —-JTT— construct the matrices corresponding to the polynomial functions (i), (ii), (Hi), and (iv), respectively. The subdiagrams in the first three cases, as shown above, are already built for you. You need only complete the subdiagram in Case —^jn— • 5. The Matrix Condition Number VI has an input

called norm type. Earlier in this chapter, you looked at different types of norms. This VI can compute the condition number using four different norm types. In this activity, norm type has been set to 2-norm. In case of a singular matrix, the condition number output may be set to NaN.

6. The Determinant VI has an input called matrix type. In this activity, matrix type has been set to General.

Linear Algebra

291 7.

The Matrix Rank VI has an input called tolerance. Leave this terminal unconnected, using the default value for this activity.

8. Return to the front panel and run the VI. Choose different polynomial functions using the polynomial function selector control. 9. Look at the condition numbers of the four matrices. Which one is very close to being singular? 10. Save and close this VI. 11. You will now use the matrices (computed in the Construct Matrices VI) to calculate the population for any year between 1900 and 1980. To do so, open the Compute Population VI from the library Activities . lib. This VI computes a polynomial to interpolate the data values to the population data. It then computes the population for a specified year. 12. Set the choose year control to 1950. Using each of the four polynomial functions, run the VI to compute the population for this year. The red dot on the population graph shows the population value for the year chosen. Which of these values is closest to the true value of 151,325,798, according to the 1950 census? 13. Save the VI and close it.

End of Activity 8-1

292

LabVIEW Signal Processing

Activity 8-2 Objective: To study special matrices

In this activity, you will learn to use the Create Special Matrix VI in the Analysis Library. Examine the different types of special matrices that this VI creates. Note that this VI also generates the Vandermonde matrix used in the previous activity.

Front Panel

1. Build the front panel as shown above. You can resize the two-dimensional matrices D, U, and L to see all the elements in the matrix.

Linear Algebra

293

Block Diagram

2. Build the block diagram as shown above. This block diagram is partially built for you. You will complete the remaining diagram as explained in steps 3, 4, and 5. Create Special Matrix VI (Functions » Analysis » Linear Algebra » Advanced Linear Algebra subpalette). In this activity, this function creates special matrices.

3. Construct Diagonal Matrix D using the Create Special Matrix VI. The matrix size input determines the

LabVIEW Signal Processing

294

4.

5.

6. 7.

8.

dimension size of the output Special Matrix. Choose matrix size = 6. The matrix type input determines the type of matrix that is generated at the output Special Matrix. Choose matrix type = Diagonal. Enter the diagonal elements 1, 2, 3, 4, 5, and 6 in the Diagonal Elements control on the front panel. Connect this control to the Input Vectorl terminal. The Input Vectorl terminal is the input to construct a special matrix depending on the matrix type chosen. Return to the front panel and run the VI. Compute the determinant of this matrix as you did in the earlier activity. Do you find anything interesting about this determinant value? If yes, what is it? If no, take a close look at the diagonal elements of the matrix D. Select the Upper Lower Symmetric Matrix VI from the library Activities. lib. This subVI can be found below the top level Vis. Set Select Matrix Type = 0 (upper triangular matrix). Set matrix Size = 6. Wire the matrix D to the input matrix terminal. The output matrix U is an upper triangular matrix.

9. Compute the determinant of this matrix. Do you find anything interesting about this determinant value? If yes, what is it? 10. Once again, select the Upper Lower Symmetric Matrix VI from the library Activities . lib. This time, choose Select Matrix Type = 1 (lower triangular matrix). Set matrix Size equal to 6. Wire the matrix D to the input matrix terminal. The output matrix L is a lower triangular matrix. Repeat step 9.

Linear Algebra

295 11. Save the VI as Special Matrix.vi in the library Activities.llb and close it. The deferminont for all the three matrices is equad to the product of the diagonal elements of e

End of Activity 8-2

Basic Matrix Operations and Eigenvalue-Eigenvector Problems In this section, we will discuss some very basic matrix operations. Two matrices, A and B, are said to be equal if they have the same number of rows and columns and their corresponding elements are all equal. Multiplication of a matrix A by a scalar a is equal to multiplication of all its elements by the scalar. That is,

For example,

Two (or more) matrices can be added or subtracted if and only if they have the same number of rows and columns. If both matrices A and B have m rows and n columns, then their sum C is an m-by-n matrix defined as C = A ± B , where For example,

LobVIEW Signal Processing

296

For multiplication of two matrices, the number of columns of the first matrix must be equal to the number of rows of the second matrix. If matrix A has m rows and n columns and matrix B has n rows and p columns, then their product C is an m-by-p matrix defined as C = AB, where for i = 0,1, ... m-1 and j= 0,1, ... p-1

For example,

So, you multiply the elements of the first row of A by the corresponding elements of the first column of B and add all the results to get the element in the first row and first column of C. Similarly, to calculate the element in the z'th row and the ;th column of C, multiply the elements in the z'th row of A by the corresponding elements in the jih column of B, and then add them all. This is shown pictorially in Figure 8-2. Matrix multiplication, in general, is not commutative. That is, AB * BA. Also, remember that multiplication of a matrix by an identity matrix results in the original matrix.

Figure 8-2 Pictorial representation of matrix-matrix multiplication

Linear Algebra

297

Dot Product and Outer Product If x represents a vector and y represents another vector, then the dot product of these two vectors is obtained by multiplying the corresponding elements of each vector and adding the results. This is denoted by

where n is the number of elements in x and y. Note that both vectors must have the same number of elements. The dot product is a scalar quantity and has many practical applications. For example, consider the vectors a = 2i + 4j and b = 2i+j in a two-dimensional rectangular coordinate system as shown in Figure 8-3. The dot product of these two vectors is given by

The angle a between these two vectors is given by

Figure 8-3 Two vectors in a rectangular coordinate system

LobVIEW Signal Processing

298 where I a I denotes the magnitude of a.

Figure 8-4

Force acting on a body causes displacement

As a second application, consider a body on which a constant force a acts. The work W done by a in displacing the body is defined as the product of I d t and the component of a in the direction of displacement d. That is,

On the other hand, the outer product of two vectors is a matrix. The (z./jth element of this matrix is obtained using the formula For example,

Eigenvalues and Eigenvectors To understand eigenvalues and eigenvectors, let us start with the classical definition. Given an n x n matrix A, the problem is to find a scalar X and a nonzero vector x such that Such a scalar A, is called an eigenvalue, and x is the corresponding eigenvector.

Linear Algebra

299 Calculating the eigenvalues and eigenvectors are fundamental principles of linear algebra. Completely understanding these principles allows you to solve many problems, such as systems of differential equations. Consider an eigenvector x of a matrix A as a nonzero vector that does not rotate when x is multiplied by A (except perhaps to point in precisely the opposite direction), x may change length or reverse its direction, but it will not turn sideways. Consider the following example. One of the eigenvectors of the matrix A, where A =

is

. Multiplying the

matrix A and the vector x simply causes the vector x to be expanded by a factor of 6.85. Hence, the value 6.85 is one of the eigenvalues of the matrix A. For any constant a, the vector ax is also an eigenvector with eigenvalue A,, because A(ocx) = ocAx= Aax In other words, an eigenvector of a matrix determines a direction in which the matrix expands or shrinks any vector lying in that direction by a scalar multiple, and the expansion or contraction factor is given by the corresponding eigenvalue. The following are some important properties of eigenvalues and eigenvectors: The eigenvalues of a matrix are not necessarily all distinct. In other words, a matrix can have multiple eigenvalues. All the eigenvalues of a real matrix need not be real. However, complex eigenvalues of a real matrix must occur in complex conjugate pairs. The eigenvalues of a diagonal matrix are its diagonal entries, and the eigenvectors are the corresponding columns of an identity matrix of the same dimension. A real symmetric matrix always has real eigenvalues and eigenvectors. As discussed earlier, eigenvectors can be scaled arbitrarily.

LabVIEW Signal Processing

300

There are many practical applications in the field of science and engineering for an eigenvalue problem. For example, the stability of a structure and its natural modes and frequencies of vibration are determined by the eigenvalues and eigenvectors of an appropriate matrix. Eigenvalues are also very useful in analyzing numerical methods, such as convergence analysis of iterative methods for solving systems of algebraic equations, and the stability analysis of methods for solving systems of differential equations. The LabVIEW/BridgeVIEW Eigenvalues and Vectors VI is shown in Figure 8.5. The Input Matrix is an n x n real square matrix. Matrix type determines the type of the input matrix. Matrix type could be 0, indicating a general matrix4", or \, indicating a symmetric matrix. A symmetric matrix always has real eigenvalues and eigenvectors.

Figure 8-5 Eigenvalues and Vectors VI with Input-Output terminals

Output option determines what needs to be computed. Output option = 0 indicates that only the eigenvalues need to be computed. Output option = 1 indicates that both the eigenvalues and the eigenvectors should be computed. It is computationally very expensive to compute both the eigenvalues and the eigenvectors. So, it is important that you use the output option can't. General matrix: A matrix with no special property such as symmetry or triangular structure.

Linear Algebra

301

trol in the Eigenvalues and Vectors VI very carefully. Depending on your particular application, you might just want to compute the eigenvalues or both the eigenvalues and the eigenvectors. Also, a symmetric matrix needs less computation than an unsymmetric matrix. So, choose the matrix type control carefully. In this section, you learned about some basic matrix operations and the eigenvalues-eigenvectors problem. The next activity introduces some Vis in the Analysis Library that perform these operations.

302

LobVIEW Signal Processing

Activity 8-3 Objective: To learn basic matrix operations

You will build a VI that will help you further understand the basic matrix operations discussed in the first part of the previous section. You will also learn some very interesting matrix properties.

Front Panel

1. Build the front panel as shown above. You can resize the two-dimensional matrices A, B, and C to see all the elements in the matrix. 2. In this activity, you will experiment with three different types of matrices, namely upper triangular, lower triangular, and symmetric matrix. You will use the

Linear Algebra

303 Upper Lower Syrnrnetric Matrix VI that you used in the previous activity.

Block Diagram

3. Build the block diagram as shown above. Create Special Matrix VI (Functions » Analysis » Linear Algebra » Advanced Linear Algebra subpalette). In this activity, this VI creates special matrices. AxB VI (Functions » Analysis » Linear Algebra subpalette) In this activity, this VI multiplies two matrices). 4. Create a diagonal matrix using the Create Special Matrix VI. Select the Upper Lower Symmetric Matrix VI from the library Activities . lib. This VI will create the appropriate type of matrix depending on the Select Matrix Type control. 5. Select the AxB VI from the Analysis » Linear Algebra subpalette. You will use this VI to multiply

LabVIEW Signal Processing

304

matrix A and matrix B and the result of this multiplication is stored in matrix C. 6. Return to the front panel. Choose Matrix A Size = 6 and Matrix B Size = 6. Set the Diagonal Elements A and Diagonal Elements B controls for both the matrices to some value (similar to what you did in the previous activity). The size of these arrays is equal to the matrix size. 7. Choose Select Matrix Type = 0 (Upper Triangular Matrix). Run the VI. Observe the structure of the upper triangular matrices A and B, whose upper nondiagonal elements are randomly chosen by the Upper Lower Symmetric Matrix VI. Matrix C is the product of these two matrices. Do you find anything interesting about the structure of this matrix? 8. Now choose Select Matrix Type = 1 (Lower Triangular Matrix). Run the VI. Observe the structure of the two lower triangular matrices A and B, whose lower nondiagonal elements are randomly chosen by the Upper Lower Symmetric Matrix VI. Matrix C is the product of these two matrices. Do you find anything interesting about the structure of this matrix? 9. Now choose Select Matrix Type = 2 (Symmetric Matrix). Run the VI. Observe the structure of the two symmetric matrices A and B. Matrix C is the product of these two matrices. Do you find anything interesting about the structure of this matrix? 10. Change the Matrix A Size to 5. Keep the Matrix B Size at 6. Run the VI. Why did you get an error5? 11. Save the VI as Matrix Multiplication.vi in the library Activities . lib and close it.

End of Activity 8-3 5. See Appendix B for a list of error codes.

Linear Algebra

305

Activity8-4 Objective: To study positive definite matrices

In many applications, it is advantageous to determine if your matrix is positive definite. This is because if your matrix is indeed positive definite, you can save a significant amount of computation time when using Vis to compute determinants, solve linear systems of equations, or compute the inverse of a matrix. All these Vis let you choose the matrix type, and properly identifying the matrix can significantly improve performance. In this activity, you will learn about complex positive definite matrices. A complex matrix is positive definite if and only if it is II

TT

Hermitian; that is, A = A , and the quadratic form x Ax > 0 for all nonzero vectors x. Note that the quadratic form results in a scalar value.

Front Panel

1. Build the matrix A and the rest of the front panel as shown in the front panel above. 2. Switch to the block diagram and use the Test Complex Positive Definite VI to check if this matrix is positive definite. Test Complex Positive Definite VI (Functions » Analysis » Linear Algebra » Complex Linear Algebra » Advanced Complex Linear

LabVIEW Signal Processing

306

Algebra subpalette). Use this VI to check if the input matrix A is positive definite. 3. Enter the vector x shown below in the control x.

4. Enter the complex conjugate ex of x in the control ex. (This part has not been completed in the front panel.) Complex conjugate of a+jb is a-jb 5. Switch to the block diagram. Compute the complex

matrix vector multiplication y = Ax.

Use the Complex A x Vector VI Complex A x Vector VI (Functions » Analysis » Linear Algebra » Complex Linear Algebra subpalette). This VI multiplies a complex input matrix and a complex input vector. 6. Compute the complex dot product of the vectors ex and y. That is, z = ex • y. Use the Complex Dot Product VI. Complex Dot Product VI (Functions » Analysis » Linear Algebra » Complex Linear Algebra subpalette). Use this VI to compute the dot product of two complex vectors. 7. You have now computed the product z = xHAx. What is the value of z? Does this result verify the above definition of complex positive definite matrices? 8. Compare your block diagram with the diagram shown.

Linear Algebra

307

Block Diagram

9. Save the VI as Positive Definite Matrix.vi in the library Activities . lib and close it.

End of Activity 8-4

Activity 8-5 Objective: To compute the eigenvalues and eigenvectors of a real matrix

As explained earlier, the eigenvalues-eigenvector problem is widely used in a number of different practical applications. For example, in the design, of control systems, the eigenvalues help determine whether the system is stable or unstable. If all the eigenvalues have nonpositive real parts, the system is stable. However, if any of the eigenvalues have a positive real part, it means that the system is unstable. If the system is unstable, you can design a feedback system to obtain the desired eigenvalues and ensure stability of the overall system. In Chapter 10 (Control Systems), you will perform an activity that describes such an application.

308

LabVIEW Signal Processing

In this activity, you will use the Eigenvalues and Vectors VI to compute all the eigenvalues and eigenvectors of a real matrix. You will also learn an alternative definition of eigenvalues and numerically verify this definition.

Front Panel

1. Build the front panel as shown above. You can resize the controls to view all the elements in the matrices A and Eigenvectors and the array Eigenvalues. The size of the matrix A is 10 x 10. Eigenvalues is a one-dimensional complex array of size 10 containing all the computed eigenvalues of the input matrix. Eigenvectors is a 10 x 10 complex matrix containing all the computed eigenvectors of the input matrix. The zth column of Eigenvectors is the eigenvector corresponding to the zth component of the Eigenvalues vector.

Linear Algebra

309 2.

Build the block diagram as shown below. Eigenvalues and Vectors VI (Functions » Analysis » Linear Algebra subpalette). In this activity, you will use this VI to compute the eigenvalues and the eigenvectors of the input matrix.

Block Diagram

3.

Matrix A is a real matrix consisting of randomly generated numbers. Use the Random Number (0-1) function from the Functions » Numeric subpalette to create this matrix. Use the Eigenvalues and Vectors VI to compute both the eigenvalues and the eigenvectors of this matrix. Remember to set the output option control to 1. Choose matrix type = General.

4.

Earlier in this section, you looked at the classical definition of eigenvalues and eigenvectors. A different and widely used definition of eigenvalues is as fol-

LabVIEW Signal Processing

310

lows. The eigenvalues of A are the values X such that det(A - IX) = 0, where del stands for the determinant of the matrix. In this activity, you will numerically verify the validity of this definition. Select the Check Definition VI from the library Activities. lib. The Round LED on the front panel will glow green if the definition is true and turn to red if the definition fails. 5. Return to the front panel and run the VI several times. You will notice that the eigenvalues can be real or complex numbers although the matrix is purely real. The same holds true for the eigenvectors. Furthermore, you will notice that complex eigenvalues of a real matrix always occur in complex conjugate pairs (that is, if oc+y'P is an eigenvalue of a real matrix, so is a -jp). 6. Did the definition stated above in step 4 always hold true? 7. Save the VI as My Eigenvalues and Vectors.vi in the library Activities . lib and close it.

End of Activity 8-5

Matrix Inverse and Solving Systems of Linear Equations The inverse, denoted by A 1, of a square matrix A is a square matrix such that A"1 A = AA"1 = I

where I is the identity matrix. The inverse of a matrix exists if and only if the determinant of the matrix is not zero (that is, it is nonsingular). In general, you can find the inverse of only a square matrix. You can, however, compute the pseudoinverse of a rectangular matrix, as discussed in the next section.

Linear Algebra

311

Solutions of Systems of Linear Equations In matrix-vector notation, a system of linear equations has the form Ax = b, where A is a n x n matrix and b is a given n-vector. The aim is to determine x, the unknown solution n-vector. There are two important questions to be asked about the existence of such a solution. Does such a solution exist, and if it does is it unique? The answer to both of these questions lies in determining the singularity or nonsingularity of the matrix A. As discussed earlier, a matrix is said to be singular if it has any one of the following equivalent properties: The inverse of the matrix does not exist. The determinant of the matrix is zero. The rows (or columns) of A are linearly dependent. Az = 0 for some vector z * 0. Otherwise, the matrix is nonsingular. If the matrix is nonsingular, its inverse A" exists, and the system Ax = b has a unique solution: x = A b regardless of the value for b. On the other hand, if the matrix is singular, then the number of solutions is determined by the right-side vector b. If A is singular and Ax = b, then A(x + Yz) = b for any scalar Y, where z is a nonzero vector such that Az = 0. Thus, if a singular system has a solution, then the solution cannot be unique. It is not a good idea to explicitly compute the inverse of a matrix, because such a computation is prone to numerical inaccuracies. Therefore, it is not a good strategy to solve a linear system of equations by multiplying the inverse of the matrix A by the known right-side vector. The general strategy to solve such a system of equations is to transform the original system into one whose solution is the same as that of the original system but is easier to compute. One way to do so is to use the Gaussian elimination technique. The three basic steps involved in the Gaussian elimination technique are as follows. First, express the matrix A as a product A = LU where L is a unit lower triangular matrix and U is an upper triangular matrix. Such a factorization is known as LU factorization. Given this, the linear system Ax = b can be expressed as LUx = b. Such a system can then be solved

312

LabVIEW Signal Processing

by first solving the lower triangular system Ly = b, where y = Ux, for y by forward-substitution. This is the next step in the Gaussian elimination technique. For example, if

then p - (r/a),q = (s - bp)/c. The first element of y can easily be determined due to the lower triangular nature of the matrix L. Then you can use this value to compute the remaining elements of the unknown vector sequentially. Hence, the name forward-substitution. The final step involves solving the upper triangular system Ux = y by back-substitution. For example, if

then n = q/c, m = (p - bri)/a. In this case, this last element of x can easily be determined and then used to determine the other elements sequentially. Hence, the name back-substitution. So far, this chapter has discussed the case of square matrices. Because a nonsquare matrix is necessarily singular, the system of equations must have either no solution or a nonunique solution. In such a situation, you usually find a unique solution x that satisfies the linear system in an approximate sense. The Analysis Library includes Vis for computing the inverse of a matrix, computing LU decomposition of a matrix, and solving a system of linear equations. It is important to identify the input matrix properly, as it helps avoid unnecessary computations, which in turn helps to minimize numerical inaccuracies. The four possible matrix types are general matrices, positive definite matrices6, and lower and upper triangular matrices. If the input matrix is square, but does not have a full rank (a rank-deficient matrix), then the VI finds the least square solution x. The least square solution is the one that minimizes the 2-norm of Ax - b. The same holds true also for nonsquare matrices.

6. A real matrix is positive definite if and only if it is symmetric and the quadratic form xrAx > 0 for all nonzero vectors x.

Linear Algebra

313

Activity 8-6 Objective: To compute the inverse of a matrix

You will build a VI that computes the inverse of a matrix A. Further, you will compute a matrix B, which is similar to matrix A. A matrix B is similar to a matrix A if there is a nonsingular matrix T such that B = T AT so that A and B have the same eigenvalues. Such a transformation, where B = T~ AT, is known as a similarity transformation. In control theory, as you will see later in Chapter 10 (Control Systems), similarity transformations are used to convert the normal state-space representation to the modal form representation. Although such a transformation alters the states of a system, it does not alter the input-output model. You will verify the definition of similar matrices in this activity.

Front Panel

1. Build the front panel as shown above. Matrix A is a 2 x 2 real matrix. Matrix T is a 2 x 2 nonsingular matrix that will be used to construct the Similar Matrix B.

LabVIEW Signal Processing

314

Block Diagram

2. Construct the block diagram as shown above. Inverse Matrix VI (Functions » Analysis » Linear Algebra subpalette). In this activity, this VI computes the inverse of the input matrix. AxB VI (Functions » Analysis » Linear Algebra subpalette). In this activity, this VI multiplies two two-dimensional input matrices. Eigenvalues and Vectors VI (Functions » Analysis » Linear Algebra subpalette). In this activity, this VI computes the eigenvalues and eigenvectors of the input matrix. 3. Return to the front panel, enter the values as shown in the controls Matrix A and Matrix T, and run the VI. Check if the eigenvalues of A and the similar matrix B are the same. 4. Save the VI as Matrix Inverse.vi in the library Activities . lib and close it.

End of Activity 8-6

Linear Algebra

315

Activity 8-7 Objective: To solve a system of linear equations

Many practical applications require you to solve a system of linear equations. A very important area of application is related to military defense. This includes analysis of electromagnetic scattering and radiation from large targets, performance analysis of large radomes, and design of aerospace vehicles having low radar cross sections (the stealth technology). A second area of application is in the design and modeling of wireless communication systems such as hand-held cellular phones. This list of applications goes on and on, and therefore it is very important for you to properly understand how to use the Vis in the Analysis Library to solve a linear system of equations.

Solve Linear Equations VI

1.

Use the Solve Linear Equations VI in the Functions » Analysis » Linear Algebra subpalette to solve the system of equations Ax = b where the Input Matrix A and the Known Vector b are

Choose matrix type equal to general. 2. Use A x Vector.vi to multiply the matrix A and the vector x (output of the above operation) and check if the result is equal to the vector b above.

LabVIEW Signal Processing

316

3. Save the VI as Linear System.vi in the library Activities . lib and close it.

End of Activity 8-7

Matrix Factorization The previous section discussed how a linear system of equations can be transformed into a system whose solution is simpler to compute. The basic idea was to factorize the input matrix into the multiplication of several, simpler matrices. You looked at one such technique, the LU factorization technique, in which you factorized the input matrix as a product of upper and lower triangular matrices. Other commonly used factorization methods are Cholesky, QR, and the Singular Value Decomposition (SVD). You can use these factorization methods to solve many matrix problems, such as solving linear systems of equations, inverting a matrix, and finding the determinant of a matrix. If the input matrix A is symmetric and positive definite, then an LU factorization can be computed such that A = U U, where U is an upper triangular matrix and L = UT. This is called Cholesky factorization. This method requires only about half the work and half the storage compared to LU factorization of a general matrix by Gaussian elimination. As you saw earlier in Activity 8-4, it is easy to determine if a matrix is positive definite by using the Test Positive Definite VI in the Analysis Library. A matrix Q is orthogonal if its columns are orthonormal, that is, if QTQ = I, the identity matrix. The QR factorization technique factors a matrix as the product of an orthogonal matrix Q and an upper triangular matrix R. That is, A = QR. QR factorization is useful for both square and rectangular matrices. A number of algorithms are possible for QR factorization, such as the Householder transformation, the Givens transformation, and the fast Givens transformation. The Singular Value Decomposition (SVD) method decomposes a matrix into the product of three matrices: A = USV . U and V are

Linear Algebra

317 orthogonal matrices. S is a diagonal matrix whose diagonal values are called the singular values of A. The singular values of A are the nonnegative square roots of the eigenvalues of A A, and the columns of U and V, which are called left and right singular vectors, are orthonormal eigenvectors of AAT and A^A, respectively. SVD is useful for solving analysis problems such as computing the rank, norm, condition number, and pseudoinverse of matrices.

Pseudoinverse The pseudoinverse7 of a scalar a is defined as I/a if a ^ 0, and zero otherwise. You can now define the pseudoinverse of a diagonal matrix by taking the scalar pseudoinverse of each entry. Then the pseudoinverse of a general real m x n matrix A, denoted by At, is given by At = VStU T where S is a diagonal matrix. Note that the pseudoinverse exists regardless of whether the matrix is square or rectangular. If A is square and nonsingular, the pseudoinverse is the same as the usual matrix inverse. The Analysis Library includes a VI for computing the pseudoinverse of real and complex matrices.

7. In case of scalars, pseudoinverse is the same as the inverse.

318

LobVIEW Signal Processing

Activity 8-8 Objective: To compute Cholesky decomposition and QR decomposition

Activity 8-4 discussed complex positive definite matrices. You verified that the matrix A

is a positive definite matrix. In this activity, compute the Cholesky decomposition of this matrix. Also, compute the QR decomposition of a matrix B.

Front Panel

1. Build the front panel as shown above. You can resize the array of controls to see all the elements of the matrix. 2. The matrix U is an upper triangular matrix that is the result of the Cholesky Decomposition of the matrix A.

Linear Algebra

319 3. The matrix B is a rectangular matrix. That is, the number of rows m is different from the number of columns n. The result of the QR factorization is anmxm orthogonal matrix Q and an upper triangular matrix R of size m x n. 4. In this activity, you will also verify the definition of orthogonal matrices, QTQ = I. The indicator Result matrix contains the product of the transpose of the orthogonal matrix and the orthogonal matrix itself.

Block Diagram

5. Build the block diagram as shown above. Complex Cholesky Factorization VI (Functions » Analysis » Linear Algebra » Complex Linear Algebra » Advanced Complex Linear Algebra subpalette). In this activity, this VI computes the Cholesky decomposition of the positive definite input complex matrix.

LobVIEW Signal Processing

320

QR Factorization VI (Functions » Analysis » Linear Algebra » Advanced Linear Algebra subpalette). In this activity, this VI computes the QR factorization of the input real matrix. 6. Select the Complex Cholesky Factorization VI. The output terminal of this VI is connected to the indicator Matrix U. 7. Generate a random matrix B. Select the QR Factorization VI. Connect the matrix B as the input matrix for QR factorization. Connect the Q and R outputs of this VI to the indicators Matrix Q and Matrix R, respectively. 8. Compute the transpose of the matrix Q and then multiply this transpose with the original matrix Q. The result of this operation is connected to the indicator Result Matrix.

The Transpase 2D Array function is in the Functions Array subpalette.

9. Choose a value for the number of rows and the number of columns. Run the VI. Notice the upper triangular structure of the output of the Cholesky decomposition and the R output of the QR factorization. You can run the VI a number of times to generate different matrices and check if this definition is true. 10. Save the VI as QR Factor.vi in the library Activities . lib and close it.

End of Activity 8-8

Linear Algebra

321

Activity 8-9 Objective- To compute singular value decomposition

^n tms activity, you will compute the singular value decomposition of the following matrix.

Use the SVD Factorization VI from the Analysis » Linear Algebra » Advanced Linear Algebra subpalette. Compute the rank of the matrix A using the Matrix Rank VI (Analysis » Linear Algebra » Advanced Linear Algebra subpalette). Do you see an interesting relation between the rank of this matrix and the number of nonzero singular values? (The singular values are stored in the one-dimensional array s.) Now compute the 2norm of this matrix using the Matrix Norm VI (Analysis » Linear Algebra » Advanced Linear Algebra subpalette). Do you see an interesting relation between this number and the largest singular value of the matrix? The rank of a matrix is equal to the number of nanzero singular values, whicj in this example is equal to 2. Also, as discussed at the beginning of this hapter, the 2-norm of a matrix is equal to its larget singular valu.

End of Activity 8-9 Wrap It Up! A matrix can be considered as a two-dimensional array of m rows and n columns. Determinant, rank,

LabVIEW Signal Processing

322

and condition number are some important attributes of a matrix. The condition number of a matrix affects the accuracy of the final solution. The determinant of a diagonal matrix, an upper triangular matrix, or a lower triangular matrix, is the product of its diagonal elements. Two matrices can be multiplied only if the number of columns in the first matrix is equal to the number of rows in the second matrix. An eigenvector of a matrix is a nonzero vector that does not rotate when the matrix is applied to it. Similar matrices have the same eigenvalues. The existence of a unique solution for a system of equations depends on whether the matrix is singular or nonsingular.

Review Questions 1. For the matrix given by A =

calculate its

rank, determinant, 1-norm, and inf-norm. Which LabVIEW/BridgeVIEW VI(s) could you use to check your answer? 2. The condition number of a matrix B is 15.3, and that of a matrix C is 30,532. Which of these matrices, B or C, is closer to being singular? 3. Which of the following is true, and which is false? a) The eigenvalues of a real matrix are always real. b) The rank of an m X n matrix could at most be equal to the larger of m or n (m & «).

4. For the two vectors given by x = [1,2] and y = [3,4], calculate:

Linear Algebra

323 a) Their dot product b) Their outer product c) The angle between the two vectors Which LabVIEW/BridgeVlEW VI(s) could you use to check your answer? 5. Which VI could you use to check if a matrix is positive definite? Why might you want to make such a check? 6. Why is matrix factorization important? Which are the matrix factorization Vis available in LabVIEW/ BridgeVIEW?

Additional Activities 1. Use the Create Special Matrix VI in the Analysis Library to create a Toeplitz matrix and a Vandermonde matrix. Use the following data: Input Vector 1 = [ 1.2 2.9 1.8 3.7 4.2]. Use the Matrix Condition Number VI, Determinant VI, and the Matrix Norm VI in the Analysis Library to compute the condition number, determinant, and norm of the Vandermonde matrix and the Toeplitz matrix. 2. Consider a plant design in which the matrix A of the state space representation x = Ax + Bu is given by

(See Chapter 10 on control systems for more details.) Use the Eigenvalues and Vectors VI to compute the eigenvalues and the eigenvectors of the matrix. Based on the location of the eigenvalues, comment on the stability of the system.

LabVIEW Signal Processing

324

3. Consider the following set of equations: jq + 3x2 + 2x^ + 5x4 = 2

6x^ + XT + 2x^ + 3jc4 = 5 4xj + 6*9 + 3.T3 + x4 = 1 jCj + 5.T., + 2x3 + 4x4 = 1

This set of equations can be put in matrix form as Ax = b, where A is a 4 x 4 matrix, b is a 4 x 1 right-handside vector, and x is a 4 x 1 vector consisting of the unknowns xl7 x2, £3, x^. Compute the determinant of the matrix A. Is this matrix singular? Is there a unique solution for the system of equations? If yes, use the appropriate VI from the Analysis Library to compute the solution (method 1). As a second approach, use the appropriate VI to compute the inverse of matrix A and then multiply this inverse by the vector b to compute the vector x (method 2). Are both the solutions same? Which of the two methods is the proper technique for solving the linear system of equations and why? 4. Repeat Activity 8-9 with the following matrix:

Real World Applications

325

Joint Time Frequency Analysis of Electromyograpkic Signals for Investigating Neuromuscular Coordination

Lawrence D. Abraham, Ed.D.

Associate Professor, Kinesiology & Health Education, Biomedical Engineering, Neuroscience The University of Texas at Austin, Austin, TX 78712 USA Ing-Shiou Hwang, M.S., PI Doctoral Candidate in Biomedical Engineering The University of Texas at Austin Austin, TX 78712 USA The Challenge Investigating changes in neural activation of individual muscles during dynamic human movement offers great potential benefit in basic research and clinical neurology and physical rehabilitation settings. However the most commonly available measure, surface electromyography, represents muscle activation as a complex combination of biosignal amplitude and frequency. The challenge is to determine instantaneous changes in signal frequency. The Solution Using Lab VIEW'S JTFA Toolkit we are performing joint time frequency analysis to calculate the instantaneous median frequency of surface EMG signals, which represents an important factor in muscle activation.

Introduction Human neuromuscular coordination is studied by scientists and clinicians who are seeking to understand, restore, and improve the way we move. A basic premise is that the specific temporal pattern of muscle activation throughout the body, regulated by the nervous system, determines the exact movement produced. Yet it is extremely difficult to accurately and quantitatively assess the mechanisms underlying movement. Whether the application is in rehabilitation medicine, sports, or ergonomics, there are no ideal methods for measuring the activation patterns of individual muscles or of the neural elements which regulate muscle function. The most common tool for approaching this

326

Real World Applications

problem has been electromyography (EMG), recording the weak bioelectrical signals generated by activated muscle fibers, to provide an indication of the intensity of muscle activation. However traditional methods of analyzing EMG signals have not been very successful in elucidating underlying mechanisms of coordination during dynamic movement. We describe here the application of a powerful new signal processing technique, using Lab VIEW, which has the potential to greatly enhance our ability to use EMG to study patterns of neuromuscular coordination.

Traditional EMG Analysis First, let's take a quick look at what EMG is. When skeletal muscle contracts, each of the many fibers activated generates a small voltage potential. Greater contraction effort involves recruitment of more fibers as well as a more rapid "firing" rate in active fibers, and the individual potentials sum at any recording site to a signal of varying amplitude and frequency. There are several recording techniques for acquiring EMG signals, including intramuscular needles, intramuscular fine wires, and surface recording electrodes. Usually these electrodes (signal detection surfaces) are either bipolar or multipolar, yielding a differential, biphasic signal which reflects the instantaneous difference in electrical potential between two or more sites. Since the bioelectric potentials generated in the active muscle fibers spread easily throughout most body tissues, proper arrangement of the recording lead surfaces can help to localize the area from which signals are detected. Intramuscular electrodes tend to have the recording sites closer together, yielding a higher frequency signal and detecting signals from a smaller volume of muscle. However surface electrodes are far more commonly used, particularly during analysis of voluntary movement, because of ease of application, less risk of medical complications, and less interference with actual muscular contraction and movement. Surface EMG typically contains lower frequency signals because of spatial filtering of the volume-conducted potentials between

Real World Applications

327

the muscle fibers of origin and the electrode surface affixed to the overlying skin. Surface EMG records also tend to include Signals from a larger volume of muscle tissue, since the electrodes are larger and farther apart than those used intracmuscolarly. So surface EMG signals are biphasic signals originating in underlying muscle and representing the intensity of activation by modulations in amplitude and frequency (for a more detailed discussion of surface EMG, see DeLuca, 1997). To study human neuromuscular coordination we must simultaneouslyJ record from several muscles and examine the patterns A of activation. The central nervous system has many interconnections among its active elements which provide for unique temporal and spatial patterns of muscle activation for each unique movement. Since it is extremely difficult and/or risky to record the activity of these individual neural elements during voluntary movement, we normally must infer from EMG records how the underlying neural elements are orchestrating the muscular action. Specific patterns of activity which are used repeatedly are commonly referred to as synergies and are thought to reflect patterns of connectivity among underlying neural elements,' One way to investigate human coordination is by looking lot common aspects of activation among multichannel EMG recordings. Two aspects of EMG signals are fairly easily studied: relative timing and amplitude. We study relative timing by simply using threshold detectors to determine when the signal rises above or returns to some baseline level of background activity. This information reveals which muscles are activated simultaneously, sequentially, or perhaps alternately. We study amplitude (as a measure of intensity of contraction) using the root mean square (RMS) value of the signal (with a window of length around 25ms) with respect to the baseline value. Intensity of activity is also studied by examining the frequency of the signal, but traditional techniques for EMG frequency analysis have not been particularly satisfactory.

328

Real World Applications

Problems With Traditional Analysis of EMG Frequency During the course of a movement, activation of each muscle increases and decreases as the demand for muscle force varies. Early attempts to study EMG signal frequency using traditional Fourier transform-based power spectral analysis reported average frequency characteristics during an entire contraction. The results clearly showed that as the level of muscle activation increased, measures such as the median frequency also increased, reflecting (we assume) both increased recruitment of motor units and also increased individual unit firing rate. Using such data several investigators have shown a linear relationship between frequency and isometric (constant muscle length) force production (e.g. Woods & Bigland-Ritchie, 1983). Such data have been useful in assessing relationships between activation level and force output during a steady, invariant contraction, but do not provide any information about changes in recruitment during typical dynamic movement. To try to address this latter question, some investigators have tried short time Fourier transform (STFT) techniques (e.g. Hannaford et al, 1986). Unfortunately this approach often yields poor resolution of the spectrum and biased instantaneous frequency estimation because of a fixed moving window regardless of the signal properties. In addition, it fails to preserve finite support in the time domain, an important requirement for understanding motor synergy (Cohen, 1995). More recently several short-time-based parametric approaches have been tried, such as the auto-regression (AR) model (Kiryu, 1992). However AR analysis is best suited to reflect drastic changes in signal frequency (Devedeux et al., 1994) and requires numerous repeated measures and a lengthy data segment to ensure converged AR parameters (Box et al, 1994). Our solution to these problems is to employ a relatively new dynamic spectral analysis technique known as joint time frequency analysis (JTFA) which is being used to analyze nonstationary signals, including other biosignals such as the electroencephalogram (EEC) and heart sounds (Williams et al., 1995; Wood et al., 1995; Sun et al., 1996). In addition to allowing us to examine modest changes in EMG signal spectrum over time, this

Real World Applications

329

method also allows us to calculate the time history of the median frequency to represent the changing frequency instantaneously.

Research Methods We describe here an initial experiment to examine two or more EMG signals for evidence of synergistic control, reflected in similar simultaneous patterns of EMG signal frequency changes over time. The subjects are strapped in a comfortable feat with one leg fixed to an isokinetic dynamometer (Biodex Medical Systems, Inc.) which allows movement against resistance %t only one joint (in our case, the ankle). The dynamometer is set'to allow a specific joint angular velocity and records the torque generated by the subject trying to move against the velocity-regulating resistance. The EMG signals are collected using preamplified surface electrodes (Motion Control, lomed Corp., = 360^ bandwidth = 8Hz - 26Khz, CMRR = lOOdB, DC input i»pedanc« = 100MQ). The analog electrode output signals are led through an analog bandpass filter (6Hz - 400Hz) to limit artifactual features in the frequency content, and then sampled at IKhz using a National Instruments AT-MIO-16E board in a PowerMac 7100 / 66 computer. The data are stored in raw data files, using a data collection virtual instrument (VI) developed in Lab VIEW 4, and then analyzed off-line using a second Lab VIEW VI. The data are collected during voluntary maximal isokinetic contraction of one muscle group at the ankle, through the full range of ankle motion, while EMG signals are collected from muscles controlling both the ankle and the knee. We then attempt to determine whether the involuntary activity which usually appears in the knee muscles is modulated in the same way as the activity in the primary muscle used to perform the task. The JTFA method requires selection of an appropriate kernel function to reflect the fundamental waveform shape. We have chosen a cone-shaped kernel based on typical values for peak width and amplitude of a single motor unit action potential "signature", the fundamental element in EMG signals (Zhao, Atlas & Marks, 1990). We also have chosen an interference suppression

330

Real World Applications

parameter for the EMG time-frequency distribution of 1, to minimize distortion of the typically highly variable EMG signal. Furthermore, and importantly, a cone-shaped kernel allows preservation of finite support in the time domain for expression of the EMG time-frequency distribution. From the JTFA results, we then calculate the instantaneous median frequency of the signal, which we can compare statistically with the median frequency of other muscles to determine whether they exhibit similar timevarying patterns. The instantaneous median frequency indicates the recruitment strategy of motor units in an activated muscle (Solomonow et al., 1987). The resolution in the frequency domain of the time-varying spectrum analysis is equal to the Nyquist frequency divided by 2n (n=8). The resolution in the time domain is 2n ms (in our case we choose n=4), constrained by the uncertainty principle. The mathematical expression of JTFA with a coneshaped kernel is expressed as follows: The general form of JTFA is

where (p(9,r) is a two dimensional function called the kernel function. The selection of a cone-shaped distribution refers to Devedeux and Duchene's work (1994) which compares different EMG time frequency distributions. The cone-shaped function ( 0 for all x. The area under the probability density function graph is equal to one. Notice from Equation 9.1 that for a specific value of the continuous random variable, that is for X = a,

Probability and Statistics

369

It should not be surprising that you assign a probability of zero to any specific value, because there are an infinite number of possible values that the random variable can take. Therefore, the chance that it will take on a specific value X = a is extremely small. The previous example used the exponential function model for the probability density function. There are a number of different choices for this function. One of these is the Normal distribution, which we will discuss next.

Normal Distribution The Normal distribution (as you have already seen in the chapter on Curve Fitting) is one of the most widely used continuous probability distributions. This distribution function has a symmetric bell shape, as shown in Figure 9-15. The curve is centered at the mean value x = 0, and its spread is measured by the variance s2 = 1. These two parameters completely determine the

Figure 9-15 Graphical representation of a Normal density function

LabVIEW Signal Processing

370

shape and location of the Normal density function, whose functional form is given by

Suppose a random variable Z has Normal distribution with mean equal to zero and variance equal to one. This random variable is said to have standard normal distribution. The Normal Distribution VI in the Analysis Library computes the one-sided probability, p, of the normally distributed random variable x, p = Prob(X, (t), x2(t), ..., xn(t)]. These state variables determine the future behavior of a system when the present state of the system and the excitation signals are known. Consider a dynamic system with state variables xlt jc2, ...,xn . It has two inputs MJ, u 2 and two outputs y^y-, as shown in Fig-

Control Systems

399

figure 10-7 A dynamic system with two inputs and two outputs

ure 10-7. The state of this system can be described by the set of first-order differential equations written in terms of the state variables. These first-order differential equations can be written in general form as

n^] + 0)2*2 + °13X3 + ^11M1 + ^12M2 -X-2 ^ t/niXi T dryyUij \ Cl'j'jX'^ ~\~ t?71 Ml ~"~ £?'-)o Mo

X3 = a31-*l + a32x2 + ^33^3 + ^31 Ml + ^32M2

where x(f) = dx/dt . This set of simultaneous equations can be written in matrix form as follows

The column vector consisting of the state variables is called the state vector and is written as

The vector of input signals is referred to as u. Then the system can be represented by the compact notation of the state differential equation as

4QQ

LabVIEW Signal Processing

x = A x + Bu

(10.4)

This differential equation is also commonly called the state equation. This equation relates the rate of change of the state of the system to the current state of the system and the input signals. In general, the outputs of the linear system can be related to the state variables and the input signal by the state equation y = Cx + Du

(10.5)

The set of Equations 10.4 and 10.5 that describes the unique relations between the input, output, and state is often referred to as the dynamical equation. One example of a dynamic system can be an RLC circuit with voltage and current sources. In this case, the inputs can be the voltage and current, the states can be chosen as the voltage across the capacitor and the current flowing through the inductor, and the output can be chosen as the voltage across the resistor. In this section, you have learned about different types of representations for linear, time-invariant systems. The type of representation chosen depends on the application and how the system is defined. As shown in the activities that follow, you can use the Vis in the Control and Simulation Software to convert from one type of representation to another. Follow the instructions in the preface to install this software which can be found on the CD-ROM at the back of this book.

Activity 10-1 Objective- To draw In ^n the analysis of control systems, it is often required to deterthe pole-zero plot for mine the location of the poles and zeros of the system on the a system given it pole-zero plot. The location of the poles of the system gives us transfer function valuable information about the stability of the system. (We will representation discuss stability in more detail later on in this chapter.)

In this activity, you will learn how to use the Vis in the Control and Simulation Software to compute the poles and zeros of the system. We will assume that we have the transfer function representation of the system in the Laplace domain.

Control Systems

401

Front Panel

1. Build the front panel as shown in the figure above. 2. The array control Numerator will hold the coefficients of the numerator of the transfer function of the system. The first element in the array will contain the lowest-order (constant term) coefficient, the second element will contain the first-order coefficient, and so on. 3. The array control Denominator will hold the coefficients of the denominator of the transfer function of the system. The first element of the array will contain the lowest-order (constant term) coefficient, the second element will contain the first-order coefficient, and so on. 4. The array indicator Zeros and Poles will contain the zeros and poles of the system after the VI has been run. 5. The XY Graph Zero-Pole Plot will plot the poles and zeros of the system in the complex s-plane.

LabVIEW Signal Processing

402

Block Diagram

6. Switch to the block diagram and complete it as explained in the next three steps. 7. Choose the GSim Compute Poles VI (Functions »GSim subpalette). Wire the array control Denominator to the Alphas input. Wire the output Poles to the array indicator Poles and the output Error to the indicator Errorl.

GSim Compute Poles.vi

8 Choose the GSim Compute Zeros VI (Functions »

GSim subpalette). Wire the array control Numerator to the Betas input. Wire the output Zeros to the array indicator Zeros, the output Gain Constant to the indicator Gain Constant, and the output Error to the indicator ErrorZ.

GSim Compute Zeros.vi

Control Systems

403

9. Build the rest of the block diagram as shown in the figure above. This is needed for separating the real and imaginary parts of the complex poles and zeros and then plotting them on the XY Graph Zero-Pole Plot. 10. Increase the size of the Legend of the XY Graph, so that it shows two plots, Plot 0 and Plot 1. Pop up on Plot 0 in the Legend, and select Common Plots so that only the points are displayed. Also, in the Legend of Plot 0, select Point Style so that the points are displayed as circles. Similarly, pop up on Plot 1 in the Legend, and select Common Plots so that only the points are displayed. Also, in the Legend of Plot 1, select Point Style so that the points are displayed as x's. 11. You will compute the poles and zeros of the system whose transfer function representation is

Switch to the front panel and enter the numerator and denominator coefficients as shown on the front panel. As explained earlier, the first element of the array Numerator is 6 (the constant term in the numerator), the second element of the array is 5, and so on. Similarly, the first element of the array Denominator is 10 (the constant term in the denominator), the second element of the array is 9, the third element is 7, and the fifth element is 1. Note that the fourth element of the array is zero (since the coefficient of s3 is zero). 12. Run the VI. The VI computes the poles and zeros of the system and then plots them on the Zero-Pole Plot. The zeros are represented by a circle and the poles are represented by an "x." You will see that the system has two zeros at -2 and -3 and four poles. You will also observe that complex valued poles appear in complex conjugate pairs.

LabVIEW Signal Processing

404

13. Save this VI as Zeros Poles.vi in the library Activities . lib and close it.

End of Activity 10-1 Activity 10- 2 Objective: To study conversion from one type of system representation to another

In many applications, it is often needed to convert from one type of system representation to another. In this activity you will start with the following system representation in the state space form:

In order to plot the poles and zeros of the system on the zeropole plot, you will convert the system representation from the state space form to the zero-pole form. Next, in order to compute system parameters such as settling time, you will require the system representation in the transfer function form. For this, you will convert the system representation from the zero-pole form to the transfer function form. In this activity, you will learn how to use Vis in the Control and Simulation Software to do such conversions.

Control Systems

405

Front Panel

i. Build the front panel as shown in the figure above. 2. The array controls A, B, C, and D contain matrices A,

B, C, and D of the state space representation as explained in the previous section. 3. In case of multiple input systems, the control Input Number contains the index of the input for which the conversion is required. In case of multiple output systems, the control Output Number contains the index of the output number for which the conversion is required. 4. After the VI has been run, the array indicators Zeros and Poles contain the zeros and poles of the system for the input and output number specified. The XY Graph Zero-Pole Plot will plot the poles and zeros of the system in the complex s-plane.

LabVIEW Signal Processing

406

Block Diagram

5. Switch to the block diagram and complete the block diagram as shown above and explained in the following four steps. 6. Choose the GSim SS2ZP VI (Functions » GSim subpalette). You will use this VI to convert the system representation from the state space form to the transfer function form. Bundle the controls A, B, C, and D into a cluster. Wire this cluster to the System input of the VI. Wire the controls Input Number and Output Number to the inputs Input Number and Output Number of the VI, respectively. Wire the output terminals Poles and Zeros to the array indicators Poles and Zeros, respectively.

Control Systems

407 7. Choose the GSim ZP2TF VI (Functions » GSim subpalette). You will use this VI to convert the system representation from the zero pole form to the transfer function form. Bundle the Zeros and Poles indicators to a cluster and wire the cluster to the System input of this VI.

8. Choose the GSim Compute Parameters VI (Functions » GSim subpalette). You will use this VI to compute the settling time, given the denominator coefficients of the transfer function of the system. Wire the Alphas output of the GSim ZP2TF VI to the Alphas input of the GSim Compute Parameters VI. Wire the output Settling Time to the array indicator Settling Time.

9. Build the rest of the block diagram as shown in the figure on the previous page. This is needed for separating the real and imaginary parts of the complex poles and zeros and then plotting them on the XY Graph Zero-Pole Plot. 10. Switch to the front panel and enter the elements of matrices A, B, C, and D of the state space representation as shown in the equations at the beginning of this activity. There are two inputs and one output. Let us first look at the response at the output terminal due to the first input. Set both the Input Number and Output Number equal to 1. Run the VI and look at

LabVIEW Signal Processing

408

the poles and zeros on the Zero-Pole Plot. The array indicator Settling Time contains the settling time for the transfer function between the first input and the output. Follow the instructions as in step 10 of Activity 10-1 in order to see th& poles and zeros as x's and circles fespectiveiy on the XY Graph, 11. Set the control Input Number equal to 2. Run the VI. Study the Zero-Pole Plot and the settling time for the transfer function between the second input and the output. 12. Save this VI as Conversion.vi in the library Activities . lib and close it.

End of Activity 10-2

Frequency Domain Analysis In this section, we will briefly describe frequency-domain analysis tools such as Bode plot, Nyquist plot and root-locus plot. We will then show how Vis in the Control and Simulation Software can be used to analyze systems using these tools. In the frequency domain, the transfer function G(s) of a system can be described by the relation where and

Control Systems

409

Figure 10-8 Polar plot representation for an RC filter

As shown in Figure 10-8, in a polar plot representation of an RC filter, (a filter consisting of a resistor (R) and capacitor (C) in series), the imaginary part of the transfer function is plotted versus the real part. This is the simplest form of the frequencydomain analysis. However, the polar plot representation has its own limitations. The calculation of the frequency response is tedious and does not indicate the effect of individual poles or zeros. It is sometimes more convenient to plot the magnitude and phase as the function of frequency. In terms of magnitude and phase, the transfer function can be represented as

where

The analysis procedure is further simplified if the magnitude and phase are plotted on a logarithmic plot. The introduction of such logarithmic plots, often called Bode plots, simplifies the

LnbVIEW Signal Processing

410

calculation for plotting the frequency response. Such plots were introduced by H.W. Bode who used them extensively in his studies of feedback amplifiers. Equation 10.6 can be written in natural logarithm form as

where In I G(;to) I is the magnitude in nepers. The logarithm of the magnitude is normally expressed in terms of the logarithm to the base 10, so that we use Logarithmic Gain = 20 log10|G(/co)| where the units are in decibels(dB). The magnitude is plotted as the function of frequency on one graph and the phase is plotted as the function of frequency on a different graph. The phase is usually plotted in degrees. In the next activity, we will compute the data and graphically portray the Bode plot for two different systems.

Activity 10-3 Objective: To plot and study the Bode diagram for a given system

In this activity, we will use the Bode Plot to analyze the classical control system shown in Figure 10-9.

Figure 10-9 Plant design

411

Control Systems

The control system consists of two systems in a series connection and a feedback system in a closed loop connection. System 1 in the main loop is an integrator and System 2 in the main loop is a motor. The feedback system is a constant gain K, which is equal to 4 in this example. In this activity, you will learn how to use the Vis in the Control and Simulation Software to analyze the system.

Front Panel

1. Build the front panel as shown in the above figure. Systeml is a cluster containing the following two elements. The array control Numerator will hold the coefficients of the numerator of the transfer function of System 1 in the plant design. The first element in

LabVIEW Signal Processing

412

the array will contain the lowest order (constant term) coefficient, the second element will contain the first order coefficient, and so on. The array control Denominator will hold the coefficients of the denominator of the transfer function of Systeml. The first element of the array will contain the lowest order (constant term) coefficient, the second element will contain the first order coefficient, and so on. 2. SystemZ is a cluster containing the numerator and denominator coefficients of the transfer function of System2 in the plant design. Feedback System is a cluster containing the numerator and denominator coefficients of the transfer function of the feedback system in the plant design. 3. Gain in dB and Phase in degrees are XY Graphs. When the VI is run, gain in decibels is plotted as a function of frequency on the Gain in dB plot and phase in degrees is plotted as a function of frequency on the Phase in degrees plot.

Block Diagram

4. Switch to the block diagram and complete it as explained in the following steps: 5. Choose the GSim Series VI (Functions » GSim subpalette). You will use this VI to compute the overall transfer function of the two systems, System 1 and

Control Systems

A] 3

System 2, connected in series. Wire the cluster

Systeml to the input System 1 and the cluster System! to the input System 2. 6. Choose the GSim Feedback VI (Functions » GSim subpalette). You will use this VI to compute the closed loop transfer function. Wire the Output cluster from the VI described in step 5 to the input System 1 and the cluster Feedback System to the input System 2. On execution, the cluster Output contains the transfer function of the closed loop transfer function.

7. Choose the GSim Bode Plot from TF VI (Functions » GSim subpalette). You will use this VI to compute data for the Bode plot using the transfer function representation of the closed loop system computed in step 6. Wire the Output cluster from the VI described in step 6 to the input System. Use the Unbundle By Name VI to unbundle the Bode Plot Data cluster which contains three components: Gain, Phase, and Frequency. Bundle the Gain and Frequency together and plot them on the Gain in dB plot. Bundle the

LabVIEW Signal Processing

414

Phase and Frequency together and plot them on the Phase in degrees plot.

Switch back to the front panel. Enter the numerator and denominator coefficients of the transfer functions of System 1, System 2, and Feedback System in the respective clusters. Remember that the constant term is the first element of the array and the first order term is the second element of the array. Run the VI and study the Bode plots for the plant 9. design.

8.

lo see a /OQQ< ;//?»;«• x-s ofe pop »p