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 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 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 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...
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...
Write a function such that given a number N, display the N*N multiplication matrix from 1...
Write a function such that given a number N, display the N*N multiplication matrix from 1 to N. Then, write a C++ program such that, it prints the multiplication matrices of numbers 1,4,7, and 10 using a loop concept. Check the sample output below, to see how the program should work. Make sure to have your output exactly the same as the below output.
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?
Write a new MATLAB function as described in the following: 1. The new function will have...
Write a new MATLAB function as described in the following: 1. The new function will have three input parameters: f, W, C. 2. Parameter f will specify the frequency of the square wave. 3. The parameter W will specify the width of the single pulse as a number of sample periods. 4. The parameter C will specify the number of square wave cycles. 5. Calculate a number of samples, N, to run the simulation for both waveforms. 6. Create one...
Write a recursive function in C++ named multiplyNumbers, which takes one int argument n as input...
Write a recursive function in C++ named multiplyNumbers, which takes one int argument n as input and returns the product of numbers from 1 to n.
Sketch the wave-function of the ground state of a particle of mass m which is con-...
Sketch the wave-function of the ground state of a particle of mass m which is con- fined in one dimension within a square potential well of infinite height, centred at x = 0 and of width a between x = ?a/2 and x = a/2. What type of function is that? If the infinite potential well is replaced by a potential well of finite height, sketch the new ground state wave-function. Explain qualitatively how the ground state energy changes in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT