⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fir_windows.c

📁 dsp5416 fir windows程序源码
💻 C
字号:
/*****************************************************************************/
/*                                                                           */
/* FILENAME                                                                  */
/* 	FIR_windows.c                                                            */
/*                                                                           */
/* DESCRIPTION                                                               */
/*   Program to show the effect of different window functions on the finite  */
/*   impulse response (FIR) filter using the TMS320C5416 DSK.                */
/*   Uses Rectangular, Hamming, Hanning, Blackman and Kaise windows to       */
/*   implement 1200 Hz high pass and low pass filters using 48000 Hz         */
/*   sampling rate.                                                          */
/*                                                                           */
/*   The bargraph is calibrated in units of 3 dB.                            */
/*                                                                           */
/* REVISION                                                                  */
/*   Revision: 1.00	                                                         */
/*   Author  : Richard Sikora                                                */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* HISTORY                                                                   */
/*   Revision 1.10                                                           */
/*   27th November 2002. Modified for 48000 Hz sampling rate.                */
/*   Revision 1.00                                                           */
/*   3rd November 2002. Created by Richard Sikora from TMS320C5402 code.     */
/*                                                                           */
/*****************************************************************************/

#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 "FIR_windowscfg.h"

#include "dsk5416.h"
#include "dsk5416_pcm3002.h"

#include "bargraph.h"
#include "switches.h"
#include "stereo.h"

#include "FIR_filters_asm.h"

#include "blackman_high_pass_filter_1200Hz.h"
#include "hamming_high_pass_filter_1200Hz.h"  
#include "hanning_high_pass_filter_1200Hz.h"
#include "kaiser_high_pass_filter_1200Hz.h"
#include "rectangular_high_pass_filter_1200Hz.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 long dual_output;
       
    /* Start the codec */
    hCodec = DSK5416_PCM3002_openCodec(0, &setup);
 
    /* Display project details on StdOut. \n is important. */
 
    puts("TMS320C5416 DSK: FIR filters using different window functions. Mono. Bargraph at 6dB intervals.\n");
    
    /* Clear buffers used for FIR filters to zero */      
    FIR_filters_asm_initialize();      
          
    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));

      mono_input = stereo_to_mono( left_input, right_input);

      /* Read user switches on DSK and display their meaning on Stdout. */
      switch_value = switch_status_display();

      /* Display greater of two outputs on bargraph in 6 dB intervals. */
      bargraph_6dB ( left_output, right_output );
      
      /* Read right input channel */
      while (!DSK5416_PCM3002_read16(hCodec, &right_input));

      /* Output to right output channel */
      while (!DSK5416_PCM3002_write16(hCodec, right_output));

      if ( 0 == switch_value)
        {
          /* Straight through for unfiltered reference */
          left_output = left_input >> 1;
          right_output = right_input >> 1;
        }
      else if ( 1 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using rectangular windows */
          left_output = FIR_filter_asm ( &rectangular_high_pass_filter_1200Hz[0], mono_input); 
          right_output = left_output;
        }
      else if ( 2 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using Hamming window */
          left_output = FIR_filter_asm ( &hamming_high_pass_filter_1200Hz[0], mono_input);        
          right_output = left_output;
        } 
      else if ( 3 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using Hanning window */
          left_output = FIR_filter_asm ( &hanning_high_pass_filter_1200Hz[0], mono_input);          
          right_output = left_output;
        }  
      else if ( 4 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using Blackman window */
          left_output = FIR_filter_asm ( &blackman_high_pass_filter_1200Hz[0], mono_input);
          right_output = left_output;                     
        }
      else if ( 5 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using Kaiser window */
          left_output = FIR_filter_asm ( &kaiser_high_pass_filter_1200Hz[0], mono_input);
          right_output = left_output;                     
        }         
      else if ( 6 == switch_value)
        {
          /* 1200 Hz low pass FIR filter using rectangular windows */
          dual_output = FIR_dual_filter_asm ( &rectangular_high_pass_filter_1200Hz[0] , mono_input);
          left_output = (signed int)( dual_output & 0xFFFF);
          right_output = left_output;
        }
      else if ( 7 == switch_value)
        {
          /* 1200 Hz low pass FIR filter using Hamming window */
          dual_output = FIR_dual_filter_asm ( &hamming_high_pass_filter_1200Hz[0], mono_input); 
          left_output = (signed int)( dual_output & 0xFFFF); 
          right_output = left_output;                
        } 
      else if ( 8 == switch_value)
        {
          /* 1200 Hz low pass FIR filter using Hanning window */
          dual_output = FIR_dual_filter_asm ( &hanning_high_pass_filter_1200Hz[0], mono_input);  
          left_output = (signed int)( dual_output & 0xFFFF);
          right_output = left_output;                  
        }  
      else if ( 9 == switch_value)
        {
          /* 1200 Hz low pass FIR filter using Blackman window */
          dual_output = FIR_dual_filter_asm ( &blackman_high_pass_filter_1200Hz[0], mono_input); 
          left_output = (signed int)( dual_output & 0xFFFF);
          right_output = left_output;          
        } 
      else if ( 10 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using Kaiser window */
          left_output = FIR_dual_filter_asm ( &kaiser_high_pass_filter_1200Hz[0], mono_input);
          right_output = left_output;                     
        }        
      else if ( 11 == switch_value)
        {
          /* 1200 Hz low pass / high pass FIR filter using rectangular windows */
          dual_output = FIR_dual_filter_asm ( &rectangular_high_pass_filter_1200Hz[0] , mono_input);
          left_output = (signed int)( dual_output >> 16);
          right_output = (signed int) ( dual_output & 0xFFFF );
          left_output >>= 1; /* Attenuate treble */
        }
      else if ( 12 == switch_value)
        {
          /* 1200 Hz low pass / high pass FIR filter using Hamming window */
          dual_output = FIR_dual_filter_asm ( &hamming_high_pass_filter_1200Hz[0], mono_input); 
          left_output = (signed int)( dual_output >> 16);   
          right_output = (signed int) ( dual_output & 0xFFFF);
          left_output >>= 1; /* Attenuate treble */                        
        } 
      else if ( 13 == switch_value)
        {
          /* 1200 Hz low pass / high pass FIR filter using Hanning window */
          dual_output = FIR_dual_filter_asm ( &hanning_high_pass_filter_1200Hz[0], mono_input);  
          left_output = (signed int)( dual_output >> 16);
          right_output = (signed int) ( dual_output & 0xFFFF );
          left_output >>= 1;  /* Attenuate treble */                            
        }  
      else if ( 14 == switch_value)
        {
          /* 1200 Hz low pass / high pass FIR filter using Blackman window */
          dual_output = FIR_dual_filter_asm ( &blackman_high_pass_filter_1200Hz[0], mono_input); 
          left_output = (signed int)( dual_output >> 16); 
          right_output = (signed int) ( dual_output & 0xFFFF );
          left_output >>= 1; /* Attenuate treble */                    
        } 
      else if ( 15 == switch_value)
        {
          /* 1200 Hz high pass FIR filter using Kaiser window */
          dual_output = FIR_dual_filter_asm ( &kaiser_high_pass_filter_1200Hz[0], mono_input);
          left_output = (signed int)( dual_output >> 16); 
          right_output = (signed int) ( dual_output & 0xFFFF );
          left_output >>= 1; /* Attenuate treble */                               
        }
  
     }

    /* 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 FIR_windows.c                                                       */
/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -