Vous êtes sur la page 1sur 27

EECS 152B/CES135B: Implement FIR and IIR Filters

Due on Tuesday, February 26, 2013

ORourke 2:00pm

Christopher Pham 88576960


Kevin Sison 86974045

1
CONTENTS EECS 152B/CES135B Implement FIR and IIR Filters

Contents
Problem 1 3
Lowpass FIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Problem 2 7
Highpass FIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Problem 3 11
Bandpass FIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Problem 4 16
Lowpass IIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Problem 5 20
Highpass IIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Problem 6 24
Bandpass IIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Page 2 of 27
EECS 152B/CES135B Implement FIR and IIR Filters

Problem 1
Lowpass FIR Filter
Implement an FIR filter for low pass filtering.

Lowpass frequency response from Matlab

Passband zoomed for Lowpass frequency response

Problem 1 continued on next page. . . Page 3 of 27


Lowpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 1 (continued)

Oscilloscope of our Lowpass filter applied to the 3 Pure Sinusoid file

Problem 1 continued on next page. . . Page 4 of 27


Lowpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 1 (continued)

Listing 1: C Code for FIR Lowpass filter


#include "dsk6713_aic23.h"
#include "lp75.h"

#define DSK6713_AIC23_INPUT_MIC 0x0015


5 #define DSK6713_AIC23_INPUT_LINEIN 0x0011

Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011
short inShort;
10 f l o a t input[75];
f l o a t y = 0;
short ys;
int i;
int j;
15

void main()
{
comm_poll();

20 while(1)
{
inShort = input_left_channel();

input[0] = ( f l o a t )inShort;
25

input[0] /= 10000;
y = 0;

for(i=0; i < 75; i++)


30 {
y += (lowpass[i] * input[i]);
}

for(j=74; j > 0; j--)


35 {
input[j] = input[j-1];
}

y *= 1000;
40 ys = (short)y;

output_left_sample(ys);
}
}

Problem 1 continued on next page. . . Page 5 of 27


Lowpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 1 (continued)

Listing 2: Matlab code for FIR Lowpass filter


f_lp = 1760; %Cutoff frequency for Low Pass Filter
Fs = 16000; %Sampling Frequency

Wn = f_lp/(Fs/2); %Cutoff frequency


5 win = kaiser(75,3.86); %Hanning window
b = fir1(74, Wn, win); %FIR filter design using window method
[g] = zp2sos(z,p,k);
freqz(b) %Digital filter frequency response

10 file = fopen(lp75.h,w); %Open file

fprintf(file, float lowpass[75]={); %Write formatted data to text file


fprintf(file, %d, , b(1:74));
fprintf(file, %d, b(75));
15 fprintf(file, };\n);
fclose(file); %Close file

Listing 3: lp75.h
f l o a t lowpass[75]={3.663493e-04, -2.658213e-04, -1.053694e-03, -1.559787e-03,
-1.350120e-03, -2.722435e-04, 1.353100e-03, 2.771166e-03, 3.105759e-03,
1.834415e-03, -8.093653e-04, -3.759031e-03, -5.489628e-03, -4.744107e-03,
-1.290370e-03, 3.701649e-03, 7.955725e-03, 9.048265e-03, 5.661719e-03,
5 -1.469770e-03, -9.485162e-03, -1.441258e-02, -1.297701e-02, -4.437347e-03,
8.469433e-03, 2.012731e-02, 2.419536e-02, 1.658128e-02, -2.015164e-03,
-2.524064e-02, -4.258587e-02, -4.296134e-02, -1.912323e-02, 2.878990e-02,
9.215754e-02, 1.558964e-01, 2.030639e-01, 2.204460e-01, 2.030639e-01,
1.558964e-01, 9.215754e-02, 2.878990e-02, -1.912323e-02, -4.296134e-02,
10 -4.258587e-02, -2.524064e-02, -2.015164e-03, 1.658128e-02, 2.419536e-02,
2.012731e-02, 8.469433e-03, -4.437347e-03, -1.297701e-02, -1.441258e-02,
-9.485162e-03, -1.469770e-03, 5.661719e-03, 9.048265e-03, 7.955725e-03,
3.701649e-03, -1.290370e-03, -4.744107e-03, -5.489628e-03, -3.759031e-03,
-8.093653e-04, 1.834415e-03, 3.105759e-03, 2.771166e-03, 1.353100e-03,
15 -2.722435e-04, -1.350120e-03, -1.559787e-03, -1.053694e-03, -2.658213e-04,
3.663493e-04};

The filter order we used for this lowpass FIR filter was 74 using a Hanning window. The transition band
frequency is 0.06 radians per sample. We designed a hanning window using a the kaiser function and we
used the function FIR1 to design our filter. The gain for this filter is simply the sum of its coefficients, 1.
This gain value does indeed match the gain in the oscilloscope.

Page 6 of 27
EECS 152B/CES135B Implement FIR and IIR Filters Problem 1

Problem 2
Highpass FIR Filter
Implement an FIR filter for high pass filtering.

Highpass frequency response from Matlab

Passband zoomed for Highpass frequency response

Problem 2 continued on next page. . . Page 7 of 27


Highpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 2 (continued)

Oscilloscope of our Highpass filter applied to the 3 Pure Sinusoid file

Problem 2 continued on next page. . . Page 8 of 27


Highpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 2 (continued)

Listing 4: C Code for FIR Highpass filter


#include "dsk6713_aic23.h"
#include "hp75.h"

#define DSK6713_AIC23_INPUT_MIC 0x0015


5 #define DSK6713_AIC23_INPUT_LINEIN 0x0011

Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011

10 f l o a t input[75];
f l o a t y = 0;
short ys;
int i;
int j;
15 short inShort;

void main()
{
comm_poll();
20

while(1)
{
inShort = input_left_channel();

25 input[0] = ( f l o a t )inShort;
input[0] /= 10000;
y = 0;

for(i=0; i < 75; i++)


30 {
y += (highpass[i] * input[i]);
}

for(j=74; j > 0; j--)


35 {
input[j] = input[j-1];
}

y *= 1000;
40 ys = (short)y;

output_left_sample(ys);
}
}

Problem 2 continued on next page. . . Page 9 of 27


Highpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 2 (continued)

Listing 5: Matlab code for FIR Highpass filter


f_lp = 1760; %Cutoff frequency for Low Pass Filter
f_hp = 4560; %Cutoff frequency for High Pass Filter
Fs = 16000; %Sampling Frequency

5 Wn = f_hp/(Fs/2); %Cutoff frequency


win = kaiser(75,3.86); %Hanning window
b = fir1(74, Wn, win); %FIR filter design using window method
g = firlp2hp(b); %FIR lowpass to highpass transformation
freqz(g) %Digital filter frequency response
10

file = fopen(lp75.h,w); %Open file

fprintf(file, float highpass[75]={); %Write formatted data to text file


fprintf(file, %d, , b(1:74));
15 fprintf(file, %d, b(75));
fprintf(file, };\n);
fclose(file); %Close file

Listing 6: hp75.h
f l o a t highpass[75]={-2.394542e-04, 1.064131e-03, -2.032407e-04, -1.449515e-03,
1.038450e-03, 1.483255e-03, -2.168201e-03, -8.981727e-04, 3.317254e-03,
-4.760582e-04, -4.053910e-03, 2.607603e-03, 3.872124e-03, -5.185693e-03,
-2.326875e-03, 7.604197e-03, -8.032495e-04, -9.025818e-03, 5.365352e-03,
5 8.527333e-03, -1.073507e-02, -5.302928e-03, 1.580368e-02, -1.117585e-03,
-1.905439e-02, 1.068972e-02, 1.869141e-02, -2.276555e-02, -1.271423e-02,
3.612908e-02, -1.344941e-03, -4.916148e-02, 2.802509e-02, 6.011001e-02,
-8.289118e-02, -6.740673e-02, 3.101262e-01, 5.697388e-01, 3.101262e-01,
-6.740673e-02, -8.289118e-02, 6.011001e-02, 2.802509e-02, -4.916148e-02,
10 -1.344941e-03, 3.612908e-02, -1.271423e-02, -2.276555e-02, 1.869141e-02,
1.068972e-02, -1.905439e-02, -1.117585e-03, 1.580368e-02, -5.302928e-03,
-1.073507e-02, 8.527333e-03, 5.365352e-03, -9.025818e-03, -8.032495e-04,
7.604197e-03, -2.326875e-03, -5.185693e-03, 3.872124e-03, 2.607603e-03,
-4.053910e-03, -4.760582e-04, 3.317254e-03, -8.981727e-04, -2.168201e-03,
15 1.483255e-03, 1.038450e-03, -1.449515e-03, -2.032407e-04, 1.064131e-03,
-2.394542e-04};

For this highpass FIR filter, we used the same filter order as the lowpass FIR filter, 74. As expected, the
transition band is also the same as the lowpass filter, 0.6 radians per sample. We used the filter we designed
in the lowpass filter using FIR1 and applied the firlp2hp function to transform it to a highpass FIR filter.
The gain of this FIR filter is 0.12 by adding up all the coefficients.

Page 10 of 27
EECS 152B/CES135B Implement FIR and IIR Filters Problem 2

Problem 3
Bandpass FIR Filter
Implement a FIR filter for band pass filtering.

Bandpass frequency response from Matlab

Stopband zoomed for Bandpass frequency response

Problem 3 continued on next page. . . Page 11 of 27


Bandpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 3 (continued)

Passband zoomed for Bandpass frequency response

Problem 3 continued on next page. . . Page 12 of 27


Bandpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 3 (continued)

Oscilloscope of our Bandpass filter applied to the 3 Pure Sinusoid file

Problem 3 continued on next page. . . Page 13 of 27


Bandpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 3 (continued)

Listing 7: C Code for FIR Bandpass filter


f_lp = 1760; %Cutoff frequency for Low Pass Filter
f_hp = 4560; %Cutoff frequency for High Pass Filter
Fs = 16000; %Sampling Frequency

5 Wn = f_lp/(Fs/2);
win = kaiser(75,3.86);
b1 = fir1(74, Wn, win);

Wn = f_hp/(Fs/2); %Cutoff frequency


10 win = kaiser(75,3.86); %Hanning window
b = fir1(74, Wn, win); %FIR filter design using window method
b2 = firlp2hp(b); %FIR lowpass to highpass transformation

A = horzcat(b2,b1)
15

freqz(A) %Digital filter frequency response

file = fopen(bp75.h,w); %Open file

20 fprintf(file, float bandpass[75]={); %Write formatted data to text file


fprintf(file, %d, , a(1:74));
fprintf(file, %d, a(75));
fprintf(file, };\n);
fclose(file); %Close file

Problem 3 continued on next page. . . Page 14 of 27


Bandpass FIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 3 (continued)

Listing 8: Matlab code for FIR Bandpass filter


f_lp = 1760; %Cutoff frequency for Low Pass Filter
f_hp = 4560; %Cutoff frequency for High Pass Filter
Fs = 16000; %Sampling Frequency

5 Wn = f_lp/(Fs/2);
win = kaiser(75,3.86);
b = fir1(74, Wn, win);

Wn = f_hp/(Fs/2); %Cutoff frequency


10 win = kaiser(75,3.86); %Hanning window
b = fir1(74, Wn, win); %FIR filter design using window method
g = firlp2hp(b); %FIR lowpass to highpass transformation

a = b + g;
15

freqz(a) %Digital filter frequency response

file = fopen(lp75.h,w); %Open file

20 fprintf(file, float bandpass[75]={); %Write formatted data to text file


fprintf(file, %d, , b(1:74));
fprintf(file, %d, b(75));
fprintf(file, };\n);
fclose(file); %Close file

Listing 9: bp75.h
f l o a t bandpass[75]={0 2.128262e-03, -2.899031e-03, 2.966511e-03, -1.796345e-03,
-9.521165e-04, 5.215206e-03, -1.037139e-02, 1.520839e-02, -1.805164e-02,
1.705467e-02, -1.060586e-02, -2.235170e-03, 2.137944e-02, -4.553111e-02,
7.225815e-02, -9.832295e-02, 1.202200e-01, -1.348135e-01, 1.139478e+00,
5 -1.348135e-01, 1.202200e-01, -9.832295e-02, 7.225815e-02, -4.553111e-02,
2.137944e-02, -2.235170e-03, -1.060586e-02, 1.705467e-02, -1.805164e-02,
1.520839e-02, -1.037139e-02, 5.215206e-03, -9.521165e-04, -1.796345e-03,
2.966511e-03, -2.899031e-03, 2.128262e-03,};

We used a filter order of 74 to design this bandpass FIR filter. Both transition bands had frequencies of 0.6
radians per sample. We used both the lowpass and highpass filter we previously design and concatenated
them both which resulted in this bandpass FIR filter. The gain we resulted in was 1.12 for this filter.

Page 15 of 27
EECS 152B/CES135B Implement FIR and IIR Filters Problem 3

Problem 4
Lowpass IIR Filter
Implement an IIR filter for low pass filtering.

Lowpass frequency response from Matlab

Stopband zoomed for lowpass frequency response

Problem 4 continued on next page. . . Page 16 of 27


Lowpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 4 (continued)

Passband zoomed for lowpass frequency response

We could not get the filter to work because of the NAN seen above

Problem 4 continued on next page. . . Page 17 of 27


Lowpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 4 (continued)

Listing 10: C Code for IIR Lowpass filter


#include "dsk6713_aic23.h"
#include "LPIIRCoeff.h"

#define DSK6713_AIC23_INPUT_MIC 0x0015


5 #define DSK6713_AIC23_INPUT_LINEIN 0x0011

Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011

10 f l o a t d_samples[stages][2];

void main()
{
comm_poll();
15

while(1)
{
int i
f l o a t input, n, output;
20

input = input_sample(); //input to 1st stage


input /= 10000;

for (i = 0; i < stages; i++) //repeat for each stage


25 {
n = input - ((b[i][0]*d_samples[i][0])) -
((b[i][1]*d_samples[i][1]));

output = ((a[i][0]*n))+((a[i][1]*d_samples[i][0]))+
30 ((a[i][2]*d_samples[i][1]));

d_samples[i][1] = d_samples[i][0]; //update delays


d_samples[i][0] = n; //update delays
input = output; //intermediate output->in to next stage
35 }

output_sample(output);
}
}

Problem 4 continued on next page. . . Page 18 of 27


Lowpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 4 (continued)

Listing 11: Matlab code for IIR Lowpass filter


clc;
clear all;

f_lp = 1760; %Cutoff frequency for High Pass Filter


5

Fs = 16000; %Sampling Frequency

Wnlp = f_lp/(Fs/2); %Cutoff frequency for High Pass

10 [b,a] = ellip(6,5,40,Wnlp)
freqz(b,a,Fs)

[z,p,k] = ellip(6,5,40,Wnlp)
[sos,g] = zp2sos(z,p,k);
15

file = fopen(LPIIRCoeff.h,w); %Open file

fprintf(file, float a[7]={); %Write formatted data to text file


fprintf(file, %d, , a(1:7));
20 fprintf(file, %d, a(7));
fprintf(file, };\n \n);

fprintf(file, float b[7]={); %Write formatted data to text file


fprintf(file, %d, , b(1:7));
25 fprintf(file, %d, b(7));
fprintf(file, };\n);

fclose(file); %Close file

Listing 12: Coefficients for IIR Lowpass filter


f l o a t a[7]={1, -4.831379e+00, 1.051540e+01, -1.301538e+01,
9.631646e+00, -4.040198e+00, 7.557030e-01, 7.557030e-01};

f l o a t b[7]={1.650508e-02, -5.159464e-02, 9.519011e-02,


5 -1.113174e-01, 9.519011e-02, -5.159464e-02, 1.650508e-02,
1.650508e-02};

The filter order we used for this lowpass IIR filter was 6. The transition band frequency is 0.10 radians per
sample for this filter. We used the ellip function to design this filter. Then we used the dir2cas function to
transform it to second order cascaded form. The gain for this filter is 0.0165. We were not able to completely
run the C code because we continued to get a NaN error. We eventually realized the indexing for the array
a was off by one which caused it to explode.

Page 19 of 27
EECS 152B/CES135B Implement FIR and IIR Filters Problem 4

Problem 5
Highpass IIR Filter
Implement an IIR filter for high pass filtering.

Highpass frequency response from Matlab

Stopband zoomed for highpass frequency response

Problem 5 continued on next page. . . Page 20 of 27


Highpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 5 (continued)

Passband zoomed for highpass frequency response

We could not get the filter to work because of the NAN seen above

Problem 5 continued on next page. . . Page 21 of 27


Highpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 5 (continued)

Listing 13: C Code for FIR Highpass filter


#include "dsk6713_aic23.h"
#include "HPIIRCoeff.h"

#define DSK6713_AIC23_INPUT_MIC 0x0015


5 #define DSK6713_AIC23_INPUT_LINEIN 0x0011

Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011

10 f l o a t d_samples[stages][2];

void main()
{
comm_poll();
15

while(1)
{
int i
f l o a t input, n, output;
20

input = input_sample(); //input to 1st stage


input /= 10000;

for (i = 0; i < stages; i++) //repeat for each stage


25 {
n = input - ((b[i][0]*d_samples[i][0])) -
((b[i][1]*d_samples[i][1]));

output = ((a[i][0]*n))+((a[i][1]*d_samples[i][0]))+
30 ((a[i][2]*d_samples[i][1]));

d_samples[i][1] = d_samples[i][0]; //update delays


d_samples[i][0] = n; //update delays
input = output; //intermediate output->in to next stage
35 }

output_sample(output);
}
}

Problem 5 continued on next page. . . Page 22 of 27


Highpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 5 (continued)

Listing 14: Matlab code for FIR Highpass filter


clc;
clear all;

f_hp = 4560; %Cutoff frequency for High Pass Filter


5

Fs = 16000; %Sampling Frequency

Wnhp = f_hp/(Fs/2); %Cutoff frequency for High Pass

10 [b,a] = ellip(6,5,40,Wnhp, high)


freqz(b,a,Fs)

[z,p,k] = ellip(6,5,40,Wnhp, high)


[sos,g] = zp2sos(z,p,k);
15

file = fopen(HPIIRCoeff.h,w); %Open file

fprintf(file, float a[7]={); %Write formatted data to text file


fprintf(file, %d, , a(1:7));
20 fprintf(file, %d, a(7));
fprintf(file, };\n \n);

fprintf(file, float b[7]={); %Write formatted data to text file


fprintf(file, %d, , b(1:7));
25 fprintf(file, %d, b(7));
fprintf(file, };\n);

fclose(file); %Close file

Listing 15: Coefficients for FIR Highpass filter


f l o a t a[7]={1, 2.318884e+00, 4.154949e+00, 4.430225e+00,
3.578762e+00, 1.784131e+00, 5.813883e-01, 5.813883e-01};

f l o a t b[7]={4.418341e-02, -3.213190e-02, 1.103554e-01,


5 -6.633047e-02, 1.103554e-01, -3.213190e-02, 4.418341e-02,
4.418341e-02};

The filter order we used for this highpass IIR filter was 6. The transition band frequency is 0.12 radians
per sample for this filter. We used the ellip function to design this filter as we did for the lowpass IIR filter.
Then we used the dir2cas function to transform it to second order cascaded form. The gain for this filter
is 0.044. We were not able to completely run the C code because we continued to get a NaN error. We
eventually realized the indexing for the array a was off by one which caused it to explode.

Page 23 of 27
EECS 152B/CES135B Implement FIR and IIR Filters Problem 5

Problem 6
Bandpass IIR Filter
Implement a IIR filter for band pass filtering.

Bandpass frequency response from Matlab

Stopband zoomed for bandpass frequency response

Problem 6 continued on next page. . . Page 24 of 27


Bandpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 6 (continued)

Passband zoomed for bandpass frequency response

We could not get the filter to work because of the NAN seen above

Problem 6 continued on next page. . . Page 25 of 27


Bandpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 6 (continued)

Listing 16: C Code for FIR Bandpass filter

clc;
clear all;

5 f_lp = 1760; %Cutoff frequency for Low Pass Filter


f_hp = 4560; %Cutoff frequency for High Pass Filter

Fs = 16000; %Sampling Frequency

10 Wnlp = f_lp/(Fs/2); %Cutoff frequency for Low Pass


Wnhp = f_hp/(Fs/2); %Cutoff frequency for High Pass

[b,a] = ellip(6,5,40,[Wnlp Wnhp], bandpass)


freqz(b,a,Fs)
15

[z,p,k] = ellip(6,5,40,[Wnlp Wnhp], bandpass)


[sos,g] = zp2sos(z,p,k);

file = fopen(BPIIRCoeff.h,w); %Open file


20

fprintf(file, float a[7]={); %Write formatted data to text file


fprintf(file, %d, , a(1:7));
fprintf(file, %d, a(7));
fprintf(file, };\n \n);
25

fprintf(file, float b[7]={); %Write formatted data to text file


fprintf(file, %d, , b(1:7));
fprintf(file, %d, b(7));
fprintf(file, };\n);
30

fclose(file); %Close file

Listing 17: Matlab code for FIR Bandpass filter


#include "dsk6713_aic23.h"
#include "BPIIRCoeff.h"

#define DSK6713_AIC23_INPUT_MIC 0x0015


5 #define DSK6713_AIC23_INPUT_LINEIN 0x0011

Uint32 fs = DSK6713_AIC23_FREQ_16KHZ; // 1
Uint16 inputsource = DSK6713_AIC23_INPUT_LINEIN; // 0x011

10 f l o a t d_samples[stages][2];

void main()
{
comm_poll();
15

while(1)
{

Problem 6 continued on next page. . . Page 26 of 27


Bandpass IIR Filter EECS 152B/CES135B Implement FIR and IIR Filters Problem 6 (continued)

int i
f l o a t input, n, output;
20

input = input_sample(); //input to 1st stage


input /= 10000;

for (i = 0; i < stages; i++) //repeat for each stage


25 {
n = input - ((b[i][0]*d_samples[i][0])) -
((b[i][1]*d_samples[i][1]));

output = ((a[i][0]*n))+((a[i][1]*d_samples[i][0]))+
30 ((a[i][2]*d_samples[i][1]));

d_samples[i][1] = d_samples[i][0]; //update delays


d_samples[i][0] = n; //update delays
input = output; //intermediate output->in to next stage
35 }

output_sample(output);
}
}

Listing 18: Coefficients for IIR Lowpass Filter


#define stages 6

f l o a t a[stages][2] = {{ 0.427714, 0.992418 }, { 0.310930, 0.951266 },


{ -0.209451, 0.825137 },{ -1.103452, 0.856062 }, { -1.464358, 0.966783 },
5 { -1.534237, 0.995031 }};

f l o a t b[stages][3] = {{ 1.000000, 1.399709, 1.000000 },


{ 1.000000, 0.614281, 1.000000 }, { 1.000000, 0.488459, 1.000000 },
{ 1.000000, -1.562952, 1.000000 }, { 1.000000, -1.613234, 1.000000 },
10 { 1.000000, -1.862281, 1.000000 }};

The filter order we used for this highpass IIR filter was 6. The transition band frequency is 0.12 radians
per sample for this filter. We used the ellip function to design this filter as we did for the lowpass IIR filter.
Then we used the dir2case function to transform it to second order cascaded form. The gain for this filter
is 0.0299. We were not able to completely run the C code because we continued to get a NaN error. We
eventually realized the indexing for the array a was off by one which caused it to explode.

Page 27 of 27

Vous aimerez peut-être aussi