FIR Filter. C-Implementation (FIR filter) #include #include #include "coeff_ccs_16int.h" int in_buffer[300]; int out_buffer[300]; #define TRUE 1 /*Function.

Slides:



Advertisements
Similar presentations
Chapter 7 Linear Assembly
Advertisements

A Short Review Arrays, Pointers and Structures. What is an Array? An array is a collection of variables of the same type and placed in memory contiguously.
TMS320C6713 Assembly Language (cont’d). Module 1 Exam (solution) 1. Functional Units a. How many can perform an ADD? Name them. a. How many can perform.
Lecture 6 Programming the TMS320C6x Family of DSPs.
Assembly and Linear Assembly Evgeny Kirshin, 05/10/2011
 Instructor: Rob Nash  Readings: Chap 7-9  Midterm next Monday! ◦ Review this Wednesday ◦ You will see code again…
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Programming and Data Structure
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
EE 445S Real-Time Digital Signal Processing Lab Fall 2013 Lab #3.1 Digital Filters Chao Jia.
Software and Hardware Circular Buffer Operations First presented in ENCM There are 3 earlier lectures that are useful for midterm review. M. R.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
Sampling, Reconstruction, and Elementary Digital Filters R.C. Maher ECEN4002/5002 DSP Laboratory Spring 2002.
Pointers A pointer is a variable that contains memory address as its value. A variable directly contains a specific value. A pointer contains an address.
Starting Out with C++, 3 rd Edition 1 Chapter 9 – Pointers.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
EE 445S Real-Time Digital Signal Processing Lab Fall 2013 Lab #2 Generating a Sine Wave Using the Hardware & Software Tools for the TI TMS320C6748 DSP.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Pointer. What is pointer ? A Pointer is nothing but a variable that contains an address which is a location of another variable in memory. If one variable.
CS-1030 Dr. Mark L. Hornick 1 Pointers are fun!
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
ajay patil 1 TMS320C6000 Assembly Language and its Rules Assignment One of the simplest operations in C is to assign a constant to a variable: One.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Integer Types short month; // half of a machine word int car; // one machine word unsigned long distance; Character Types char c = ‘\0’; // one byte char.
6-1 Infineon 167 Interrupts The C167CS provides 56 separate interrupt sources that may be assigned to 16 priority levels. The C167CS uses a vectored interrupt.
32-Bit-Digital Signal Controller Texas Instruments Incorporated
Which one? You have a vector, a[ ], of random integers, which can modern CPUs do faster and why? //find max of vector of random ints max=0; for (inda=0;
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
Lecture 13: Arrays, Pointers, Code examples B Burlingame 2 Dec 2015.
1 CSC103: Introduction to Computer and Programming Lecture No 19.
CHAPTER 7: Arrays CSEB113 PRINCIPLES of PROGRAMMING CSEB134 PROGRAMMING I by Badariah Solemon 1BS (Feb 2012)
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
EE 345S Real-Time Digital Signal Processing Lab Fall 2007 Lab #2 Generating a Sine Wave Using the Hardware & Software Tools for the TI TMS320C6713 DSP.
Scis.regis.edu ● CS-362: Data Structures Week 6 Part 2 Dr. Jesús Borrego 1.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
EE 345S Real-Time Digital Signal Processing Lab Fall 2008 Lab #3 Generating a Sine Wave Using the Hardware & Software Tools for the TI TMS320C6713 DSP.
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
You learned how to declare pointer variables how to store the address of a variable into a pointer variable of the same type as the variable how to manipulate.
ECSE436 Tutorial Assembly and Linear Assembly Laurier Boulianne.
Chapter 7 Linear Assembly
Adaptive Filters Common filter design methods assume that the characteristics of the signal remain constant in time. However, when the signal characteristics.
Chapter 5: Loops and Files.
INC 161 , CPE 100 Computer Programming
Implementing real-time convolution
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
Chapter 17 Goertzel Algorithm
An Introduction to Java – Part I, language basics
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Functions with arrays.
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Getting serious about “going fast” on the TigerSHARC
Explaining issues with DCremoval( )
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
EE 345S Real-Time Digital Signal Processing Lab Fall 2007
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Introduction to Pointers
Presentation transcript:

FIR Filter

C-Implementation (FIR filter) #include #include #include "coeff_ccs_16int.h" int in_buffer[300]; int out_buffer[300]; #define TRUE 1 /*Function */ static int firfilter(int *input, int *output); static void dataIO(void);

void main() { /* Declare file pointers */ int *input = &inp_buffer[0]; int *output= &out_buffer[0]; /* Start of main program */ while(TRUE) while(TRUE) { dataIO(); / * insert probe point &attach.dat file dataIO(); / * insert probe point &attach.dat file firfilter(input, output); firfilter(input, output); }}

static int firfilter(int *input, int *output) { /* Define variable arrays, define and clear variables */ long yn = 0; /* y(n), output from FIR filter */ int xnbuf[96]; int xnbuf[96]; int i,j,k; int i,j,k; int size = 300; int size = 300; for(k=0;k<NL;k++) for(k=0;k<NL;k++) { xnbuf[k]=0; xnbuf[k]=0; }

while (size--) { for (i=NL-1;i>0;i--) for (i=NL-1;i>0;i--) {xnbuf[i]=xnbuf[i-1]; }xnbuf[0]=*input++;

/* FIR filtering :y(n) = Sum[x(n-i)*coeff(i)] for i = 0to NL-1 */yn = 0; */ for (j=0; j< NL; j++) for (j=0; j< NL; j++) { yn += (((long)(int)xnbuf[j](long)(int16_T)NUM[j])>>15); yn += (((long)(int)xnbuf[j](long)(int16_T)NUM[j])>>15); } *output++ = (int)(yn); *output++ = (int)(yn); } return(TRUE); return(TRUE);}

static void dataIO() { return; return; }

FIR using DSK #include "bs2700.cof" //coefficient file #include "dsk6713_aic23.h" //codec-dsk support file Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate int yn = 0; //initialize filter's output short dly[N]; //delay samples interrupt void c_int11() //ISR { short i; short i; dly[0]=input_sample(); //input newest sample dly[0]=input_sample(); //input newest sample yn = 0; //initialize filter's output yn = 0; //initialize filter's output

for (i = 0; i< N; i++) yn += (h[i] * dly[i]); //y(n) += h(i)* x(n-i) yn += (h[i] * dly[i]); //y(n) += h(i)* x(n-i) for (i = N-1; i > 0; i--) end of buffer for (i = N-1; i > 0; i--) end of buffer dly[i] = dly[i-1]; //update delays with datamove dly[i] = dly[i-1]; //update delays with datamove output_sample(yn >> 15); //scale output filter sample return; return;} void main() { comm_intr(); //init DSK, codec, McBSP comm_intr(); //init DSK, codec, McBSP while(1); //infinite loop while(1); //infinite loop }

CoefficientsTime nTime n+1Time n+2 h(0)x(n)x(n+1)x(n+2) h(1)x(n-1)x(n)x(n+1) h(2)x(n-2)x(n-1)x(n).. x(n-2)x(n-1)... x(n-2) h(n-3)x(n-(N-3)).. h(n-2)x(n-(N-2))x(n-(N-3)). h(n-1)x(n-(N-1))x(n-(N-2))x(n-(N-3))

FIR using C-callable asm program #include “filter_coeff_bandpass.h" // contain h coeff int yn = 0; interrupt void c_int11() interrupt void c_int11(){ dly[N-1] = input_sample(); yn = fircasmfunc(dly,h,N); output_sample(yn >> 15); return; } void main() { short i;for (i = 0; i<N; i++) dly[i] = 0; comm_intr();while(1); }

 ;FIRCASMfunc.asm ASM function called from C to implement FIR ;  A4 = Samples address, B4 = coeff address, A6 = filter order ;Delays organized as:  x(n-(N-1))...x(n);coeff as h[0]...h[N-1].def _fircasmfunc.def _fircasmfunc _fircasmfunc: ;ASM function called from C MV A6,A1 ;setup loop count MV A6,A1 ;setup loop count MPY A6,2,A6 ;since dly buffer data as byte ZERO A8 ;init A8 for accumulation MPY A6,2,A6 ;since dly buffer data as byte ZERO A8 ;init A8 for accumulation ADD A6,B4,B4 ;since coeff buffer data as byte ADD A6,B4,B4 ;since coeff buffer data as byte

SUB B4,1,B4 ;B4=bottom coeff array h[N-1] loop: ;start of FIR loop LDH *A4++,A2 ; A2=x[n-(N-1)+i] i=0,1,...,N-1 LDH *B4- -,B2 ;B2=h[N-1-i] i=0,1,...,N-1 NOP 4 MPY A2,B2,A6 ;A6=x[n-(N-1)+i]*h[N-1-i] NOP ADD A6,A8,A8 ;accumlate in A8 LDH *A4,A7 ; A7=x[(n-(N-1)+i+1]update delays NOP 4 ;using data move "up" STH A7,*-A4[1] ;->x[(n-(N-1)+i] update sample SUB A1,1,A1 ;decrement loop count

[A1] B loop ;branch to loop if count # 0 NOP 5 MV A8,A4 ;result returned in A4 B B3 ;return addr to calling routine NOP 4

If we take four coeffs h[0] to h[4] then above equation becomes Y[3]=h[0]x[3] +h[1]x[2]+h[2]x[1]+h[3]x[0] Y[4]=h[0]x[4] +h[1]x[3]+h[2]x[2]+h[3]x[1] Y[5]=h[0]x[5] +h[1]x[4]+h[2]x[3]+h[3]x[2]

 Two buffers are created dly for data samples and h for coefficients.  On each interrupt, a new data sample is acquired and stored at the end (higher- memory address) of the buffer dly.  The delay samples are stored in memory starting with the oldest sample  The newest sample is at the end of the buffer

 The coefficients are arranged in memory with h(0) at the beginning of the coefficient buffer and h(N - 1) at the end.  The addresses of the delay sample buffer, the filter coefficient buffer, and the sizeof each buffer are passed to the ASM function through registers A4, B4, and A6, respectively.  The size of each buffer through register A6 is doubled since data in each memory location are stored as bytes.

 the pointers A4 and B4 are incremented or decremented every two bytes (two memory locations)  Y(n)=h(N-1)x(n-(N-1))+h(N-2)x(n-(N-2)) + ………..+h(1)x(n-1)+h(0)x(n).

Thank you