Question
I Need a C code that can do this i already i have a code below, it's just missing a few things. Please tell me
I Need a C code that can do this i already i have a code below, it's just missing a few things. Please tell me if it follows the procedures correctly.
code//
#include #include void convolution(int f[], int g[], int n) { int i, j, h[n];
FILE *fptr; fptr = fopen("convolution.txt","w");
if(fptr == NULL) { printf("Error!"); exit(1); }
for(i = 0; i 0) { h[i] += f[i]*(g[j]-f[i]); printf("index: %d\t convolution: %d ", i, h[i]); fprintf(fptr,"index: %d\t convolution: %d ",i,h[i]); } } } fclose(fptr); } int main() { int T,t;
printf("Enter the value of T: "); scanf("%d",&T);
FILE *fptr; fptr = fopen("function.txt","w");
if(fptr == NULL) { printf("Error!"); exit(1); }
for(t=0;t
fclose(fptr);
fptr = fopen("function.txt","r");
if(fptr == NULL) { printf("Error!"); exit(1); } int a[T+1];
for(t=0;t
fclose(fptr);
convolution(a, a, T+1);
return 0; }
The convolution operation is frequently used in many areas of engineering and physics. It can be used to determine the response of a linear system to a general excitation; je: the driving force in an inhomogeneous linear differential equation. It is a basic tool of signal processing in electrical engineerns- The convolution integral of two functions f(t) and g(t) is given by: An equivalent operation can be defined for discrete (as opposed to continuous) functions: If either function is only non-zero over a limited domain, then the integral sum is effectively limited to values of t or m where the product of the functions in non-zero A continuous function ft) can be sampled at regular time intervals to generate a corresponding discrete function. In this assignment you will be asked to sample a continuous function at regular intervals and conwolve the function with itself Consider the function: f(t) 0: otherwise Carry out the following steps: 1. Read in an integer value for T. Sample the functionf above, att 0,1,2... T and write the values to a file 'function.trt 2. Read the values firom the file, and place them in an array. 3. Write a function called "convolution" which takes two arrays as arguments, calculates their discrete convolution and prints out the resulting function in two columns: index and convolution. Print the output both to the screen and to a file called 'convolution.txt' Your function should only do the calculation for indices corresponding to non-zero values of the convolution. Assume both functions are only nonzero betiween 0 and T (hint the covolution will only be nonzsro betwsen 0 and 2T- make sure you undsrstand 4. Call your function with both functions f and g given by the same array from part 1. The convolution operation is frequently used in many areas of engineering and physics. It can be used to determine the response of a linear system to a general excitation; je: the driving force in an inhomogeneous linear differential equation. It is a basic tool of signal processing in electrical engineerns- The convolution integral of two functions f(t) and g(t) is given by: An equivalent operation can be defined for discrete (as opposed to continuous) functions: If either function is only non-zero over a limited domain, then the integral sum is effectively limited to values of t or m where the product of the functions in non-zero A continuous function ft) can be sampled at regular time intervals to generate a corresponding discrete function. In this assignment you will be asked to sample a continuous function at regular intervals and conwolve the function with itself Consider the function: f(t) 0: otherwise Carry out the following steps: 1. Read in an integer value for T. Sample the functionf above, att 0,1,2... T and write the values to a file 'function.trt 2. Read the values firom the file, and place them in an array. 3. Write a function called "convolution" which takes two arrays as arguments, calculates their discrete convolution and prints out the resulting function in two columns: index and convolution. Print the output both to the screen and to a file called 'convolution.txt' Your function should only do the calculation for indices corresponding to non-zero values of the convolution. Assume both functions are only nonzero betiween 0 and T (hint the covolution will only be nonzsro betwsen 0 and 2T- make sure you undsrstand 4. Call your function with both functions f and g given by the same array fromStep 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