0% found this document useful (0 votes)
3 views

DiscreteSignalConvolution

The document contains a C program that performs convolution of two input signals. It prompts the user to enter the lengths and values of the two signals, computes their convolution, and outputs the result. The convolution is implemented in a separate function that initializes the output array and calculates the convolution values using nested loops.

Uploaded by

imytalwar759
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DiscreteSignalConvolution

The document contains a C program that performs convolution of two input signals. It prompts the user to enter the lengths and values of the two signals, computes their convolution, and outputs the result. The convolution is implemented in a separate function that initializes the output array and calculates the convolution values using nested loops.

Uploaded by

imytalwar759
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <stdio.

h>

void convolution(int x[], int h[], int y[], int n, int m) {


int i, j;

// Initialize the output array to zero


for (i = 0; i < n + m - 1; i++) {
y[i] = 0;
}

// Perform convolution
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
y[i + j] += x[i] * h[j];
}
}
}

int main() {
int n, m, i;

// Lengths of the input signals


printf("Enter the length of the first signal: ");
scanf("%d", &n);
int x[n];
printf("Enter the first signal: ");
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
}

printf("Enter the length of the second signal: ");


scanf("%d", &m);
int h[m];
printf("Enter the second signal: ");
for (i = 0; i < m; i++) {
scanf("%d", &h[i]);
}

// Length of the output signal


int y[n + m - 1];

// Call the convolution function


convolution(x, h, y, n, m);

// Print the result


printf("Convolution result: ");
for (i = 0; i < n + m - 1; i++) {
printf("%d ", y[i]);
}
printf("\n");

return 0;
}

You might also like