⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convolution_in_c.c

📁 Convolution program in C
💻 C
字号:
# include<stdio.h>
# include<conio.h>

int main()
{
    int n,k,x1t1,x1t2,x2t1,x2t2,t,t1,t2,n1,x1[100],x2[100],x11[100],y[100];
    int i,j,temp;
    
    // The parameters of first signal is taken here 
    printf("Enter the starting range for input x1(n) : ");
    scanf("%d",&x1t1);
    printf("Enter the ending range : ");
    scanf("%d",&x1t2);
    n = abs(x1t2 - x1t1) + 1;
    printf("Enter the variables of the sequence : \n");
    for(i=0;i<n;i++)
    {
            printf("Enter the sample value at instant %d : ",x1t1+i);
            scanf("%d",&x1[i]);
            }
        
    // The parameters of the second signal is taken here 
    printf("\nEnter the starting range for input x2(n) : ");
    scanf("%d",&x2t2);
    printf("Enter the ending range : ");
    scanf("%d",&x2t1);
    k = abs(x2t1 - x2t2) +1;
    x2t2 = 0-x2t2;
    x2t1 = 0-x2t1;
    printf("Enter the variables of the sequence : \n");
    for(i=k-1,j=0;i>=0;j++,i--)
    {
            printf("Enter the sample value at instant %d : ",j-x2t2);
            scanf("%d",&x2[i]);
            }
    
    // Finding the Output Periods & Total sample length
    t1 = x1t1 - x2t2;
    t2 = x1t2 - x2t1;
    t = abs(t2-t1)+1;
    
    // Finding the number of zeroes padded at both ends
    n1 = t-n;
    
    // Zeroes are padded at the end of first signal    
    for(i=0;i<n1;i++)
    x11[i] = 0;
    for(i=n1;i<n+n1;i++)
    x11[i] = x1[i-n1];
    for(i=n+n1;i<n+(2*n1);i++)
    x11[i] = 0;

    // Initializing the output register to zero   
    for(i=0;i<t;i++)
          y[i] = 0;
    
    // Convolution Operation
    for(i=0;i<t;i++)
    {
               temp = 0;     
               for(j=0;j<k;j++)
               {
                         temp = x11[i+j]*x2[j];      
                         y[i] = y[i] + temp;
                         }
               }
               
    // Printing the result to monitor
    printf("\nThe period of the signal is from %d to %d ... ",t1,t2);
    printf("\nThe values at these instants are : \n");
    for(i=0;i<t;i++)
          printf("%d ",y[i]);
    getch();    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -