Hello!! I just need help on this question. Here is my code so far but it is not
ID: 3722277 • Letter: H
Question
Hello!! I just need help on this question. Here is my code so far but it is not fully working. Thank you in advance!
void add_echo(int array[], int length, int rate, double d){
int p = rate*d;
int arrayTwo[length];
for (int i = 0; i < length; i++){
arrayTwo[i]=array[i]+array[i-p];
}
for (int i = 0; i < length; i++){
array[i]=arrayTwo[i];
}
Explanation / Answer
Given below is the modified code. You will need #include <math.h> if its C program, or #include <cmath> if its C++. Hope it helps.
void add_echo(int array[], int length, int rate, double d){
double interval = 1.0 / rate; // time interval between samples
int index;
double t1, t2;
//start from the last entry
for (int i = lenght-1; i > 0; i--){
t1 = i * interval;
t2 = t1 - d;
if(t2 > 0){
index = ceil( t2 / interval); //calculate the index for the corresponding time t2
array[i]=array[i]+array[index];
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.