Question
C++ For this next part, you will be writing a low pass filter using a very basic hanning window. The idea behind a low pass
C++ For this next part, you will be writing a low pass filter using a very basic hanning window. The idea behind a low pass filter is to get rid of high frequencies, or, in essence, smoothing out the massive outliers in an array. The way to do this is to take a window size, usually an odd number in length, in which you take the average of the values before and after a value in an array and replace that value with the average. So, for instance, if you had an array as follows: 3,8,2,5,1,4,6,0,2 And you had a window size of 3, you would go through the array in window sizes of 3 and replace each center value with the average. For those values at the beginning and the end, in which you cant have a window on both sides, youd replace the values with a 0. Otherwise each value gets replaced with its window average. The resulting array would be: 0 4 5 2 3 3 3 2 0 Which is a much smoother array with fewer outliers. Now, an even better way of smoothing out the outliers is to weight the window. So, in the process of averaging, the values farthest from the center value in the window are weighted the lowest, whereas the values closest to the center of the window are weighted the highest. This is known as a Hanning window. For instance, if you have a window size of 5, you might weight the values by multiplying the values at location 1 and 5 with 1, the values at location 2 and 4 with 2 and the values at location 3 (the center) with 3, and then dividing the sum by 9 to get the weighted average. So in this case, given the following array and a window size of 5, 3,8,2,5,1,4,6,0,2 Using a hanning window for a filter, youd get: 0, 0, 4, 3, 3, 3, 3, 0, 0, (Note that this is even smoother than the really simple filter we used above). #1 Write a function for the hanning window. For this function, you should take as input parameters a part of the array (remember whenever you pass in an array, no matter what you pass in, it is always interpreted as the address of the first value of the array. So if I passed in &arr[3], when that address enters the function, it will assume that the 4th address is the first address in the array. So DO NOT make a copy of each window and send that into the function that is just wasteful and makes no sense). Assume the window size is an odd number in size, Weight the values appropriately. Return the weighted and averaged value. Do not let the user input any values, everything should be written as a function.
Write a function for filtering the array. This function should return a new array. You cant write over the old array (why not?). You will have to create a new array on the heap, and return that new array. This function should take as input parameters the original array and the size of the original array, and should create a new array that has been filtered using the hanning window function.
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