Question

In: Computer Science

Write a function ‘filter_wave(wave,n)’ and this will produce a new wave which is a smoothed version...

Write a function ‘filter_wave(wave,n)’ and this will produce a new wave which is a smoothed version of the input ‘wave’ adhering to the following rules. The input parameter n will be explained later in part 2. • In the new wave, for every position i, it is the weighted sum of three positions of the original wave. More preciously, the new wave value in position i will be equal to new_wave[i] = wave[i-1] * 0.2 + wave[i]*0.6 + wave[i+1]*0.2 • Let len(wave) be L. The above calculation requires access to wave[-1] and wave[L] which do NOT exist in the original wave. You may assume that both wave[-1] and wave[L] are 0. • You should NOT modify the original wave input • And all the number in the new wave will be integers. You can simple use the function int() to convert any number into an integer. • Your function should return the new wave as a list.

Finally, modify the function ‘filter_wave(wave,n)’ for n ≥ 0. And this will repeat the filtering n times to the wave accumulatively and produce an even smoother wave. You still need to adhere to the rules mentioned in Part 1. Here is the expected wave for filter_wave(original_wave_sample,10)

Solutions

Expert Solution

I used Python for this problem. The following is the code-->

def filer_wave(wave,n):    //fiter_wave function declaration which takes two parameters wave and n
i=1
L=len(wave)
// variable L contains the length of the wave list
new_wave=wave    // here we are declaring a list new_wave, and initializing it with wave list.

while(i<=n): //We are looping n times to modify new_wave n times so that the wave is filtered n times.    //This was explained in the second part of the question.
j=0
while(j<L):
//Now we are looping L times to modify each index of the wave list and store the filtered value //in new_wave
if j==0 and L>1:    // This condition checks for first element of wave list and if the length of wave list greater than1
s=(int)(new_wave[j]*0.6+new_wave[j+1]*0.2)
elif j==0 and L==1: //This condition checks for first element of wave list and if the length of wave list equal to one
s=(int)(new_wave[j]*0.6)
elif j==L-1: //This condition checks for last element of wave list
s=(int)(new_wave[j-1]*0.2+new_wave[j]*0.6)
else: // This condition works for element in between first and last element of wave list
s=(int)(new_wave[j-1]*0.2+new_wave[j]*0.6+new_wave[j+1]*0.2) // We are using the required expression from // equation. And converting it to Integer

new_wave[j]=s   //We have computed values for each condition in s. Here we are storing s in correct position of // new_wave list
j+=1 //Iterating inner loop
i+=1 //Iterating outer loop
return new_wave //Returning new_wave list as required


Related Solutions

Write a C++ program that has a function which given n>=0, create an array length n*n...
Write a C++ program that has a function which given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups) generateGroups(3) → [0, 0, 1, 0, 2, 1, 3, 2, 1] generateGroups(2) → [0, 1, 2, 1] generateGroups(4) → [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
Write a version of the selection sort algorithm in a function called selectionSort that can be...
Write a version of the selection sort algorithm in a function called selectionSort that can be used to sort a string vector object. Also, write a program to test your algorithm. The program should prompt the user for a series of names. The string zzz should end the input stream. Output the sorted list to the console. *Need answer in C++*
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie...
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie Germain prime that is greater or equal to n.
Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
a) Write a function drawShape() that accepts a parameter n, and: If n is odd, it...
a) Write a function drawShape() that accepts a parameter n, and: If n is odd, it constructs a pattern of a diamond of height n If n is even, it constructs an hourglass of length n b) What is the time complexity of the drawShape() function you created? C++ language with for loop
Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
Write a recursive function to implement the Factorial of n (n!). In the main, let the...
Write a recursive function to implement the Factorial of n (n!). In the main, let the user input a positive integer and call your function to return the result.
Write C code that contains a function called triangle_generator that outputs a triangle wave at a...
Write C code that contains a function called triangle_generator that outputs a triangle wave at a specified frequency (in hertz) using a specified sample rate (in hertz), and for a specified time duration (in seconds). These parameters are float type. The output you generate are floating point numbers between -1 and 1, one number per output line. The math trig functions in C use radians while all the specifications here are in hertz (cycles per second). One hertz is 2*Pi...
Question 2 (Function Template) Write a template version of the iterative binary search algorithm that searches...
Question 2 (Function Template) Write a template version of the iterative binary search algorithm that searches an array of arbitrary type for a given key. Declare and implement a class called Student that keeps the student id, name, and grade. Include a default constructor, the overloaded insertion (<<) operator and also the overloaded extraction operator (>>). Declare and implement another class called Book that keeps the book’s title, author, and price. Just like the Student class, Include in class Book...
How the wave function and wave packets can be used to explain the particle-wave properties of...
How the wave function and wave packets can be used to explain the particle-wave properties of electrons?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT