This page is optimized for mobile devices, if you would prefer the desktop version just click here

7.2 Lab  (Page 11/11)

Appendix e: additional routines for psd estimator

pn.c

iirfilt.c

autocorr.c

c_fft_given_iirc.asm

1 /* ECE420, Lab 4, Reference PN Generator Implementation (Non-Optimized) */ 2 /* Matt Kleffner 08/04 */ 3 /* Original by Michael Frutiger 02/24/04 */ 4 /* Use governed by the Creative Commons Attribution License */ 5 6 #include "lab4b.h" 7 8 extern unsigned int *iseed; 9 extern int autocorr_in[N]; 10 11 /* Returns as an integer a random bit, based on the 15 lowest significant 12 bits in iseed (which is modified for the next call). */ 13 int randbit() 14 { 15 int newbit; 16 /* XOR bits 15, 1 and 0 of iseed */ 17 newbit = (*iseed >> 15) & 1 ^ (*iseed >> 1) & 1 ^ *iseed & 1; 18 /* Leftshift the seed and put the result of the XOR's in bit 1. */ 19 *iseed=(*iseed << 1) | newbit; 20 return(newbit); 21 } 22 23 void rand_fillbuffer(void) 24 { 25 int i; 26 27 for (i = 0; i < N; ++i) 28 { 29 if (randbit()) autocorr_in[i] = 32767; 30 else autocorr_in[i] = -32767; 31 } 32 } 1 /* Simple, unoptimized IIR filter (feedback only) */ 2 /* for TMS320C54X series DSPs */ 3 /* Copyright September 2005 by Matt Kleffner */ 4 /* under the Creative Commons Attribution License */ 5 6 #include "lab4b.h" 7 #include "intrinsics.h" 8 9 /* IIR values and buffers (declared in c_fft_given_iirc.asm) */ 10 #define IIR_order 4 11 extern int scale; 12 extern int coef[IIR_order]; 13 extern int state[IIR_order]; 14 15 /* Arrays declared in main routine */ 16 extern int autocorr_in[N]; 17 extern int autocorr_out[N]; 18 19 /* Pointer to state buffer location */ 20 extern int iirptr; 21 22 void iirfilt() 23 { 24 int i, j; 25 26 _set_fract_bit(); 27 /* Filter PN input */ 28 for (i = 0; i < N; ++i) 29 { 30 int sum = 0; 31 /* Calculate and sum all feedback terms except the "oldest" one */ 32 for (j = 0; j < (IIR_order-1); ++j) 33 { 34 sum += _i_mul_fract_fb1_ii(coef[j],state[iirptr]); 35 /* Avoid usage of "modulo" routine */ 36 iirptr++; 37 if (iirptr == IIR_order) iirptr = 0; 38 } 39 /* Calculate and sum oldest feedback term without incrementing iirptr */ 40 sum += _i_mul_fract_fb1_ii(coef[IIR_order-1],state[iirptr]); 41 42 /* Calculate direct input contribution */ 43 sum += _i_mul_fract_fb1_ii(scale,autocorr_in[i]); 44 autocorr_in[i] = sum; 45 state[iirptr] = autocorr_in[i]; 46 } 47 _reset_fract_bit(); 48 } 1 /***********************************************************/ 2 /* autocorr.c */ 3 /* Copyright August 2004 by Matt Kleffner */ 4 /* under the Creative Commons Attribution License */ 5 /* */ 6 /* Simple, unoptimized autocorrelation function */ 7 /* for ECE 420 (TMS320C54X series) */ 8 /* */ 9 /* #defines expected in lab4b.h */ 10 /* L: length of data in autocorr_in buffer */ 11 /* N: length of data in autocorr_out buffer */ 12 /* logL: log base 2 of L (used for scaling output) */ 13 /* M: Largest positive lag of autocorrelation desired */ 14 /* (must be < L and < N/2) */ 15 /* */ 16 /* 16-bit-limited input/output (must be defined elsewhere) */ 17 /* autocorr_in: buffer for input data (L pts) */ 18 /* autocorr_out: buffer for output data (N pts) */ 19 /* N must be >= 2*M+1 */ 20 /* assumed to be full of zeros at start */ 21 /* output in zero-phase form */ 22 /***********************************************************/ 23 24 #include "lab4b.h" 25 #include "intrinsics.h" 26 27 extern int autocorr_in[L]; 28 extern int autocorr_out[N]; 29 30 void autocorr(void) 31 { 32 int i,j,temp; 33 34 _set_fract_bit(); 35 for(i=0;i<=M;++i) 36 { 37 long int sum=0; 38 for(j=0;j<(L-i);++j) 39 { 40 temp = _i_mul_fract_fb1_ii(autocorr_in[j],autocorr_in[j+i]); 41 sum += temp; 42 } 43 autocorr_out[i]=(int)(sum >> logL); 44 } 45 _reset_fract_bit(); 46 47 /* Copy values for negative indeces at end of buffer */ 48 for(i=1,j=N-1;i<=M;++i,--j) 49 { autocorr_out[j]=autocorr_out[i]; } 50 }
<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, Digital signal processing laboratory (ece 420). OpenStax CNX. Sep 27, 2006 Download for free at http://cnx.org/content/col10236/1.14
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.