DSP - LTI convolution sum / C++ 구현
/*
* made by so_Sal
*/
y[n] = h[n]*x[n]
FIR filter는 LTI 시스템의 한 예로, 선형적이며 시불변성을 가집니다.
Impulse response h[n]은 입력이 델타로 표현될 때, y[n]을 결정시켜주는 시스템입니다.
h[n]에 의해 들어온 input들이 처리되어 각각의 하나의 신호를 만들며
그들이 겹쳐지는 신호합을 구하는 과정을 convolution 이라고 합니다.
아래는 h[n]과 x[n]의 impulse response가 주어졌을 때, y[n]을 구하는 convolution 과정입니다.
위의 convolution 작업을 c++을 이용하여 구현하였습니다.
아래는 H[n]과 X[n]이 배열로 주어졌을 때,
Y[n] 결과와 그 Matrix를 출력하는 프로그램입니다.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int x[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; //x[n] input
int h[] = {1,-1, 2,-1, 1, 0, 0, 0, 0, 0, 0}; //h[n] system
int matrix[100][100] = {0,};
for(int i=0;i<sizeof(h)/sizeof(int); i++){
for(int j=0;j<sizeof(x)/sizeof(int); j++){
matrix[i][i+j] = h[i]*x[j]; // convolution
}
}
for(int i=0;i<sizeof(h)/sizeof(int); i++){
for(int j=0;j<sizeof(x)/sizeof(int); j++){
cout<<setw(3)<<matrix[i][j];
}cout<<endl;
}
}