Quantcast
Channel: Processors
Viewing all articles
Browse latest Browse all 124602

Forum Post: Matlab fdatool and C5505 ezdsp

$
0
0

I've been trying to create my own filters for use in the ezdsp usb development tool, but nothing I do seems to work. I've been using matlab's fdatool to generate filter coefficients. Right now, I'm only trying to recreate an example filter with the fdatool's coefficients. It is a fourth order lowpass filter with a cutoff frequency of 600Hz and second order sections.

This is the output of the fdatool:

#define MWSPT_NSEC 5
const int NL[MWSPT_NSEC] = { 1,3,1,3,1 };
const int16_T NUM[MWSPT_NSEC][3] = {
{
49, 0, 0
},
{
32767, 32767, 32767
},
{
14, 0, 0
},
{
32767, 32767, 32767
},
{
29205, 0, 0
}
};
const int DL[MWSPT_NSEC] = { 1,3,1,3,1 };
const int16_T DEN[MWSPT_NSEC][3] = {
{
32767, 0, 0
},
{
32767, -32768, 32058
},
{
32767, 0, 0
},
{
32767, -32768, 31079
},
{
32767, 0, 0
}
};

and this is the code that I've altered to attempt to use the coefficients:

signed int fourth_order_IIR_direct_form_II ( signed int input)
{
long temp;
static short int delay[2][3] = { 0, 0, 0, 0, 0, 0};
unsigned int stages;
const signed int xco[2][3] = {32767, 32767, 32767, 32767, 32767, 32767};
const signed int yco[2][3] = {32767, -32768, 32058, 32767, -32768, 31079};
const signed int amp[2] = {49, 14};
// Copy input to temp for temporary storage

temp = (long) input;

for ( stages = 0 ; stages < 2 ; stages++)
{
// Process denominator coefficients
temp *= amp[stages];

temp >>= 15;

delay[stages][0] = (signed int) temp;

temp = (((long) yco[stages][0] * delay[stages][0]) >> 7); // Divide by 128

temp -= ( (long) yco[stages][1] * delay[stages][1] ); // A1/2

temp -= ( (long) yco[stages][1] * delay[stages][1] ); // A1/2

temp -= ( (long) yco[stages][2] * delay[stages][2] );

temp >>= 15; // Divide temp by coefficients[A0]

if ( temp > 32767)
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}

delay[stages][0] = ( signed int ) temp;

// Process numerator coefficients

temp = ((long) xco[stages][0] * delay[stages][0] );

temp += ((long) xco[stages][1] * delay[stages][1] ) ; // B1/2

temp += ((long) xco[stages][1] * delay[stages][1] ) ; // B1/2

temp += ((long) xco[stages][2] * delay[stages][2] ) ;

delay[stages][2] = delay[stages][1];
delay[stages][1] = delay[stages][0];

// Divide temp by coefficients[A0] then multiply by 128

temp >>= (15 - 7);

// Range limit temp between maximum and minimum

if ( temp > 32767)
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}

// Temp will be fed into input of filter next time through
}

temp *= 29205;
temp >>= 15;
return ( (short int) temp );
}

The coefficients are used somewhat awkwardly since the dsp unit only handles fixed point values. Can anyone tell me what I'm doing incorrectly here? I apologize in advance if I haven't included enough information.


Viewing all articles
Browse latest Browse all 124602

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>