EECS 152B Lab Report 3
EECS 152B Lab Report 3
EECS 152B Lab Report 3
Problem 1
The objective of this problem is to implement an FIR lowpass filter with the dsk board.
The filter should have a cuto frequency of 1760 Hz.
itm:questions-fir-lowpass
The following code starts o by declaring an array lowpass[] which has the filter coecients
found by the matlab code found in i.. It then begins polling and fills an input vector (of the
same length as the filter) with samples from the dsk board. After filling the input vector,
it then enters a loop which accomplishes the following:
1. It sums the convolution of the current input vector with the filter coecients
2. It outputs this sum to the board
3. It shifts the input vector once to the left and inserts a new sample in its rightmost
position
1
2
#include "dsk6713_aic23.h"
#include "dsk6713_led.h"
3
4
5
6
7
#define FILTER_LENGTH 49
8
9
10
Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
0.00161979322029948370, 0.00214225259628533000,
-0.00047558977253344320, -0.00354590407634487650,
-0.00624411669947530590, -0.00237847116307618370,
0.01295156806914578300, 0.01680622510945733700,
-0.00158902124438583140, -0.02095792775291762900,
-0.03873070207107721900, -0.01779006866361691800,
0.08966015914615578500, 0.15377710387149290000,
0.21984511275197313000, 0.20195759380955880000,
0.08966015914615578500, 0.02746970212542162300,
-0.03873070207107721900, -0.03696902393001178000,
-0.00158902124438583140, 0.01232212944474056100,
0.01295156806914578300, 0.00500021450790641420,
-0.00624411669947530590, -0.00615075099554396580,
-0.00047558977253344320, 0.00157034732804796000,
0.00161979322029948370, 0.00066640936656965611,
-0.00081696436698336546};
29
30
31
32
unsigned int i = 0;
unsigned int j = 0;
unsigned int z = 0;
33
34
void main()
35
{
comm_poll();
36
37
38
39
40
41
42
43
44
45
46
while(1) {
47
48
49
50
51
52
x
output_left_sample(sum);
sum = 0;
53
54
55
56
57
58
59
60
b = input_left_sample();
input[FILTER_LENGTH-1] = (float)b;
61
62
63
64
(a) 208 Hz
Figure 1.2: Output waveforms for the FIR lowpass filter resulting from
the code given in Figure 1.1 for dierent pure sine frequencies
Problem 2
The objective for this problem is to design a highpass filter with cuto frequency 4560 Hz.
The code below is exactly the same as for Problem 1 save for the filter coecient values.
1
2
#include "dsk6713_aic23.h"
#include "dsk6713_led.h"
3
4
5
6
7
#define FILTER_LENGTH 45
8
9
10
Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
unsigned int i = 0;
unsigned int j = 0;
unsigned int z = 0;
32
33
void main()
34
35
comm_poll();
36
37
38
39
40
41
42
43
44
45
46
47
while(1) {
/* Perform multiplication and sum */
0.00208656645683152510,
-0.00191164049242499900,
-0.01257176282544475100,
-0.01009072458143068900,
0.03057290797537401400,
0.09462042004619715400,
0.46033558445336265000,
0.09462042004619715400,
0.03057290797537401400,
-0.01009072458143068900,
-0.01257176282544475100,
-0.00191164049242499900,
0.00208656645683152510,
0.00112562953175404700,
48
sum += lowpass[z]*input[FILTER_LENGTH-1-z];
49
50
51
output_left_sample(sum);
sum = 0;
52
53
54
55
56
57
58
59
b = input_left_sample();
input[FILTER_LENGTH-1] = (float)b;
60
61
62
63
Figure 2.2: Output waveforms for the FIR highpass filter resulting from
the code given in Figure 2.1 for dierent pure sine frequencies
As shown in Figure 2.2, this filter shows the desired filter characteristics. Again, here, the
amplitudes seem to make sense. Assuming that the gain at 5.26 kHz is unity, it is expected
for the gain of the 4.09 kHz signal to be less than 3 dB since it is below the cuto frequency.
Indeed it is, as 3 dB gain would give a 453 mV amplitude, and this is much less than that.
In fact, seeing that the normalized frequency of the 4.09 kHz is 0.511 25 and thus very close
to the value which gives 40 dB gain (see Table 5.ii.1), its a wonder the amplitude isnt
even lower. The reason for this likely boils down to noise in the signal. As can be seen from
the figure, much of the signal can be attributed to noise, and from previous experience we
know that noise on the order of 50 mV is not unexpected.
Problem 3
The objective for this problem is to design a highpass filter with cuto frequencies of 1760 Hz
and 4560 Hz.
The code below is exactly the same as for Problem 1 save for the filter coecient values.
1
2
#include "dsk6713_aic23.h"
#include "dsk6713_led.h"
3
4
5
6
7
#define FILTER_LENGTH 44
8
9
10
Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011
11
12
13
14
unsigned int i = 0;
unsigned int j = 0;
unsigned int z = 0;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0.002285005291701485100,
-0.000662268802485741410,
-0.020803397305029305000,
-0.013341181860725434000,
0.012430524442952817000,
-0.052009560747888622000,
0.312710665090100040000,
-0.247111212040529190000,
-0.019285086707876285000,
0.019690796960738364000,
-0.002496698628516754200,
0.004468372773721288400,
0.005281289897170116600,
-0.000019789648741247706,
31
32
void main()
33
34
comm_poll();
35
36
37
38
39
40
41
42
43
44
45
46
while(1) {
/* Perform multiplication and sum */
0.005281289897170116600,
0.004468372773721288400,
-0.002496698628516754200,
0.019690796960738364000,
-0.019285086707876285000,
-0.247111212040529190000,
0.312710665090100040000,
-0.052009560747888622000,
0.012430524442952817000,
-0.013341181860725434000,
-0.020803397305029305000,
-0.000662268802485741410,
0.002285005291701485100,
0.000031804510880084353};
47
sum += lowpass[z]*input[FILTER_LENGTH-1-z];
48
49
50
x
output_left_sample(sum);
sum = 0;
51
52
53
54
55
56
57
58
b = input_left_sample();
input[FILTER_LENGTH-1] = (float)b;
59
60
61
62
Figure 3.2: Output waveforms for the FIR bandpass filter resulting from
the code given in Figure 3.1 for dierent pure sine frequencies
With the above code, the oscilloscope waveforms shown in Figure 3.2 are generated. While
we confirmed that the filter attenuates frequencies above the higher cuto frequencies, we
neglected to take a picture of that oscilloscope waveform.
Problem 4
The objective of this problem is to implement the same filters specified in Problem 1, Problem
2, and Problem 3 with IIR filters instead of FIR ones.
While using the following code in lab, we elected to go about having just one set of filter
coecients uncommented at a time while changing N to fit the size of the filter we were
using. In the snippet below, all three sets of coecients are shown uncommented for claritys
sake.
In any case, after defining N (the length of the given filter) and the filter coecients proper
the code declares input[] and output[] vectors to hold sections of the input and output
signals of the filter of the same length as the filter.
After entering the while loop, it sums the convolution of the current input[] vector and
the b filter coecients in order to get the first part of the output signal. It then sums the
convolution of the current output[] vector and the a filter coecients and subtracts this
sum from the sum described above.
This floating-point dierence is typecasted to a short and output to the speakers.
The input and output vectors are then shifted to the left and new appropriate values are
placed in their rightmost positions.
1
2
#include "dsk6713_aic23.h"
#include "dsk6713_led.h"
3
4
5
6
7
8
Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011
9
10
11
12
13
14
15
unsigned int i = 0;
unsigned int j = 0;
unsigned int z = 0;
16
17
18
19
20
21
-0.044995815898198468,
-0.029432173299327589,
0.063486394663502185,
0.015495475408834577};
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0.139335498243089440,
-0.202790003150475790,
-0.089676279279297971,
0.182665720844534420,
-0.032327592148735811};
45
46
float a[N] = {
47
48
49
50
1.000000000000000000,
-21.188830934225550000,
54.470584082326944000,
-35.774596361036920000,
5.419161525366078500,
- 4.027423078991632500, 10.808766498459843000,
34.523519894086988000, -46.620894233142970000,
-54.546702929057446000, 47.782069693527120000,
23.131917894380116000, -12.332159299321756000,
- 1.702254530803074800,
0.365819348914442730};
51
52
void main()
53
54
comm_poll();
55
56
57
58
59
60
61
62
63
float out;
short outs;
64
65
short bs;
66
67
while(1)
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Output to speakers
outs = (short)out;
output_left_sample(outs);
84
85
86
87
88
89
// Shift input vector left (same as reversing input and shifting right)
for(i = 0;i<N-1;i++)
{
input[i] = input[i+1];
}
90
91
92
93
94
95
// Shift output vector left (same as reversing output and shifting right)
for(i = 0;i<N-1;i++)
{
output[i] = output[i+1];
}
96
97
98
99
100
101
102
103
104
105
// Fetch input and enter into last value of input array (same as first value
// of flipped array)
bs = input_left_sample();
input[N-1] = bs;
106
107
108
109
110
111
While we observed the expected filter behavior during the lab, we didnt realize that by attenuating the
signal too far we wouldnt be able to see the frequency of the waveform in the oscilloscope measurements
2
See Footnote 1
3
See Footnote 1
10
Figure 4.3: Output waveforms for the IIR lowpass filter resulting from the
code given in Figure 4.1 for dierent pure sine frequencies
Figure 4.4: Output waveforms for the IIR highpass filter resulting from
the code given in Figure 4.1 for dierent pure sine frequencies
11
Figure 4.5: Output waveforms for the IIR bandpass filter resulting from
the code given in Figure 4.1 for dierent pure sine frequencies
12
Questions
100 mA 4 102
x=
(y) dy
1. Document the resulting parameters of the filters you design (i.e. filter
order, transition band frequencies, function used) & their associated matlab
code. Include the filter frequency plots using matlab for the coecients
used in all of the above problems. Plot the detailed passband and stopband
to demonstrate that the ripple requirements are met. Calculate the gain
values at the test frequencies used and verify that these correspond to that
on an oscilloscope.
For the gain tables below, the theoretical gain is found in matlab and compared to
the experimental gain. The experimental gain was assumed to be unitary when the
input signal frequency was in the passband, since we never actually probed the input
signal itself. For the signal not in the passband, the gain is calculated by
[
]
signal amplitude
gain = 20 log
dB
passband signal amplitude
As noted in Footnote 1, we didnt record the frequencies of any of the input signals not
in the IIR filters passbands. Because of this, there are no gain tabulations in those
filters sections.
All calculated experimental gains seem to be within 10 dB of their theoretical values,
though this margin is quite high.
i. FIR Lowpass Filter
Command used
Filter order
Transition bands
fir1()
48
/ (0.1992, 0.2637)
bl = fir1(48,[0.23]);
Figure 5.i.1: Matlab code used to generate FIR lowpass filter coecients
13
Frequency (kHz)
0.208
1.850
Table 5.i.2: Theoretical and experimental gain values for the FIR lowpass
filter
Magnitude (dB)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 5.i.2: Magnitude and phase responses for the FIR lowpass filter
Magnitude (dB)
-0.5
-1
-1.5
-2
-2.5
-3
-3.5
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
0.18
0.2
14
fir1()
48
/ (0.5059, 0.5762)
bh = fir1(44,0.54,high)
Figure 5.ii.1: Matlab code used to generate FIR highpass filter coecients
Frequency (kHz)
4.090
5.260
Table 5.ii.2: Theoretical and experimental gain values for the FIR highpass filter
15
Magnitude (dB)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 5.ii.2: Magnitude and phase responses for the FIR highpass filter
Magnitude (dB)
-0.5
-1
-1.5
-2
-2.5
-3
0.55
0.6
0.65
0.7
0.75
0.8
0.85
0.9
0.95
16
fir1()
48
/ (0.1641, 0.2363) (0.5566, 0.6509)
bb = fir1(43,[0.20 0.59],band);
Figure 5.iii.1: Matlab code used to generate FIR bandpass filter coecients
Frequency (kHz)
1.289
4.120
Table 5.iii.2: Theoretical and experimental gain values for the FIR bandpass filter
17
Magnitude (dB)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 5.iii.2: Magnitude and phase responses for the FIR bandpass filter
Magnitude (dB)
-0.5
-1
-1.5
-2
-2.5
-3
-3.5
0.2
0.25
0.3
0.35
0.4
0.45
0.5
0.55
0.6
18
ellip()
7
/ (0.2207, 0.2266)
[bl,al] = ellip(7,1,40,0.22);
Figure 5.iv.1: Matlab code used to generate IIR lowpass filter coecients
Magnitude (dB)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 5.iv.2: Magnitude and phase responses for the IIR lowpass filter
19
Magnitude (dB)
-1
-2
-3
-4
-5
-6
-7
0
0.05
0.1
0.15
0.2
0.25
20
ellip()
7
/ (0.5645, 0.5703)
[bh,ah]=ellip(7,1,40,0.57,high)
Figure 5.v.1: Matlab code used to generate IIR highpass filter coecients
Magnitude (dB)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 5.v.2: Magnitude and phase responses for the IIR highpass filter
21
Magnitude (dB)
-0.5
-1
-1.5
-2
-2.5
0.55
0.6
0.65
0.7
0.75
0.8
0.85
0.9
0.95
22
ellip()
7
/ (0.2188, 0.2207) (0.5723, 0.5762)
Magnitude (dB)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
Phase (degrees)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Figure 5.vi.2: Magnitude and phase responses for the IIR bandpass filter
23
Magnitude (dB)
-5
-10
-15
-20
-25
0.2
0.25
0.3
0.35
0.4
0.45
0.5
0.55
0.6
24
Conclusion
Through the course of this lab, we learned how filters can be implemented and convolutions
performed using c code, along with how to generate the filter coecients for FIR and IIR
low-, high- and bandpass filters using standard matlab functions.
While our experimental values seem to dier from our theoretical ones a bit, this likely has
to do with our failing to record the original input signal amplitude.
25
Matlab Code
1
2
3
4
5
%% Preliminary shit
ytexlabel = @(str) ylabel(str, interpreter, latex, FontUnits, points, FontSize, 16);
xtexlabel = @(str) xlabel(str, interpreter, latex, FontUnits, points, FontSize, 16);
textitle = @(str) title(str, interpreter, latex, FontUnits, points, FontSize, 20);
redline = @(x,y) plot(x, y, :r);
6
7
8
9
10
11
12
13
14
15
16
% Plot
figure(1);
17
18
19
20
21
22
23
24
% Magnitude
subplot(2, 1, 1);
plot(w/pi, magnitude(h))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Lowpass Filter Response);
25
26
27
28
29
30
31
hold on;
transitionBandStart = w( find(magnitude(h) < -3, 1))/pi;
transitionBandEnd = w( find(magnitude(h) < -40, 1))/pi;
redline([transitionBandStart transitionBandStart], [-300, 100]);
redline([transitionBandEnd transitionBandEnd],[-300, 100]);
hold off;
32
33
34
35
36
37
38
% Phase
subplot(2, 1, 2);
plot(w/pi, phi)
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Phase (degrees));
39
40
41
42
43
44
45
46
47
48
49
% In close magnitude
figure(2)
plot(w(1:103)/pi, magnitude(h(1:103)))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Lowpass Filter Response);
50
51
26
52
53
54
55
56
57
58
59
60
61
% Plot
figure(1);
62
63
64
65
66
67
68
69
% Magnitude
subplot(2, 1, 1);
plot(w/pi, magnitude(h))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Highpass Filter Response);
70
71
72
73
74
75
76
hold on;
transitionBandStart = w( find( magnitude(h) > -40, 1) )/pi;
transitionBandEnd = w( find( magnitude(h) > -3, 1) )/pi;
redline([transitionBandStart transitionBandStart], [-300, 100]);
redline([transitionBandEnd transitionBandEnd],[-300, 100]);
hold off;
77
78
79
80
81
82
83
% Phase
subplot(2, 1, 2);
plot(w/pi, phi)
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Phase (degrees));
84
85
86
87
88
89
90
91
92
93
94
% In close magnitude
figure(2)
plot(w( find(magnitude(h) > -3, 1) :end)/pi, magnitude(h( find(magnitude(h) > -3, 1) :end)))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Highpass Filter Response);
95
96
97
98
99
100
101
102
103
104
105
% Plot
27
106
figure(1);
107
108
109
110
111
112
113
114
% Magnitude
subplot(2, 1, 1);
plot(w/pi, magnitude(h))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Bandpass Filter Response);
115
116
117
118
119
120
hold on;
firstTransitionBandStartIndex = find(magnitude(h) > -40, 1);
firstTransitionBandEndIndex = find(magnitude(h) > -3, 1);
secondTransitionBandStartIndex = firstTransitionBandEndIndex + find( magnitude(h(firstTransitionBandEndI
secondTransitionBandEndIndex = firstTransitionBandEndIndex + find( magnitude(h(firstTransitionBandEndInd
121
122
123
124
125
firstTransitionBandStart = w(firstTransitionBandStartIndex)/pi;
firstTransitionBandEnd = w(firstTransitionBandEndIndex)/pi;
secondTransitionBandStart = w(secondTransitionBandStartIndex)/pi;
secondTransitionBandEnd = w(secondTransitionBandEndIndex)/pi;
126
127
128
129
130
131
132
133
134
135
136
137
138
% Phase
subplot(2, 1, 2);
plot(w/pi, phi)
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Phase (degrees));
139
140
141
142
143
144
145
146
147
148
149
% In close magnitude
figure(2)
plot(w(firstTransitionBandEndIndex:secondTransitionBandStartIndex)/pi, magnitude(h(firstTransitionBandEn
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Bandpass Filter Response);
150
151
152
153
154
155
156
157
158
%% Print coefficients
fprintf(lowpass = )
fprintf([);
fprintf(%0.20f ,, low);
fprintf(\n);
159
28
160
161
162
163
fprintf(highpass = )
fprintf([);
fprintf(%0.20f, , high);
fprintf(\n);
164
165
166
167
168
169
fprintf(bandpass = )
fprintf([);
fprintf(%0.20f ,, bpass);
fprintf(\n);
Figure 7.1: Matlab code used to generate FIR filter coecients and plots
in its entirety.
1
2
3
4
5
%% Preliminary shit
ytexlabel = @(str) ylabel(str, interpreter, latex, FontUnits, points, FontSize, 16);
xtexlabel = @(str) xlabel(str, interpreter, latex, FontUnits, points, FontSize, 16);
textitle = @(str) title(str, interpreter, latex, FontUnits, points, FontSize, 20);
redline = @(x,y) plot(x, y, :r);
6
7
8
9
10
11
12
13
14
15
16
% Plot
figure(1);
17
18
19
20
21
22
23
24
% Magnitude
subplot(2, 1, 1);
plot(w/pi, magnitude(h))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Lowpass Filter Response);
25
26
27
28
29
30
31
hold on;
transitionBandStart = w( find(magnitude(h) < -3, 1))/pi;
transitionBandEnd = w( find(magnitude(h) < -40, 1))/pi;
redline([transitionBandStart transitionBandStart], [-300, 100]);
redline([transitionBandEnd transitionBandEnd],[-300, 100]);
hold off;
32
33
34
35
36
37
38
% Phase
subplot(2, 1, 2);
plot(w/pi, phi)
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Phase (degrees));
39
29
40
41
42
43
44
45
46
47
48
49
% In close magnitude
figure(2)
plot(w(1:103)/pi, magnitude(h(1:103)))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Lowpass Filter Response);
50
51
52
53
54
55
56
57
58
59
60
61
% Plot
figure(1);
62
63
64
65
66
67
68
69
% Magnitude
subplot(2, 1, 1);
plot(w/pi, magnitude(h))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Highpass Filter Response);
70
71
72
73
74
75
76
hold on;
transitionBandStart = w( find( magnitude(h) > -40, 1) )/pi;
transitionBandEnd = w( find( magnitude(h) > -3, 1) )/pi;
redline([transitionBandStart transitionBandStart], [-300, 100]);
redline([transitionBandEnd transitionBandEnd],[-300, 100]);
hold off;
77
78
79
80
81
82
83
% Phase
subplot(2, 1, 2);
plot(w/pi, phi)
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Phase (degrees));
84
85
86
87
88
89
90
91
92
93
% In close magnitude
figure(2)
plot(w( find(magnitude(h) > -3, 1) :end)/pi, magnitude(h( find(magnitude(h) > -3, 1) :end)))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
30
94
95
96
97
98
99
100
101
102
103
104
105
106
% Plot
figure(1);
107
108
109
110
111
112
113
114
% Magnitude
subplot(2, 1, 1);
plot(w/pi, magnitude(h))
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Magnitude (dB));
textitle(Bandpass Filter Response);
115
116
117
118
119
120
hold on;
firstTransitionBandStartIndex = find(magnitude(h) > -40, 1);
firstTransitionBandEndIndex = find(magnitude(h) > -3, 1);
secondTransitionBandStartIndex = firstTransitionBandEndIndex + find( magnitude(h(firstTransitionBandEndI
secondTransitionBandEndIndex = firstTransitionBandEndIndex + find( magnitude(h(firstTransitionBandEndInd
121
122
123
124
125
firstTransitionBandStart = w(firstTransitionBandStartIndex)/pi;
firstTransitionBandEnd = w(firstTransitionBandEndIndex)/pi;
secondTransitionBandStart = w(secondTransitionBandStartIndex)/pi;
secondTransitionBandEnd = w(secondTransitionBandEndIndex)/pi;
126
127
128
129
130
131
132
133
134
135
136
137
138
% Phase
subplot(2, 1, 2);
plot(w/pi, phi)
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
ytexlabel(Phase (degrees));
139
140
141
142
143
144
145
146
147
% In close magnitude
figure(2)
plot(w(firstTransitionBandEndIndex:secondTransitionBandStartIndex)/pi, magnitude(h(firstTransitionBandEn
grid on;
xtexlabel(Normalized Frequency ($\times\pi$ rad/sample))
31
148
149
ytexlabel(Magnitude (dB));
textitle(Bandpass Filter Response);
150
151
152
153
154
155
156
157
158
%% Print coefficients
fprintf(lowpass = )
fprintf([);
fprintf(%0.20f ,, low);
fprintf(\n);
159
160
161
162
163
fprintf(highpass = )
fprintf([);
fprintf(%0.20f, , high);
fprintf(\n);
164
165
166
167
168
169
fprintf(bandpass = )
fprintf([);
fprintf(%0.20f ,, bpass);
fprintf(\n);
Figure 7.2: Matlab code used to generate IIR filter coecients and plots
in its entirety.
32