📄 iir_order.c
字号:
/*****************************************************************************/
/* */
/* FILENAME */
/* IIR_order.c */
/* */
/* DESCRIPTION */
/* TMS320C5416 DSK. */
/* Infinite Impulse Response filters (IIR) from 1st order to fifth order. */
/* */
/* Takes an input from a microphone or from a CD player and feeds through */
/* through low pass and high pass IIR filters to loudspeakers. */
/* Bargraph calibrated in steps of 3 dB. */
/* */
/* REVISION */
/* Revision: 1.00 */
/* Author : Richard Sikora */
/*---------------------------------------------------------------------------*/
/* */
/* HISTORY */
/* Revision 1.00 */
/* 30th October 2002. Created by Richard Sikora. */
/* */
/*****************************************************************************/
#include <stdio.h> /* Required for functions printf() and puts() */
/*****************************************************************************/
/* */
/* The name of the following header file will change if used as part of a */
/* different project. The new project xxxx will use xxxxcfg.h instead. */
/* */
/*****************************************************************************/
#include "IIR_ordercfg.h"
#include "dsk5416.h"
#include "dsk5416_pcm3002.h"
#include "bargraph.h"
#include "switches.h"
#include "IIR_filters_first_order.h"
#include "IIR_filters_second_order.h"
#include "IIR_filters_fourth_order.h"
#include "IIR_low_pass_filters.h"
#include "IIR_high_pass_filters.h"
/*****************************************************************************/
/* Configuration setup of registers of PCM3002 Codec */
/*****************************************************************************/
DSK5416_PCM3002_Config setup = {
0x1FF, // Set-Up Reg 0 - Left channel DAC attenuation
0x1FF, // Set-Up Reg 1 - Right channel DAC attenuation
0x0, // Set-Up Reg 2 - Various ctl e.g. power-down modes
0x0 // Set-Up Reg 3 - Codec data format control
};
/*****************************************************************************/
/* */
/* For compatibility with pcm3002 read / write, these variables must */
/* be declared as Int16 or short int, rather than int. */
/* */
/*****************************************************************************/
Int16 left_input;
Int16 left_output;
Int16 right_input;
Int16 right_output;
Int16 mono_input;
/*****************************************************************************/
/* UserTask() */
/*---------------------------------------------------------------------------*/
/* */
/* The main user task. */
/* */
/* Note that this task is not called by main(). It is scheduled by DSP/BIOS */
/* */
/*****************************************************************************/
void UserTask()
{
DSK5416_PCM3002_CodecHandle hCodec;
unsigned long i;
unsigned int switch_value;
signed int temp;
/* Start the codec */
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
/* Display project details on StdOut. \n is important. */
puts("TMS320C5416 DSK: IIR Filters, first order to fifth order. Bargraph at 6 dB intervals.\n");
for ( i = 0 ; i < 12000000 ; i++ )
{
/* Read left input channel */
while (!DSK5416_PCM3002_read16(hCodec, &left_input));
/* Output to left output channel */
while (!DSK5416_PCM3002_write16(hCodec, left_output));
if ( 0 == switch_value)
{
left_output = left_input;
}
else if ( 1 == switch_value)
{
/* First order low pass filter */
left_output = first_order_IIR_direct_form_I ( &first_order_low_pass_2000Hz[0], left_input);
}
else if ( 2 == switch_value)
{
/* Second order low pass filter */
left_output = second_order_IIR_direct_form_I ( &IIR_low_pass_2000Hz[0], left_input);
}
else if ( 3 == switch_value)
{
/* Create 3rd order filter by cascading first order and second order filters */
temp = first_order_IIR_direct_form_I ( &first_order_low_pass_2000Hz[0], left_input);
left_output = second_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], temp);
}
else if ( 4 == switch_value)
{
/* Fourth order low pass filter */
left_output = fourth_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], left_input);
}
else if ( 5 == switch_value)
{
/* Create 5th order filter by cascading first order and fourth order filters */
temp = first_order_IIR_direct_form_I ( &first_order_low_pass_2000Hz[0], left_input);
left_output = fourth_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], temp );
}
else if ( 6 == switch_value)
{
/* First order high pass filter */
left_output = first_order_IIR_direct_form_I ( &first_order_high_pass_2000Hz[0], left_input);
}
else if ( 7 == switch_value)
{
/* Second order high pass filter */
left_output = second_order_IIR_direct_form_I( &IIR_high_pass_2000Hz[0], left_input);
}
else if ( 8 == switch_value)
{
/* Third order high pass filter */
temp = first_order_IIR_direct_form_I ( &first_order_high_pass_2000Hz[0], left_input);
left_output = second_order_IIR_direct_form_I (&IIR_high_pass_2000Hz[0], temp);
}
else if ( 9 == switch_value)
{
/* Fourth order high pass filter */
left_output = fourth_order_IIR_direct_form_I( &IIR_high_pass_2000Hz[0], left_input);
}
else if ( 10 == switch_value)
{
/* Fifth order high pass filter */
temp = first_order_IIR_direct_form_I ( &first_order_high_pass_2000Hz[0], left_input);
left_output = fourth_order_IIR_direct_form_I (&IIR_high_pass_2000Hz[0], temp);
}
else if ( 11 == switch_value)
{
/* First order combined high pass and low pass filter */
left_output = first_order_IIR_direct_form_I ( &first_order_low_pass_2000Hz[0], mono_input);
}
else if ( 12 == switch_value)
{
/* Second order combined high pass and low pass filter */
left_output = second_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], mono_input);
}
else if ( 13 == switch_value)
{
/* Third order combined high pass and low pass filter */
temp = first_order_IIR_direct_form_I ( &first_order_low_pass_2000Hz[0], mono_input);
left_output = second_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], temp);
}
else if ( 14 == switch_value)
{
/* Fourth order combined high pass and low pass filter */
left_output = fourth_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], mono_input);
}
else if ( 15 == switch_value)
{
/* Fifth order combined high pass and low pass filters */
temp = first_order_IIR_direct_form_I ( &first_order_low_pass_2000Hz[0], mono_input);
left_output = fourth_order_IIR_direct_form_I( &IIR_low_pass_2000Hz[0], temp);
}
/* Read right input channel */
while (!DSK5416_PCM3002_read16(hCodec, &right_input));
/* Output to right output channel */
while (!DSK5416_PCM3002_write16(hCodec, right_output));
/* Read user switches on DSK and display their meaning on Stdout. */
switch_value = switch_status_display();
/* Where required, generate mono input from left input and right input */
mono_input = stereo_to_mono ( left_input, right_input);
if ( 0 == switch_value)
{
right_output = right_input;
}
else if ( 1 == switch_value)
{
/* First order low pass filter */
right_output = first_order_IIR_direct_form_II (&first_order_low_pass_2000Hz[0], right_input);
}
else if ( 2 == switch_value)
{
/* Second order low pass filter */
right_output = second_order_IIR_direct_form_II (&IIR_low_pass_2000Hz[0], right_input);
}
else if ( 3 == switch_value)
{
/* Create 3rd order filter by cascading first order and second order filters */
temp = first_order_IIR_direct_form_II (&first_order_low_pass_2000Hz[0], right_input);
right_output = second_order_IIR_direct_form_II (&IIR_low_pass_2000Hz[0], temp);
}
else if ( 4 == switch_value)
{
/* Fourth order low pass filter */
right_output = fourth_order_IIR_direct_form_II( &IIR_low_pass_2000Hz[0], right_input);
}
else if ( 5 == switch_value)
{
/* Create 5th order filter by cascading first order and fourth order filters */
temp = first_order_IIR_direct_form_II (&first_order_low_pass_2000Hz[0], right_input);
right_output = fourth_order_IIR_direct_form_II( &IIR_low_pass_2000Hz[0], temp );
}
else if ( 6 == switch_value)
{
/* First order high pass filter */
right_output = first_order_IIR_direct_form_II (&first_order_high_pass_2000Hz[0], right_input);
}
else if ( 7 == switch_value)
{
/* Second order high pass filter */
right_output = second_order_IIR_direct_form_II (&IIR_high_pass_2000Hz[0], right_input);
}
else if ( 8 == switch_value)
{
/* Third order high pass filter */
temp = first_order_IIR_direct_form_II (&first_order_high_pass_2000Hz[0], right_input);
right_output = second_order_IIR_direct_form_II (&IIR_high_pass_2000Hz[0], temp);
}
else if ( 9 == switch_value)
{
/* Fourth order high pass filter */
right_output = fourth_order_IIR_direct_form_II( &IIR_high_pass_2000Hz[0], right_input);
}
else if ( 10 == switch_value)
{
/* Fifth order high pass filter */
temp = first_order_IIR_direct_form_II (&first_order_high_pass_2000Hz[0], right_input);
right_output = fourth_order_IIR_direct_form_II (&IIR_high_pass_2000Hz[0], temp);
}
else if ( 11 == switch_value)
{
/* First order combined high pass and low pass filter */
right_output = first_order_IIR_direct_form_II (&first_order_high_pass_2000Hz[0], mono_input);
}
else if ( 12 == switch_value)
{
/* Second order combined high pass and low pass filter */
right_output = second_order_IIR_direct_form_II (&IIR_high_pass_2000Hz[0], mono_input);
}
else if ( 13 == switch_value)
{
/* Third order combined high pass and low pass filter */
temp = first_order_IIR_direct_form_II ( &first_order_high_pass_2000Hz[0], mono_input);
right_output = second_order_IIR_direct_form_II (&IIR_high_pass_2000Hz[0], temp);
}
else if ( 14 == switch_value)
{
/* Fourth order combined high pass and low pass filter */
right_output = fourth_order_IIR_direct_form_II( &IIR_high_pass_2000Hz[0], mono_input);
}
else if ( 15 == switch_value)
{
/* Fifth order combined high pass and low pass filters */
temp = first_order_IIR_direct_form_II ( &first_order_high_pass_2000Hz[0], mono_input);
right_output = fourth_order_IIR_direct_form_II( &IIR_high_pass_2000Hz[0], temp);
}
/* Display greater of two outputs on bargraph */
bargraph_6dB( left_output, right_output);
}
/* Finished processing. Close the codec */
DSK5416_PCM3002_closeCodec(hCodec);
puts("TMS320C5416 DSK has terminated\n");
}
/*****************************************************************************/
/* main() */
/*****************************************************************************/
void main()
{
/* Initialize the board support library */
/* There is no need to initialize the DIP switches and the LEDs */
DSK5416_init();
/* All other functions are scheduled by DSP/BIOS */
}
/******************************************************************************/
/* End of IIR_order.c */
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -