Figure B.3 shows the MATLAB plots of input and output signals. Note that the vector
a is defined based on coefficients a
m
used in Equation (B.6), which have different signs
than the coefficients used in Equation (B.5). An FIR filter can be implemented by
setting a [1]or using
filter(b,1,x);
where the vector b consists of FIR filter coefficients b
l
.
MATLAB can interface with three different types of data files: Mat-files, ASCII files,
and binary files. The Mat-file and binary file contain data stored in a memory-efficient
binary format, whereas an ASCII file contains information stored in ASCII characters.
Mat-files are preferable for data that is going to be generated and used by MATLAB
programs.
Data saved in both the Mat-file and ASCII file can be loaded (retrieved) from the disk
file into an array in workspace using the load command. For example,
Load xn;
will load the Mat-file xn.mat, and
load xn.dat;
will read the data from the ASCII file with the name xn.dat in the disk into an array
with the name xn.
To load the file xn.bin stored in the binary format into the array xn, we have to use
the following C-like commands:
fid fopen(`xn.bin',`r');
xn fread(fid,`float32');
where the fopen command open the file xn.bin, `r' indicates to open the file for
reading, and fid is a file identifier associated with an open file. The second command
0
20
40
Input signal
Output signal
60
80
100
120
140
4
2
3
1
-1
-2
0
-3
-4
Figure B.3 Filter input (dotted line) and output (solid line) waveforms
464
APPENDIX B: INTRODUCTION OF MATLAB FOR DSP APPLICATIONS