CHAPTER 6

Programming Vectors and Matrices

Vectors and matrices are the two most common data structures used in digital signal processing. Efficiency and ease of use are therefore of central importance for these structures. Of course, C provides a structure for vectors and even matrices. Why not just use these structures as supplied? For simple, quick routines that are going to be used for just a short time, and probably only by the developer, using the supplied structures may be the best choice. However, if the goal is to build a large library of routines with an easily remembered interface and built-in error checking, something more is needed.

This chapter develops the vector and matrix structures used in the Companion Library. Section 6.1 explores some of the helpful features of the new ANSI standard for C, especially function prototypes and the resulting type checking. Section 6.2 uses the examples of Section 6.1 to introduce the vector structure used in the Companion Library and to explore some of its advantages. Section 6.3 compares the efficiencies of three different versions of the same function, one using the encapsulated vector structure introduced in Section 6.2 and the other two not. The surprising result is that there is no measurable loss of runtime efficiency. Section 6.4 compares the chosen structure of vectors with an alternative structure. The reasons for the choice made for the Companion Library are carefully explained. Section 6.5 introduces the matrix structure ...

Get Signal Processing in C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.