This page is optimized for mobile devices, if you would prefer the desktop version just
click here
Appendix e: additional routines for psd estimator
/* ECE420, Lab 4, Reference PN Generator Implementation (Non-Optimized) */
/* Matt Kleffner 08/04 */
/* Original by Michael Frutiger 02/24/04 */
/* Use governed by the Creative Commons Attribution License */
#include "lab4b.h"
extern unsigned int *iseed;
extern int autocorr_in[N];
/* Returns as an integer a random bit, based on the 15 lowest significant
bits in iseed (which is modified for the next call). */
int randbit()
{
int newbit;
/* XOR bits 15, 1 and 0 of iseed */
newbit = (*iseed >> 15) & 1 ^ (*iseed >> 1) & 1 ^ *iseed & 1;
/* Leftshift the seed and put the result of the XOR's in bit 1. */
*iseed=(*iseed << 1) | newbit;
return(newbit);
}
void rand_fillbuffer(void)
{
int i;
for (i = 0; i < N; ++i)
{
if (randbit()) autocorr_in[i] = 32767;
else autocorr_in[i] = -32767;
}
}
/* Simple, unoptimized IIR filter (feedback only) */
/* for TMS320C54X series DSPs */
/* Copyright September 2005 by Matt Kleffner */
/* under the Creative Commons Attribution License */
/* Works for TMS320C55X series as well */
#include "lab4b.h"
#include "intrinsics.h"
/* IIR values and buffers (declared in c_fft_given_iirc.asm) */
#define IIR_order 4
extern int scale;
extern int coef[IIR_order];
extern int state[IIR_order];
/* Arrays declared in main routine */
extern int autocorr_in[N];
extern int autocorr_out[N];
/* Pointer to state buffer location */
extern int iirptr;
void iirfilt()
{
int i, j;
_set_fract_bit();
/* Filter PN input */
for (i = 0; i < N; ++i)
{
int sum = 0;
/* Calculate and sum all feedback terms except the "oldest" one */
for (j = 0; j < (IIR_order-1); ++j)
{
sum += _i_mul_fract_fb1_ii(coef[j],state[iirptr]);
/* Avoid usage of "modulo" routine */
iirptr++;
if (iirptr == IIR_order) iirptr = 0;
}
/* Calculate and sum oldest feedback term without incrementing iirptr */
sum += _i_mul_fract_fb1_ii(coef[IIR_order-1],state[iirptr]);
/* Calculate direct input contribution */
sum += _i_mul_fract_fb1_ii(scale,autocorr_in[i]);
autocorr_in[i] = sum;
state[iirptr] = autocorr_in[i];
}
_reset_fract_bit();
}
/***********************************************************/
/* autocorr.c */
/* Copyright August 2004 by Matt Kleffner */
/* under the Creative Commons Attribution License */
/* */
/* Simple, unoptimized autocorrelation function */
/* for ECE 420 (TMS320C54X series) */
/* */
/* #defines expected in lab4b.h */
/* L: length of data in autocorr_in buffer */
/* N: length of data in autocorr_out buffer */
/* logL: log base 2 of L (used for scaling output) */
/* M: Largest positive lag of autocorrelation desired */
/* (must be < L and < N/2) */
/* */
/* 16-bit-limited input/output (must be defined elsewhere) */
/* autocorr_in: buffer for input data (L pts) */
/* autocorr_out: buffer for output data (N pts) */
/* N must be >= 2*M+1 */
/* assumed to be full of zeros at start */
/* output in zero-phase form */
/***********************************************************/
/* Works for TMS320C55X series */
#include "lab4b.h"
#include "intrinsics.h"
extern int autocorr_in[L];
extern int autocorr_out[N];
void autocorr(void)
{
int i,j,temp;
_set_fract_bit();
for(i=0;i<=M;++i)
{
long int sum=0;
for(j=0;j<(L-i);++j)
{
temp = _i_mul_fract_fb1_ii(autocorr_in[j],autocorr_in[j+i]);
sum += temp;
}
autocorr_out[i]=(int)(sum >> logL);
}
_reset_fract_bit();
/* Copy values for negative indeces at end of buffer */
for(i=1,j=N-1;i<=M;++i,--j)
{ autocorr_out[j]=autocorr_out[i]; }
}
; c_fft_given_iirc.asm
; Designed for use in lab4b for ECE420
.ARMS_off ;enable assembler for ARMS=0
.CPL_on ;enable assembler for CPL=1
.mmregs ;enable mem mapped register names
.global _bit_rev_data
.global _fft_data
.global _state
.global _scale
.global _coef
.copy "macro.asm"
.sect ".data"
N .set 1024
.align 4*N
_bit_rev_data .space 16*2*N
.align 4*N
_fft_data .space 16*2*N
; IIR filter
.align 4
_coef
.word 0
.word 0
.word 0
.word -13421
_state
.space 16*4
_scale
.word 19345
.sect ".text"
Read also:
OpenStax, Digital signal processing laboratory (ece 420 55x). OpenStax CNX. Jan 18, 2010 Download for free at http://cnx.org/content/col10397/1.10
Google Play and the Google Play logo are trademarks of Google Inc.