Question
Need the correct code rewritten in accordance with the instructions given and more than just crtl+F and replace please. The first is the assignment and
Need the correct code rewritten in accordance with the instructions given and more than just crtl+F and replace please. The first is the assignment and the second part is the correct code.
Correct Code:
#include "data_types.h" // This header file defines the type Int16, which is used in myAlgorithm.h #include "myAlgorithm.h"
#include
// HPF designed by fdtool: HPF Window Hamming, Order 60, fc = 1800 Hz, fs = 48 kHz #define HFIRSIZE 61 Int16 HFIR[HFIRSIZE] = {-20, -16, -10, -3, 8, 23, 43, 68, 98, 130, 162, 189, 206, 207, 189, 144, 69, -40, -183, -360, -568, -801, -1052, -1311, -1567, -1810, -2027, -2209, -2345, -2430, 30330, -2430, -2345, -2209, -2027, -1810, -1567, -1311, -1052, -801, -568, -360, -183, -40, 69, 144, 189, 207, 206, 189, 162, 130, 98, 68, 43, 23, 8, -3, -10, -16, -20};
/* // HPF designed by fdtool: HPF Window Hamming, Order 30, fc = 1800 Hz, fs = 48 kHz #define HFIRSIZE 31 Int16 HFIR[HFIRSIZE] = {21, 11, -8, -45, -115, -229, -393, -610, -874, -1172, -1485, -1790, -2061, -2275, -2412, 30335, -2412, -2275, -2061, -1790, -1485, -1172, -874, -610, -393, -229, -115, -45, -8, 11, 21}; */
/* // define FIR filter (this is the fixed point version of the example filter used in the last Hw) #define HFIRSIZE 3 Int16 HFIR[HFIRSIZE] = {0.1938*32768, 0.2031*32768, 0.2062*32768}; */
Int16 IndexFIR = 0; // index into DelayBufferFIR that points to oldest data Int16 DelayBufferFIR[HFIRSIZE] = {0}; // delay buffer (HFIRSIZE is defined in myAlgorithm.h)
// FIRQ15 // Compute output of an FIR filter using // Q15 (fixed point) arithmetic and block processing. // This version uses a circular buffer. // x - pointer to input buffer // y - pointer to output buffer // xSize - size of input and output buffers // h - pointer to filter coefficient array // hSize - size of filter coefficient array void FIRQ15(Int16 *x, Int16 *y, Int16 xSize, Int16 *h, Int16 hSize) { Int16 n,i,k; Int32 sum; // 32 bit accumulator
for (n = 0; n hSize - 1) // increment IndexQ15 with wrap around [0,hSize-1] IndexFIR = 0; sum = 0; // initialize sum to zero for (i=0; i > 15; // shift back to 16 bit values } }
// Test FIRQ15 function #define BLOCKSIZE 4 // size of input and output buffers (block size) #define XFIRSIZE 12 Int16 XFIR[XFIRSIZE] = {-0.4*32768, 0.9999*32768, 0.2*32768, 0.1*32768, -0.2*32768, -0.1*32768, 0.4*32768, 0.5*32768, 0.7*32768, 0.6*32768, -0.3*32768, 0.3*32768}; void FIRQ15Test(void) { Int16 y[BLOCKSIZE] = {0}; Int16 *p; // pointer into array x
Int16 i,j;
// clear DelayBufferQ15 (It appears that the compiler doesn't do that automatically!) FIRQ15Init();
printf("FIRQ15Test: "); for (j=0; j p = XFIR; // Initially call FIRQ15 with first 4 input values for (j=0; j // FIRQ15Init - Initialize DelayBufferQ15 and IndexQ15 which used by FIRQ15 void FIRQ15Init(void) { Int16 i; IndexFIR = 0; for (i=0; i } // myAlgorithmInit: Use this function to initialize your DSP algorithm // This function is called once after power-up or reset // Inputs: // none // // Outputs: // none // void myAlgorithmInit(void) { // > FIRQ15Test(); FIRQ15Init(); } // myAlgorithm: Use this function to implement your DSP algorithm // This function is called each time the ping-pong buffers are full. // Inputs: // left_input (left audio input data pointer) // right_input (right audio input data pointer) // buff_size (number of samples in the input and output data vectors) // // Outputs: // left_output (left audio output data pointer) // right_output (right audio output data pointer) // void myAlgorithm(Int16 *left_input, Int16 *left_output, Int16 *right_input, Int16 *right_output, Uint16 buff_size) { // add your code here Int16 i; // convert to mono for (i=0; i FIRQ15(left_output,right_output,buff_size,HFIR,HFIRSIZE); // FIR filter using Q15 format // copy output to back to left channel copyArray(right_output,left_output,buff_size); } // Copy input array to output array // input - pointer to input array // output - pointer to output array // size - size of arrays void copyArray(Int16 *input, Int16 *output, Uint16 size) { Uint16 i; for (i=0; i // copyArrayTest - test the function copyArray #define N 10 // number of elements in input and output arrays in copyArrayTest void copyArrayTest(void) { Uint16 i; Uint16 correct = 0; Int16 x[N] = {0,1,2,3,4,5,6,7,8,9}; Int16 y[N] = {0}; copyArray(x,y,N); // count number of elements that were correctly copied for (i=0; i if (correct == N) printf("copyArrayTest: Passed "); else printf("copyArrayTest: Failed "); } // stereoPassthrough - stereo pass-through // copy left input to left output and copy right input to right output void stereoPassthrough(Int16 *left_input, Int16 *left_output, Int16 *right_input, Int16 *right_output, Uint16 size) { copyArray(left_input, left_output, size); copyArray(right_input, right_output, size); } // monoPassthrough - mono pass-through // divide left and right input by 2, add them, and copy the result to left and right output void monoPassthrough(Int16 *left_input, Int16 *left_output, Int16 *right_input, Int16 *right_output, Uint16 size) { Uint16 i; for (i=0; i copyArray(left_output, right_output, size); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started