Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

MATLAB Programming for Biomedical Engineers and Scientists
MATLAB Programming for Biomedical Engineers and Scientists
MATLAB Programming for Biomedical Engineers and Scientists
Ebook702 pages48 hours

MATLAB Programming for Biomedical Engineers and Scientists

Rating: 4.5 out of 5 stars

4.5/5

()

Read preview

About this ebook

MATLAB Programming for Biomedical Engineers and Scientists provides an easy-to-learn introduction to the fundamentals of computer programming in MATLAB. This book explains the principles of good programming practice, while demonstrating how to write efficient and robust code that analyzes and visualizes biomedical data. Aimed at the biomedical engineer, biomedical scientist, and medical researcher with little or no computer programming experience, it is an excellent resource for learning the principles and practice of computer programming using MATLAB.

This book enables the reader to:

  • Analyze problems and apply structured design methods to produce elegant, efficient and well-structured program designs
  • Implement a structured program design in MATLAB, making good use of incremental development approaches
  • Write code that makes good use of MATLAB programming features, including control structures, functions and advanced data types
  • Write MATLAB code to read in medical data from files and write data to files
  • Write MATLAB code that is efficient and robust to errors in input data
  • Write MATLAB code to analyze and visualize medical data, including imaging data
  • Many real world biomedical problems and data show the practical application of programming concepts
  • Two whole chapters dedicated to the practicalities of designing and implementing more complex programs
  • An accompanying website containing freely available data and source code for the practical code examples, activities, and exercises in the book
  • For instructors, there are extra teaching materials including a complete set of slides, notes for a course based on the book, and course work suggestions
LanguageEnglish
Release dateJun 14, 2017
ISBN9780128135105
MATLAB Programming for Biomedical Engineers and Scientists
Author

Andrew P. King

Dr King has over 20 years of experience of teaching computing courses at university level. He is currently a Reader in the Biomedical Engineering department at King's College London. With Paul Aljabar, he designed and developed the Computer Programming module for Biomedical Engineering students upon which this book was based. The module has been running since 2014 and Andrew still co-organises and teaches on it. Between 2001-2005, Andrew worked as an Assistant Professor in the Computer Science department at Mekelle University in Ethiopia, and was responsible for curriculum development, and design and delivery of a number of computing modules. Andrew's research interests focus mainly on the use of machine learning and artificial intelligence techniques to tackle problems in medical imaging, with a special focus on dynamic imaging data, i.e. moving organs (Google Scholar: https://goo.gl/ZZGrGr, group web site: http://kclmmag.org).

Related to MATLAB Programming for Biomedical Engineers and Scientists

Related ebooks

Technology & Engineering For You

View More

Related articles

Related categories

Reviews for MATLAB Programming for Biomedical Engineers and Scientists

Rating: 4.25 out of 5 stars
4.5/5

4 ratings1 review

What did you think?

Tap to rate

Review must be at least 10 words

  • Rating: 5 out of 5 stars
    5/5
    thanks for this great book ? inspired me to move on

Book preview

MATLAB Programming for Biomedical Engineers and Scientists - Andrew P. King

Preface

Aims and Motivation

This book aims to teach the fundamental concepts of computer programming to students and researchers who are studying or working in the biomedical sciences. The book and associated materials grew out of the authors' experience of teaching a first year undergraduate module on computer programming to biomedical engineering students at King's College London for a number of years. Such students have a strong interest in the biomedical applications of computing, and we felt that it was important to provide not only a concise introduction to the key concepts of programming, but also to make these concepts relevant through the use of biomedical examples and case studies.

The book is primarily aimed at undergraduate students of biomedical sciences, but we hope that it will also act as a concise introduction for students in other disciplines wishing to familiarize themselves with the important field of computer programming.

Our emphasis throughout is on practical skill acquisition. We introduce all concepts accompanied by real code examples and step-by-step explanations. These examples are reinforced by learning activities in the chapter text as well as further exercises for self-assessment at the end of each chapter. Code for all examples, activities and exercises is available for download from the book's web site.

Practical skills will be learned using the MATLAB® software package, focusing on the procedural programming paradigm. All code is compatible with MATLAB® 2016a. Note that we do not intend this text to be an exhaustive coverage of MATLAB® as a software package. Rather, we view it as a useful tool with which to teach computer programming. We are always interested in hearing feedback and suggestions from students (particularly those with an interest in biomedical applications) about material that could be added or omitted.

Learning Objectives

On completion of the book the reader should be able to:

■  Analyze problems and apply structured design methods to produce elegant, efficient and well-structured program designs.

■  Implement a structured program design in MATLAB®, making use of incremental development approaches.

■  Write code that makes good use of MATLAB® programming features, including control structures, functions and advanced data types.

■  Write MATLAB® code to read in medical data from files and write data to files.

■  Write MATLAB® code that is efficient and robust to errors in input data.

■  Write MATLAB® code to analyze and visualize medical data, including images.

How to Use This Book

The book is primarily intended as a companion text for a taught course on computer programming. Each chapter starts with clear learning objectives and the students are helped to meet these objectives through the text, examples and activities that follow. The objectives associated with each example or activity are clearly indicated in the text. Exercises at the end of each chapter enable students to self-assess whether they have met the learning objectives.

The book comes with an on-line teaching pack containing teaching materials for a taught undergraduate module to accompany the book (sample lesson plans, lecture slides and suggestions for coursework projects), as well as MATLAB® code and data files for all examples, activities and exercises in the book. All materials are available from the book's web site at: http://textbooks.elsevier.com/web/Manuals.aspx?isbn=9780128122037.

Student materials are accessible at: https://www.elsevier.com/books-and-journals/book-companion/9780128122037.

The book consists of 12 chapters:

■  Chapter 1 – Introduction to Computer Programming and MATLAB®: This chapter introduces the reader to the fundamental concepts of computer programming and provides a hands-on introduction to the MATLAB® software package. At this stage we go into just enough detail to enable the reader to start using MATLAB® to perform simple operations and produce simple visualizations. We also start to show the reader how to create and debug simple computer programs using MATLAB®.

■  Chapter 2 – Control Structures: Here, we introduce the concept of control structures, which can be seen as the basic building blocks of computer programs. We show how they can be used to create more complex code resulting in more powerful and flexible programs. Conditional and iteration control structures are introduced and we describe the MATLAB® commands that are provided to implement them.

■  Chapter 3 – Functions: In this chapter we introduce functions, an important means for programmers to split large programs into smaller modules. As we start to tackle more complex problems, functions are an essential part of the programmer's toolbox. We show how data can be passed into and returned from functions and also introduce special topics such as variable scope and recursion.

■  Chapter 4 – Program Development and Testing: Next, we cover the important (but often overlooked) topic of how to go about developing a program and checking that it does what it is supposed to do. We introduce the concept of incremental development, in which we always maintain a working version of the program, even it is trivial, and then gradually add more functionality to it. We also give further detail on debugging and describe how we can make our programs robust to errors.

■  Chapter 5 – Data Types: Up until this point, we will have been dealing with programs that use fairly simple data, such as numbers or letters. In this chapter we explore data types in more depth, investigating how to find out the type of a variable, how to convert between types, as well as introducing some more complex (but powerful) data types such as cell arrays.

■  Chapter 6 – File Input/Output: Many biomedical applications involve reading data from external files and/or writing data to them. In this chapter we describe the commands that MATLAB® provides for these operations. We describe the different types of file that might be encountered, and cover the commands intended for use on each type.

■  Chapter 7 – Program Design: While it is necessary to know how to write working code, when tackling larger and more complex problems, it becomes important to be able to break a program down into a number of simpler modules, modules that can interact with each other by passing data. Such an approach to coding makes the process quicker and the resulting code is likely to contain fewer errors. Program design refers to the process of deciding which modules to define and how they interact. We illustrate this process using the commonly used approach of top-down step-wise refinement and we show how structure charts and pseudocode can be used to document a design.

■  Chapter 8 – Visualization: In this chapter we go into more detail about how to produce visualizations of data. We extend the basic coverage introduced in Chapter 1 and describe how to create plots containing multiple datasets, and plots that visualize multivariate data as well as images.

■  Chapter 9 – Code Efficiency: There are typically several different ways that a computer program can solve a given problem, and some may be more (or less) efficient. Here we consider how the way in which a program solves a problem affects it efficiency, in terms of time and the computer's memory. We show how efficiency can be measured and discuss ways in which program efficiency can be improved.

■  Chapter 10 – Signal and Image Processing: Many biomedical applications can involve processing of large amounts of data. This chapter describes techniques for processing signals (i.e. one-dimensional data) or images (two-dimensional or even three- or four-dimensional data). We introduce the powerful techniques of filtering and convolution and demonstrate how they can be applied to one- or higher-dimensional data. We return to the topic of images (first introduced in Chapter 8) and further show how pipelines may be constructed from simple operations to build more complex and powerful image-processing algorithms.

■  Chapter 11 – Graphical User Interfaces: As well as the functionality of a program (i.e. what it does) it is important to consider how it will interact with its users. This can be done using a simple command window interface, but more powerful and flexible interfaces can be developed using a GUI (Graphical User Interface). This chapter describes how GUIs can be created and designed in MATLAB® and how we can write code to control the way in which they interact with the user.

■  Chapter 12 – Statistics: The final chapter introduces the basics of statistical data analysis with MATLAB®. The chapter does not cover statistical theory in depth, but the intention is rather to describe how the most common statistical operations can be carried out using MATLAB®. Some knowledge of statistics is assumed, although fundamental concepts are briefly reviewed. We cover the fields of descriptive statistics (summarizing and visualizing data) and inferential statistics (making decisions based upon data).

We believe that the first ten chapters of the book are suitable content for an undergraduate module in computer programming for biomedical scientists. The last two chapters are included as more advanced topics which may be useful for students' future work in using MATLAB® as a tool for biomedical problem-solving.

We end each chapter of the book with a brief pen portrait of a famous computer programmer from the past or present. As well as providing a bit of color and interest, we hope that this will help the reader to see themselves as following in the footsteps of a long line of pioneers who have developed the field of computer programming and brought it to where it is today: an intellectually stimulating and incredibly powerful tool to assist people working in a wide range of fields to further the limits of human achievement.

Finally, a word about data. We have made every effort to make our biomedical examples and exercises as realistic as possible. Where possible, we have used real biomedical data. On the occasions where this was not possible, we have tried to generate realistic synthetic data. We apologize if this synthetic data lacks realism or plausibility in any respect, or gives a misleading impression about the application that the exercise deals with. Our intention has been to provide examples that are relevant to those with an interest in biomedical applications, and we accept responsibility for any flaws or errors in the data we provide.

Acknowledgments

The authors would like to thank the following people for their contributions to the development of this book.

■  All biomedical engineering students at King's College London who have taken our Computer Programming module over the past few years, for their constructive feedback which has improved the quality of our teaching materials that formed the basis for this book. Also, for the same reasons, all teaching assistants and lecturers who have contributed to the delivery the module, in particular Alberto Gomez.

■  Dr. Adam Shortland of the One Small Step Gait Laboratory at Guy's Hospital, London, for insightful discussions and providing the data for a number of activities and exercises throughout the book: Activity 1.8, Exercise 2.8, Exercise 3.6, Activity 5.8, Activity 8.2, and Exercise 8.4.

■  From the publishers, Elsevier: Tim Pitts for prompting us to write the book in the first place, and Anna Valutkevich for encouraging us to produce it on time.

Chapter 1

Introduction to Computer Programming and MATLAB

Abstract

This chapter introduces the reader to the fundamental concepts of computer programming and provides a hands-on introduction to the MATLAB software package. The different components of the MATLAB environment are described. The chapter describes how to access the MATLAB documentation to find out more information about built-in MATLAB functions. Basic concepts are introduced including defining simple expressions using values and variables. The four basic data types used by MATLAB are introduced: integer, floating point, Boolean and character. It is also shown how variables of each of these types can be either simple scalar values, arrays or matrices. The reader is shown how to produce simple data visualizations and fit curves to the data. Finally, it is shown how sequences of commands can be saved in MATLAB script m-files, and that problems with these script files can be identified and fixed using the MATLAB debugger and code analyzer.

Keywords

MATLAB; Computer programming; Plotting; Variable; Arrays; Matrices; Expression; Data type; Script; Debugging

Learning Objectives

At the end of this chapter you should be able to:

O1.A  Describe the broad categories of programming languages and the difference between compiled and interpreted languages

O1.B  Use and manipulate the MATLAB environment

O1.C  Form simple expressions using scalars, arrays, variables, built-in functions and assignment in MATLAB

O1.D  Describe the different basic data types in MATLAB and be able to determine the type of a MATLAB variable

O1.E  Perform simple input/output operations in MATLAB

O1.F  Perform basic data visualization in MATLAB by plotting 2-D graphs and fitting curves to the plotted data

O1.G  Form and manipulate matrices in MATLAB

O1.H  Write MATLAB scripts, add meaningful and concise comments to them and use the debugger and code analyzer to identify and fix coding errors

1.1 Introduction

The processing power of digital computers has increased massively since their invention in the 1950s. Today's computers are about a trillion times more powerful than those available 60 years ago. Likewise, the use of computers (and technology in general) in biology and medicine (commonly termed biomedical engineering) has expanded hugely over the same time period. Today, diagnosis and treatment of many diseases is reliant on the use of technology such as imaging scanners, robotic surgeons and cardiac pacemakers. Computers and computer programming are at the heart of this technology.

The simultaneous rise in computing power and the biomedical use of technology is not a coincidence: advances in technology often drive advances in biology and medicine, enabling more sensitive diagnostic procedures and more accurate and effective treatments to be developed. In recent years, the ever-closer relationship between technology and medicine has resulted in the emergence of a new breed of medical professional: someone who both understands the biological and medical challenges but also has the skills needed to apply technology to address them and to exploit any opportunities that arise. If this sounds like you (or perhaps the person you would like to be), then this book is for you. Over the next twelve chapters we hope to introduce the fundamental concepts of computer programming but with a strong biomedical focus, which we hope will give you the skills you need to tackle the increasingly complex problems faced in modern medicine.

In this first chapter of the book we will introduce some fundamental concepts about computer programming, and then focus on familiarizing ourselves with the MATLAB software application. This is the software that will be used throughout the book to learn how to develop computer programs.

1.1.1 Computer Programming

The development of the modern digital computer marked a step change in the way that people use machines. Until then, mechanical and electrical machines had been proposed and built to perform specific operations, such as solving differential equations. In contrast, the modern digital computer is a general purpose machine that can perform any calculation that is computable. The way in which we instruct it what to do is by using computer programming.

We can make a number of distinctions between different computer programming languages depending on how we write and use the programs. Firstly, a useful distinction is between an interpreted language and a compiled language. A program written in an interpreted language can be run (or executed) immediately after it has been written. For compiled languages, we need to perform an intermediate step, called compilation. Compiling a program simply means translating it into a language that the computer can understand (known as machine code). Once this is done, the computer can execute our program. With an interpreted language this ‘translation’ is done in real-time as the program is executed and a compilation step is not necessary.

In this book we will be learning how to program computers using a software application called MATLAB. MATLAB is (usually) an interpreted language. Although it is also possible to use it as a compiled language, we will be using it solely as an interpreted language.

Another distinction we can make between different programming languages relates to how the programs are written and what they consist of. Historically, most programming languages have been procedural languages. This means that programs consist of a sequence of instructions provided by the programmer. Until the 1990s almost all programming languages were procedural. More recently, an alternative called object-oriented programming has gained in popularity. Object-oriented languages allow the programmer to break down the problem into objects: self-contained entities that can contain both data and operations to act upon data. Finally, some languages are declarative. In principle, when we write a declarative program it does not matter what order we write the program statements in – we are just ‘declaring’ something about the problem or how it can be solved. The compiler or interpreter will do the rest. Currently, declarative languages are mostly used only for computer science research.

MATLAB is (mostly) a procedural language. It does have some object-oriented features but we will not cover them in this book.

1.1.2 MATLAB

MATLAB is a commercial software package for performing a range of mathematical operations. It was first developed in 1984 and included mostly linear algebra operations (hence the name, MATrix LABoratory). It has since been expanded to include a wide range of functionality including visualization, statistics, and algorithm development using computer programming. It has approximately 1 million current users in academia, research and industry, and has found particular application in the fields of engineering, science and economics. As well as its core functionality, there are a number of specific toolboxes that are available to extend MATLAB's capabilities.

Although MATLAB is a very powerful software package, it is a commercial product. Student licenses can be obtained relatively cheaply, but full licenses are more expensive. If your institution provides a license this is not a problem for you, but if you need to acquire a license yourself, and you are not eligible for a student license, you may want to consider one of the free, open-source alternatives to MATLAB. Some of the most common are:

■  Octave: Good compatibility with MATLAB, but includes a subset of its functionality (http://www.gnu.org/software/octave);

■  Freemat: Good compatibility with MATLAB, but includes a subset of its functionality (http://freemat.sourceforge.net);

■  Scilab: Some differences from MATLAB (http://www.scilab.org/en).

1.2 The MATLAB Environment

After we start MATLAB, the first thing we see is the MATLAB environment window. To begin with, it is important to spend some time familiarizing ourselves with the different components of this window and how to use and manipulate them. Fig. 1.1 shows a screenshot of the MATLAB environment window (if yours does not look exactly like this, don't worry – as we will see shortly it is possible to customize its appearance).

Figure 1.1 The MATLAB environment.

The command window is where we enter our MATLAB commands and view the responses MATLAB gives (if any). As we enter commands they will be added to our command history. We can always access and repeat old commands through the command history window. Another way of cycling through old commands in the command window is to use the up and down arrow keys. Although the command window is the main way in which we instruct MATLAB to perform the operations we want, it is often also possible to execute commands via the menu bar at the top of the environment window.

The MATLAB environment window can also be used to navigate through our file system. The current folder window shows our current folder and its contents. It can also be used for simple navigation of the file system.

As we use the command window to create and manipulate data, these data are added to our workspace. The workspace is basically a collection of all of the data that have been created or loaded into MATLAB. The current contents of the workspace are always displayed in the workspace browser.

When we start creating scripts to perform more complex MATLAB operations (see Section 1.10), we will use the editor window to create and edit our script files. This can be useful if we want to perform the same sequence of operations several times or save a list of operations for future use.

We can customize the MATLAB environment by clicking on the Layout button in the menu bar (under the Home tab).

Activity 1.1

Try customizing the MATLAB environment window. For example, switch between Default and Two Column layouts; hide the Current Folder and/or Workspace panels, then make them reappear again; try switching the Command History between the Popup and Docked modes and see the effect this has. If you want to get rid of any changes you've made and return to the original layout, then simply select Layout

Enjoying the preview?
Page 1 of 1