Skip to content

Commit f4eec5f

Browse files
Create linear_convolution.c
1 parent a6c274c commit f4eec5f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: linear_convolution.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<stdio.h>
2+
int main()
3+
{ int x[100],h[100],y[100],i,j,N,M;
4+
printf("Enter the size of sequence x[n]: ");
5+
scanf("%d",&N);
6+
printf("Enter the size of sequence h[n]: ");
7+
scanf("%d",&M);
8+
//Input the sequence x[n]
9+
printf("Enter the sequence x[n]: ");
10+
for(i=0;i<N;i++)
11+
scanf("%d",&x[i]);
12+
for(i=N;i<M+N-1;i++)
13+
x[i]=0;
14+
//Input the sequence h[n]
15+
printf("Enter the sequence h[n]: ");
16+
for(i=0;i<M;i++)
17+
scanf("%d",&h[i]);
18+
for(i=M;i<M+N-1;i++)
19+
h[i]=0;
20+
//Compute Convolution
21+
for(i=0;i<M+N-1;i++)
22+
{ y[i]=0;
23+
for(j=0;j<=i;j++)
24+
y[i]+=x[j]*h[i-j];
25+
}
26+
//Display the output sequence
27+
for(i=0;i<M+N-1;i++)
28+
printf("%d ",y[i]);
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)