Thread: Convolution in c

  1. #16
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    well, my professor said that we are not supposed to ask for any inputs to store in the array, everything starts at 0 and goes up from there. I have some code but it gives me 0 all the time as the value for the convolution
    Code:
    #include<stdio.h>
    
    
    void mult( int f[], int g[], int n){ //function to multiply  first array by 4
    
            int i;
            for (i =0; i < n; i++){
                    g[i] = 4 * f[i];    //multiply f[i] by 4 so the series is sampled every four
    
            }
    }
    
    
    void convo(int f[], int g[], int  h[], int n){  /*function to convolve the 2 arrays*/
    
            int i, j;
    
            for(i = 0; i < n; i++){
                h[i] = 0;
                for(j = 0; j < n; j++){
                     if (g[j]-f[i]>0){
                           h[i] += g[j] * f[j-i];  /*convolve the two arrays*/
                                  }
    
                              }
                            printf("index: %d\t convolution %d\n", i, h[i]);  //display the index number starting from 0 and its convolution value
    
                    }
    }
    
    
    
    int main()
    {
            int n = 0;
    
            printf("enter the number of elements in the array: ");
            scanf("%d", &n);
            int f[1000];
            int g[100];
    
            int h[n];
    
            mult(f, g, n);          //call mult function
            convo(f, g, h, n);      //call convo function
    
            return 0;
    
    }

  2. #17
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Garbage * 4 still equal Garbage.

    Bye, You are not learning anything from me; So, I give up on trying to help you.

    Tim S.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Convolution in C
    By rrr in forum C Programming
    Replies: 2
    Last Post: 01-19-2011, 05:34 PM
  2. FFT and convolution
    By DavidP in forum General Discussions
    Replies: 7
    Last Post: 07-03-2009, 09:31 AM
  3. Caught In The Convolution Matrix
    By SMurf in forum Game Programming
    Replies: 3
    Last Post: 11-25-2007, 10:24 PM