f(t)={t+3: t ∈[0,T].
0: otherwise}
Read in an integer value for T. Sample the function f(t) above, at t = 0, 1, 2 . . . T and write the values to a file ‘function.txt’.
Read the values from the file, and place them in an array.
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 between 0 and T. (hint: the convolution will only be nonzero between 0 and 2T- make sure you understand why.)
Call your function with both functions f and g given by the same array from part 1. The formula for finding the convolution is
(f*g)[n] ∑ (f[m] g[n-m])
This is what I have so far. need help finishing it.
#include <stdlib.h>
#include <stdio.h>
void convolution (int F[ ] ,int G [ ])
{
FILE *fptr;
int i,j,T;
int x;
F[T],G[T];
x= T+1;
fptr = fopen("function.txt","r");
if (fptr == NULL)
{
printf("No such file!");
exit(0);
}
for (i=0; i<=x; i++)
{
F[i]= i+3;
fscanf(fptr,"%d",&j);
printf("F[%d] = %d\n",i,F[i]);
}
printf("\n");
fclose(fptr);
int sum;
for (c=0; c<2T+1; c++)
{
sum =0; g=c;
for(f=0; f<c; f++,g--)
{
if (f<=T && g<=T)
{
sum = sum + F [ ]* G [ ];
}
printf("convolution [%d] = %d",c, sum);
}
}
}
int main (void)
{
int x;
int T,F[x],G[x];
x= T+1;
printf("Enter the value of T: ");
scanf("%d",&T);
convolution(F,G);
return 0;
}