Chapter 1
Introduction
1.1 Introduction: Computer Programming and Digital Signal Processing
Computers are powerful tools for recording, analyzing, visualizing, and processing digital audio. Programming a computer allows for the robust control of audio signals and the creation of software for specialized tasks. Digital signal processing (DSP) is an extensive field of mathematical methods with many applications to process digital audio signals. Together, computer programming and DSP provide a framework for accomplishing many audio-related tasks.
1.2 The Purpose of This Book
The purpose of this book is to provide an introduction for audio engineers to computer programming and digital signal processing. These topics are presented generally, and also demonstrated using the MATLAB® programming language. Furthermore, many pertinent features of the MATLAB Signal Processing ToolboxTM are covered.
The content of the book is intended to supplement a more general introduction to programming by an undergraduate computer science course and introduction to DSP by an undergraduate electrical engineering course. However, topics are presented for readers with little or no experience with computer programming or DSP. Therefore, this book can be used as a precursor for more general study. Additionally, the material in this book is intended to provide a foundation for advanced study specifically in audio engineering.
1.3 Intended Readers
This book is intended for students who would like to learn about computer programming through the use of examples and applications in audio. A mathematical foundation at the level of college algebra and trigonometry is expected. Consequently, audio signal processing can be an intuitive context to practically apply mathematical theory. It is not necessary to have previous knowledge of calculus because all processing is performed with digital signals. Additionally, it is helpful to have a foundation in the physics of sound. Necessary topics include a foundational understanding of signals, vibration, amplitude, frequency, and sampling.
Additionally, this text is intended for practicing engineers needing a handbook to reference with a wide range of implemented examples and detailed background explanations.
1.4 Topics Covered
The following is a list of topics covered in the book. An introduction to programming using the MATLAB language is presented in Chapter 2. The basics of working with audio signals are discussed in Chapter 3, along with common methods to visualize audio. An overview of the MATLAB programming environment is provided in Chapter 4. The programming constructs of several control structures are presented in Chapter 5. In Chapter 6, the basics of amplitude processing are discussed, including gain scaling and DC offset. The synthesis of common audio test signals is covered in Chapter 7. From there, the topics pivot to applying computer programming to perform DSP algorithms. Chapter 8 presents digital summing, signal fades, and amplitude modulation. Chapters 9 and 10 cover stereo audio and nonlinear distortion effects, respectively. Chapters 11, 12, and 13 introduce systems with delay processing to create echo effects and spectral effects. Circular buffers and fractional delay are covered in Chapter 14. Modulated delay effects are demonstrated in Chapter 15, and these modulation effects are used as the building blocks to create algorithmic reverberation in Chapter 16. Finally, effects based on a signal’s amplitude envelope are covered in Chapter 17 and become the foundation of dynamic range effects in Chapter 18.
The topics are organized sequentially based on requisite computer programming knowledge and by increasing complexity for signal processing. However, the presentation of material is intended to allow for topical study for readers with prior computer programming and signal processing experience.
1.5 Additional Content
To supplement the material in the book, there is Additional Content available at the Hack Audio website (www.hackaudio.com). Readers can access MATLAB scripts, functions, and sound files that accompany various examples. It is highly recommended that students use the Additional Content to follow along with the content of the book.
Chapter 2
Basics of Programming in MATLAB®
2.1 Introduction: Computer Programming in MATLAB
Computers can be used for calculations, analysis, visualization, and processing. These are all important tasks when working with audio. In order to program a computer to complete all these tasks with audio information, it is important to understand how a computer performs these tasks with more general types of information. This chapter introduces necessary programming concepts in preparation for working with audio in Chapter 3.
2.2 Programming Languages
A programming language is a vocabulary or a set of instructions a computer can interpret. Computers can interpret many different programming languages. Despite their differences, many languages have similar constructs. As an analogy, there are many spoken languages that use the same conceptual constructs (nouns, verbs, punctuation, etc.), yet might incorporate the constructs differently. The rules for what is allowed in a language is called syntax.
Different programming languages have various advantages and disadvantages. Some languages allow for advanced control of the computer, but are complex. Other languages are simpler, but have less control. MATLAB is a programming language specialized for scientific computing that makes many mathematical and engineering tasks intuitive while maintaining advanced control of the computer. It is used in a diverse range of fields including statistics, finance, biomedical engineering, computer vision, wireless communication, robotics, and economics. More specifically for audio, MATLAB is a common language for DSP.
Examples of other general-purpose programming languages are C/C++, Java, HTML, Python, Fortran, Visual Basic, Swift, Objective-C, assembly, and machine code. Comp...