Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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> 1) + (right_input[i] >> 1);

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> 1) + (right_input[i] >> 1);

copyArray(left_output, right_output, size); }

7. Implement a real-time FIR filter using Q15 arithmetic and block processing a. Write a function called FIRQ15 that computes the output of an FIR filter using Q15 (fixed point) arithmetic where the input x is assumed to be a block (or short segment) of the input signal. Use a circular buffer to store values from previous function calls. Put your function in the file myAlgorithm.c and put the function prototype in myAlgorithm.h. Use the following function definition: 7FIRQ15 Compute output of an FIR filter using Q15 // (fixed point) arithmetic and block processing //x-pointer to input buffer y- pointer to output buffer //h- pointer to filter coefficient array void FIRQ15 (Int16 *x, Int16 *y, // xSize - size of input and output buffers // hSize - size of filter coefficient array Int16 xSize, Int16 *h, Int16 hSize) b. Since the compiler doesn't initialize global variables to zero, also write a function FIRQ15Init that initializes the circular buffer and the index into the circular buffer. Write a function called FIRQ15Test to test your function FIRQ15. This function should define (small) arrays for the input x, output y, and coefficients h, all of which are Q15 numbers (type Int16). It should then initialize the circular buffer and index. Next it should repeatedly call FIRQ15 to compute the output of the filter for small sections of the input data, and print out the output values. Call your FIRQ15Test function from the function myAlgorithmInit. c. d. Test your FIRQ15 function with sample input and coefficient values and compare to the expected output values computed by MATLAB Use the MATLAB command fdatool to design an FIR filter to remove the jet noise from the recording birds jet noise.wav. Use fs- 48000 Hz since that is the default sampling rate in the Real-time DSP Demo project. Export the coefficients into the MATLAB workspace. Print the coefficients to the Command Window, convert them to Q15 integers, and copy/paste them into your source code. In the e. comments, document the parameters of the filter (type of filter, sampling rate, cutoff frequency, order, and other parameters from fdatool). f. Modify the function myAlgorithm so that it converts the input signal to mono, filters the signal using your FIRQ15 function with the filter coefficients that you computed in part e, and copies the output of the signal to both the left and right chauncels. g. Test your function by playing the file birds_jet noise.wav through the TMS320C5515 eZdsp USB Stick and listening to the output. You can best hear the effect of your filter if you switch back and forth between the pass-through algorithm and your algorithm. Also, listen to how your filter affects music and other signals. 7. Implement a real-time FIR filter using Q15 arithmetic and block processing a. Write a function called FIRQ15 that computes the output of an FIR filter using Q15 (fixed point) arithmetic where the input x is assumed to be a block (or short segment) of the input signal. Use a circular buffer to store values from previous function calls. Put your function in the file myAlgorithm.c and put the function prototype in myAlgorithm.h. Use the following function definition: 7FIRQ15 Compute output of an FIR filter using Q15 // (fixed point) arithmetic and block processing //x-pointer to input buffer y- pointer to output buffer //h- pointer to filter coefficient array void FIRQ15 (Int16 *x, Int16 *y, // xSize - size of input and output buffers // hSize - size of filter coefficient array Int16 xSize, Int16 *h, Int16 hSize) b. Since the compiler doesn't initialize global variables to zero, also write a function FIRQ15Init that initializes the circular buffer and the index into the circular buffer. Write a function called FIRQ15Test to test your function FIRQ15. This function should define (small) arrays for the input x, output y, and coefficients h, all of which are Q15 numbers (type Int16). It should then initialize the circular buffer and index. Next it should repeatedly call FIRQ15 to compute the output of the filter for small sections of the input data, and print out the output values. Call your FIRQ15Test function from the function myAlgorithmInit. c. d. Test your FIRQ15 function with sample input and coefficient values and compare to the expected output values computed by MATLAB Use the MATLAB command fdatool to design an FIR filter to remove the jet noise from the recording birds jet noise.wav. Use fs- 48000 Hz since that is the default sampling rate in the Real-time DSP Demo project. Export the coefficients into the MATLAB workspace. Print the coefficients to the Command Window, convert them to Q15 integers, and copy/paste them into your source code. In the e. comments, document the parameters of the filter (type of filter, sampling rate, cutoff frequency, order, and other parameters from fdatool). f. Modify the function myAlgorithm so that it converts the input signal to mono, filters the signal using your FIRQ15 function with the filter coefficients that you computed in part e, and copies the output of the signal to both the left and right chauncels. g. Test your function by playing the file birds_jet noise.wav through the TMS320C5515 eZdsp USB Stick and listening to the output. You can best hear the effect of your filter if you switch back and forth between the pass-through algorithm and your algorithm. Also, listen to how your filter affects music and other signals<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

a. Does your organization have a compliance and ethics office?

Answered: 1 week ago

Question

What is the relation of physical mathematics with examples?

Answered: 1 week ago

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago