1 Overview In this homework, you will implement a convolution method using the f
ID: 3881301 • Letter: 1
Question
1 Overview In this homework, you will implement a convolution method using the following formula. M-1 where f is an array of size N, g is an array of size M, and f*g is the array of size N - M + 1 that stores the result of the convolution, For example if N = 18 and M = 3, then the size of f * g is 18-3+ 1 = 16. You will also implement a correlation method using the following formula M-1 m-0 where f is an array of size N. q is an arrav of size M, and f * a is the array of size N - M + 1 that stores the result of the correlation, Note that array index starts from 0 so that the index of f ranges from 0 to N - 1, the index of g ranges from 0 to M - 1, and the index of f * g and fg ranges from 0 to N -M Lastly, we assume that N 2 M. 2 Requirements 1. You must define the following method for convolution f*g and correlation private static double[] convolution (doublel] f, double [] g) private static double[] correlation (double[] f, double [] g) You should not print the results using the two methods. Instead, you should return the result of convolution and correlation to the main method for printingExplanation / Answer
Answer-)
private static double[] convolution(double[] f,double[] g){ \function for calculating convolution
int N=f.length,M=g.length,m=0,n=0;\N size of f ,M size of g,m and n are iterative variable
double[] result=new double[N]; esulting array since result contain N element only
for(n=0;n<N;n++){ esult for each element
for(m=0;m<M;m++){ \summation of convolution formula
result[n]+=f[n+(M-1)-m]*g[m];\formula for calculating convolution
}
}
return result; //returning result
}
private static double[] correlation(double[] f,double[] g){\function for calculating correlation
int N=f.length,M=f.length,m=0,n=0;\N size of f ,M size of g,m and n are iterative variable
double[] result=new double[N]; esulting array since result contain N element only
for(n=0;n<N;n++){ esult[n] for each element
for(m=0;m<M;m++){ \summation of corelation formula
result[n]+=f[n+m]*g[m];\formula for calculating correlation
}
}
return result;//returning result
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.