ENCM 515 W11 Midterm 1 Submitted Questions Midterm Sample Questions Question 1 (Part 1) – 5 Marks: You are given the following code: input[4] = {1, 2, 3, 5}; output = 0; N = 4; a0 a1 a2 a3 = = = = 1; 2; 3; 5; for (i = 0; i < 4; i++) { output = filter(input[i]); //Point 2 } double filter(newvalue){ static float FIFO[N] = {0}; for (int i = 0; i < N-1; i++){ FIFO[i] = FIFO[i+1]; } FIFO[N-1] = newvalue; //Point 1 return a0 * FIFO[0] + a1 * FIFO[1] + a2 * FIFO[2] + a3 * FIFO[3]; } For the above code, show the contents of FIFO at Point 1 and output at Point 2 for each of the four iterations through the for loop. i=0 FIFO: {____ , ____ , ____ , ____} output: __________ i=1 FIFO: {____ , ____ , ____ , ____} output: __________ i=2 FIFO: {____ , ____ , ____ , ____} output: __________ i=3 FIFO: {____ , ____ , ____ , ____} output: __________ 1|Page ENCM 515 W11 Midterm 1 Submitted Questions Question 1 (Part 2) – 3 Marks: Assume you are working with a moving average (low-pass) filter like the one you designed in lab 1. Draw a rough sketch of the frequency response of the filter for N = 4 versus N = 16. Elaborate on the differences between the two sketches. N=4 N = 16 __________________________________________________________________________________________ __________________________________________________________________________________________ __________________________________________________________________________________________ __________________________________________________________________________________________ __________________________________________________________________________________________ Question 2 – 12 Marks: There are several ways to design a high-pass FIR filter. Modify the following low-pass filter code to produce a high-pass filter in C++ and assembly. If you'd like, you may use pseudo-code for your C++ implementation (not your assembly). Assume all variables used have already been properly allocated. Some helpful skeleton code for your assembly implementation has been included. // C++ Low Pass Filter float sum = 0; for (int i = 0; i < N; i++) sum = sum + FIFO_Left[i]; float average = sum / N; Left_Channel_Out1 = average; // C++ High Pass Filter 2|Page ENCM 515 W11 // Assembly #define #define #define #define #define #define Midterm 1 Submitted Questions sum_F5 F5 temp_F6 F6 count_R1 R1 FIFO_Length_R2 R2 FIFO_I4 I4 addressIndex_M4 M4 count_R1 = 0; addressIndex_M4 = 0; // Set up even iterations LOOP1: CMP(count_R1, FIFO_Length_R2) IF GE JUMP LOOP1_END (DB); nop; nop; JUMP LOOP1; LOO1_END: LOOP2: JUMP LOOP2; LOO2_END: 3|Page