'분류 전체보기'에 해당되는 글 165건

  1. 2015.04.15 mason's formula 4
  2. 2015.04.03 Matlab 명령어
  3. 2015.04.03 matlab
  4. 2015.04.03 convolution - C++ 구현
  5. 2015.03.30 AC & DC coupling
  6. 2015.03.26 rect func fourier transform
  7. 2015.03.23 causal vs noncausal
  8. 2015.03.16 fourier property
  9. 2015.03.16 Properties of Fourier Transform
  10. 2015.03.16 convolution 의미

mason's formula

DSP 2015. 4. 15. 23:32




반갑습니다. 위대한 교주 LGS입니다. (모두들 교주를 찬양합시다)

System을 표현 하는 방법중에는 Transfer function을  담고 있는 Block(네모난 상자)들을 서로 연결하여 

Graphical 하게 System을 표현하는 방법도 있습니다. 각 Block은 System을 이루는 각 부품을 표현하는 TF일꺼구요~ 

Block으로 이루어진 그림을 Block Diagram이라고 그래요.

오늘은 이 Transfer function Block을 가지고 놀아보죠~ ^^


TF0301.png


만약 Block diagram에서 Transfer function이 series(직렬)로 연결되어 있으면 ... 둘을 곱하면 됩니다.

Control System Toolbox에서 series라는 함수를 제공하고 있지만 (G = series(G1,G2) ) 굳이 series라는 함수를 사용하실 필요 없이

그냥 간단하게 G = G1 * G2 라고 하시면 됩니다.



TF0302.png


Transfer function이 parallel(병렬)로 연결되어 있으면 둘을 더하면 되구요

역시 Control System Toolbox에서 parallel이라는 함수를 제공하고 있지만(G = parallel(G1,G2) ) 그냥 G = G1 + G2 라고 하셔도 됩니다.

여기까지는 문제 없으시죠? ^^

자 다음 Feedback을 포함하고 있는 closed loop를 봅시다~


TF0303.png


E(s)는 실제 output Y(s)와 내가 원하는 값 X(s) 사이의 차이(Error)를 말합니다. 

그러므로 E(s) = X(s) - Y(s)가 될꺼구요 ( (-)가 붙은 것에 주의하세요~ )

Feedback 신호에 (-)마이너스가 붙은 녀석을 Negative Feedback이라고 합니다.

H(s)는 센서 같은 녀석의 transfer function이구요. (G(s)는 plant(실제 작동하는 녀석)의 TF겠죠?)

전체 Transfer function은 Y(s) = E(s)G(s) 와 E(s) = X(s) - E(s)G(s)H(s) 를 연립해서 푸시면 쉽게 구하실 수 있습니다. ^^

계산을 해보시면 feedback loop의 transfer function은 Geq(s) = G(s)/[1+H(s)G(s)] 가 되네요 

(Negative Feedback인 경우 Geq가 G(s)/[1+H(s)G(s)] 라는 정도는 외워두시면 편합니다.)

MATLAB에서 closed loop의 전체 transfer function을 계산하시려면 feedback이라는 함수를 사용하시면 되요~ =(=^ㅅ^=)=

G_eq = feedback(G,H)라고 하시면 equivalent transfer function을 얻으 실 수 있습니다.


예를 들어 G(s) = 1/(s+2) , H(s) = 1/(s+3) 이라고 한다면 TF는?? 넵~ 잘하셨습니다 ㅎㅎ

TF0304.png

TF0305.png


아주 간단한 녀석으로 연습 하나 더 해보고 가겠습니다. ^^

TF0313.png


간단하다고 한건 훼이크였구요 ;; (죄송) 조금만 복잡해져도 머리속이 복잡해집니다요 ㅜㅜ

위의 Block diagram을 다른 방법으로 표현해보겠습니다.

TF0306.png

위와 같이 생긴 그림을 Signal-flow graph라고 해요.

Block diagram에서 Signal-flow graph로 변경하는 것 척!봐도 아시겠죠? ^^ 

Node(신호가 쪼개지거나 합쳐지는 지점)만 잘 잡으시고 부호만 신경 써주시면 땡입니다요~ o(^o^)o


위의 복잡한 Signal Flow Chart(또는 Block Diagram)를 팍 뭉뚱그려서 한개의 Block으로 만드는 방법이 있습니다. 

이름하야 (Mason 아져씨가 만들었다 하여) Mason's Rule !! 두둥!!

Mason's Rule을 적용하시려면 우선 3가지를 구해 주셔야 합니다.

Forward-path gain, Loop gain, 그리고 마지막으로 Nontouching-loop gain !!


Forward-path gain 부터 보죠~

Forward-path gain은 말 그대로 input X(s)에서 output Y(s)로 가는 모든 길을 말합니다. 단 중간에 뒤로 돌아올 수 없습니다.

무조건 앞으로만 전진하여 X(s)에서 Y(s)로 가는 모든 길을 찾아주시면 됩니다.


TF0307.png


TF0308.png


위의 예제의 경우 Forward-path가 2개가 있네요~ 그러므로

TF0309.png

이 됩니다.

두번째로 Loop gain. 말그대로 빙글빙글 도는 Loop를 모두 찾아주세요. 화살표 방향 잘보시고요~


Correction01.png 

 

아 복잡하군요 ^^;;  각 Loop를 따로 그려보면 

Correction03.png


Loop gain을 정리해봅시다요. o(^o^)o

Correction02.png  


마지막으로 Loop들끼리 Nontouching-loop gain을 찾아주시면 끝~

1번 loop와 2번 loop는 서로 노터치 하고 있네요. 그리고 1번 loop와 3번 loop도 노터치이구요~

2번,3번은 서로 터치합니다. 그러니까 Nontouching-loop gain에서 제외!!

(지금의 예제에서는 없지만 만약 3개,4개, 등등...의 Loop가 서로 독립적이라면 모든 조합을 다 적어주세요~)


Correction04.png  


자~ 이제 위에서 구한 Forward-path gain, Loop gain, Nontouching-loop gain을 Mason 아져씨가 잘 정리해둔 Mason's Rule에 

대입하면 끝~  =(=^ㅅ^=)=


Correction05.png 

여기에서 Δ는  1 - (모든 Loop gain의 합) + (모든 2 Nontouching-loop gain의 합) - (모든 3 Nontouching-loop gain의 합) - (모든 4 .....) 입니다.

지금의 예에서는 2 Nontouching-loop gain 밖에 없네요 ^^

Pk는 K번째 Forward-path gain이구요~ Δk는 K번째 Forward-path gain와 노터치하는 Loop의 Δ를 계산해주시면 됩니다.

지금은 모든 Loop가 Forward path랑 다 접하고 있어 Δk는 모두 1입니다.


Mason's Rule을 하시다보면 아~ 귀찮아요 -_-;; 흑묘든 백묘든 쥐만 잘 잡으면 됩니디요~ 깜장 고양이든 흰둥이 고양이든... 냠 

훨씬 간단한 방법이 있습니다. 대단히 대단하고 엄청히 엄청난 여러분의 교주가

Simulink로 Block diagram을 그리고 Simulink model에서 바로 Transfer function을 뽑아내 보겠습니다. ^^ (Simulink의 간단한 사용법)

우선 Simulink로 보이는 대로 들리는 대로 상상하는 대로 사이버 Simulink Model 하나 만드시구요~ (기타로 오토바이 타자!!)


TF0315.png 


위의 System은 G(s) = 1/s고 H(s)는 1이니까 Geq(s) = 1/(s+1)로 암산으로도 계산 할 수 있으시죠? =(=^ㅅ^=)= 

우선 Constant와 node(동그라미 안에 +-있는 녀석) 사이의 선을 선택하신 후 마우스 오른쪽을 클릭 -> Linearization Points -> Input point를 클릭하여

Input point를 만듭니다.


TF0316.png

 

다음으로 Integrator(1/s)와 Scope 사이의 선을 선택하신 후 위와 같은 방법으로 Output point를 만들어 주세요~

그러면 Input point와 Output point를 확인 할 수 있는 표시가 생깁니다.


TF0317.png


다음으로 Menu의 Tools -> Control Design -> Linear Analysis ... 를 클릭하셔서...

TF0318.png


Linear Analysis Tool을 띄워주세요.


TF0319.png


EXACT LINEARIZATION Tab에서 녹색 삼각형 Linearize 아이콘을 폭풍 클릭!!


TF0322.png


그러면 Linear Analysis Workspace에 linsys1 State Space(ss) class 변수가 생성된 것을 볼 수 있습니다.

(Plot Result에서 Step, Impluse 등 그래프도 바로 그릴 수 있습니다.)

사실 위에서 했던 것은 Nonlinear Simulnik 모델을 Linearization하는 과정이었구요~ 우리는 linsys1을 얻기 위해 위의 과정을 수행하였습니다.

자~ 마지막으로 Linear Analysis Workspace에 있는 linsys1을 MATLAB Workspace로 Drag & Drop 하시면 짠!!

MATLAB Workspace에 linsys1 ss model이  복사됩니다.


TF0323.png

State Space(SS) model을 Transfer Function(TF) model로 변환하시려면 그냥 tf 함수를 사용하시면 됩니다.

(model간 변환은 추후에 다루도록 하겠습니다.)


TF0324.png


Very Good!! 맞게 나오네요 o(^o^)o

위대한 교주의 능력!! ㅋㅋ




자~ 이번시간은 여기서 마무리하죵~ 

다음시간에 뵙겠습니다. 이만...

첨부 (30)

'DSP' 카테고리의 다른 글

convolution - C++ 구현  (0) 2015.04.03
rect func fourier transform  (0) 2015.03.26
causal vs noncausal  (0) 2015.03.23
fourier property  (0) 2015.03.16
Properties of Fourier Transform  (0) 2015.03.16
Posted by bogus919
,

Matlab 명령어

Matlab 2015. 4. 3. 18:37

MATLAB(1) 주요명령과 행렬입력방법   
1. 주요 명령어
▶ who, whos : 작업공간에 기억된 변수의 목록을 보여줌
▶ file ->show graphic property editor : 그래프 세팅
▶ set path : 경로지정. >>path 치면 경로가 나온다.
  MATLAB에서 파일의 경로등록/삭제에 쓰임. save path를 해 줘야한다.
▶ help : 도움말 명령. 예를들어 >>help fft 하면 FFT 함수에 대해서 도움말 제공. 매트랩 내장함수의 사용법을 잘 모를때 쓰면 도움이 된다.
▶ ! : >>!dir 하면 도스창에서 dir한것과 같은 효과. >>!dir&하면 새로운 창 생성
▶ lookfor : help함수처럼 MATLAB 함수나 명령어를 찾음. 많이 쓰인다.
▶ clear : workspace나 메모리에서 특정 항목을 지우는 데 사용한다.
▶ clc : clear_screen. 작업화면을 지우는 데 쓰인다. 도스에서 cls와 기능같음.


2. 행렬의 입력 : 매트랩에서 데이터  처리의 기본이 되는 단위는 행렬이다.
>>a=[1 2 3; 4 5 6; 7 8 9]
a = 
     1  2  3
     4  5  6
     7  8  9
(행 구분은 세미콜론(;) 혹은 개행(new line)을 사용. 열 구분은 콤마 혹은 공백)
▶ a(시작행:끝행,시작열:끝열) : 시작행~끝행과 시작열~끝열을 동시에 포함하는 행렬의 부분만 출력시켜 준다. a(i:j,k:l)
▶ load : file로부터 값을 불러온다. 
          >>load a.txt 하면 a라는 변수를 가진 행렬이 생기게 된다.
▶ 이미 존재하는 행렬에 다른 행렬을 추가해서 새 행렬을 만들수도 있다.
  D=[A;C] 는 A 행렬부분 밑에 C행렬이 추가되어 D행렬이 생긴다.
  D=[A,C] 는 A 행렬부분 옆에(오른쪽)에 C행렬이 추가돼 D행렬.
▶ 특별한 행렬
   a=[] : 빈 행렬이다. 행렬은 존재하나 요소가 없다.
   zeros(k) : k by k의 0의 원소를 갖는 정방행렬이 생긴다.
   zeros(m,n) : m by n의 0의 원소를 갖는 정방행렬.
   zeros(size(A)) : 행렬 A와 크기가 같은 영행렬이 생긴다.
   ones() : zeros와 사용법이 같음. 대신 원소값이 1이다.
   eys(n) : n by n 의 단위행렬이 생긴다.
   rand() : 0~1 사이의 값으로 균등분포된 난수들로 이루어진 행렬
   randn() : 0~1 사이의 값으로 정규분포된 난수들로 이루어진 행렬
▶ 벡터의 입력 : 벡터는 행벡터와 열벡터가 있으며 이들은 서로 전치(Transpose)를 통해 바꿀 수 있다. 전치를 할때 주의할 것은 벡터가 복소수일 경우 전치를 하면 켤레화되어 전치가 되어 버린다는 것.
>>a=[1 2 3 4 5] : 행벡터
>>a=[1;2;3;4;5] : 열벡터
a=1:1:5   콜론을 이용한 벡터입력 a=시작값:증분값:최종값
▶ 10의 거듭제곱 : a=4e5 = 4*10^5와 같다.

<행렬의 연산>
덧셈 : C = A + B;
뺄셈 : C = A - B;
곱셈 : C = A * B;           C = AB와 같다.
나눗셈 : C = A \ B; 혹은 C = A / B;
           A\B는 inv(A)B와 같은 기능, A/B는 Ainv(B)와 같다.
행렬의 나눗셈을 통해서 연립방정식의 해를 쉽게 구할 수 있다.
거듭제곱 : A^5 행렬 A를 5번 곱한거랑 같다.

▶ 행렬 조작
  rot90(A) : CCW(반시계방향)으로 90도 회전
  rot90(A,k) : k는 정수. k가 양이면 반시계, 음이면 시계방향으로 90*k만큼회전
  flipus(A) : 상하방향. fliplr(A) : 좌우방향
▶ 행렬의 배열 연산 : (.*)   (./)  (.\)  (.^)와 같이 도트를 첨가해 준다.
   그리고 연산되는 행렬의 차원이 서로 같아야 한다.
▶ 벡터의 내적(inner product)
   >>dot(A,B) 또는 sum(A.*B)
▶ 벡터의 외적(cross product)
  >>cross(A,B)



MATLAB(2) 그래픽 기능 I   
3. 그래픽(그래프그리기) 기능
▶ figure(n) 그림창 n을 호출한다. n은 정수인데 수를 굳이 쓰지 않아도 됨.
▶ set() 선의 종류 및 마커(marker)의 성질을 선택
   set(plot(x,y),'LineStyle','--') : 선의 모양이 실선에서 파선으로 그려짐
▶ axis([x축시작 x축끝 y축시작 y축끝]) : x축과 y축의 범위를 결정해 준다.
▶ grid on, grid off : 격자를 생성/없애줌
▶ xlabel('This is X axis') : x축을 라벨링함. y축, z축도 비슷하게 사용
▶ title('제목') : 그 그래프에 제목을 입력하고자 할때 사용

● figure() : (1)새로운 그림창 생성 (2) 이미 띄워진 그림창을 활성화
            즉, 여러개의 그래프를 출력하고자 할때 figure명령 사용하면 유용
● subplot(abc) : a by b 모양의 a*b개의 구역을 만들고 c번째를 선택.
   >>subplot(22k)는 아래처럼 4개 구역이 나뉘어지게 되는 것이다.
                                  221          222
                                  223          224

4. 선도(line plot)의 종류
★ plot() : x-y축이 모두 선형 배율을 가진다.
★ loglog() : x-y축 모두가 로그 배율을 가진다.
★ semilogx() : x축에는 로그배율, y축에는 선형 배율
★ semilogy() : y축에는 로그배율, x축에는 선형 배율
★ plotyy() : 2개의 그래프가 하나의 그림 창에 그려진다
                 이때 y는 서로 다르게 스케일링 된 것이 좌우 라벨창에 표시됨
*******************************************************************
>>plot(x좌표행렬,y좌표행렬,'Color+LineStyle+Marker')
선색깔 : 사이안(c)   마그네타(m)   노랑(y)     빨강(r)    녹색(g)
           파랑(b)      흰색(w)          검정(k)
선모양 : 기본(-)    파선(--)      없음(none)      점선(:)     -.-.-형태(-.)
마커 : +     ^(△)   O   *   .  x     square(□)    diamond(◇)    v(▽)
        >(▷)      <(◁)        pentagram(☆)      none(기본값)

>>plot(x1,y1,x2,y2,x3,y3,...) 여러쌍의 데이터를 그림창에 한꺼번에 표현
   선의 색을 지정하지 않아도 알아서 식별되도록 처리해준다.
*******************************************************************

<이미 존재하는 그래프에 새로운 그래프 추가>
>>hold (=hold on)
>>hold (=hold off) 
보통, 이미 열려있는 그림창에 hold on을 시켜 원하는 선도를 삽입한 후
hold off로 닫아준다.

<복소수 관련 함수>
§ isreal(A) : 입력값이 복수수이면 0, 실수이면 1
§ real(A) : 실수부만 호출
§ imag(A) : 허수부만 호출
§ abs(A) :  복소수의 크기 계산 a+bi => sqrt(a^2+b^2)
§ angle(A) : 각도를 계산 (-파이~파이의 범위)



MATLAB(3) 그래픽 기능 II   
<객체의 라벨링>
▶ title(제목) xlabel, ylabel, zlabel(xyz라벨링) grid(격자)
▶ legend : 그래프에 범례를 더한다.
   legend('str1','str2',...,'strN'',정수)
    정수가 0(MATLAB에서 고려한 최적위치), 1(오른쪽 위,기본치)
    2(왼쪽 위), 3(왼쪽 아래), 4(오른쪽 아래) -1(그래프 영역 오른쪽 밖)
▶ text(x좌표,y좌표,'String') : 그래프 좌표의 어떤 지점에 marker를 지정하고
   그곳을 라벨링할 때-예를 들면 그 그래프가 어떤 함수인지를 표시할 때
▶ gtext('String') : 그림창이 열리면 좌표(십자표시)가 나타나는데 적당한
   곳을 선택해서 입력한다. 마우스를 이용한 좌표의 입력이다.
▶ 특수문자 : MATLAB 책 134 페이지 참조.


<극 좌표계 polar coordinate system>
크기(반지름)와 각도(방위각)으로 좌표가 결정된다.
▶ polar(각도, 반지름, '컬러,스타일,마커')
plot 명령과는 달리 한 figure에 다중 입력은 되지 않는다.


<막대, 면적 그래프> - 2D & 3D
▶ bar(x축,y축,'색깔') : 2차원    barh(x,y,'color') : 수평방향
▶ bar3(), barh3() : 3차원 표현이다.
▶ y가 행렬일 경우 -> bar 그룹이 생성된다. 마치 히스토그램처럼
▶ 기냥 y만 입력 -> x좌표는 1,2,3... 이렇게 차례로 할당된다.
▶ 기타 형태의 막대 그래프
   bar3(x,y,'group') : 그룹지어진 그래프
   bar3(x,y,'stack') : 적층된 그래프, 스택 형태로 쌓여진 그래프

<면적 그래프>
▶ area(x,y) 
   y가 행렬일 경우에는 적층된 형태로 면적 그래프가 그려진다.

<파이 차트 pie chart>
▶ pie(y) : 벡터 y의 각 요소의 퍼센트를 계산해서 차트로 표시(반시계방향할당)
▶ pie(y, explode) : 파이 차트에서 어떤 부분을 차트로부터 분리하고자 할때
   이때 explode는 y와 같은 크기의 행렬인데, 0이면 그 부분은 분리되지 않고
   0이 아니면 파이에서 분리된 모양으로 표시가 된다.
▶ pie(y, explode, {'data1','data2',...,'dataN'}) : 라벨링은 이와 같이 한다.

<히스토그램>
▶ hist() : 직각 좌표계에서의 히스토그램이다.
   히스토르갬은 행렬 형태의 data를 bar 형태로 만든 것과 비슷하다.

<이산 데이터 그래프>
▶ bar(x,y) : 막대 모양의 그래프를 그린다.
▶ stem(x,y) :  가지 모양으로 수직으로 뻗은 그래프를 그림
   stem(x,y,'색,선모양,마커')
   stem(x,y,'~~~','fill') : 선의 끝의 원을 색으로 채울 때 사용
   stem3(x,y) : 3차원 이산 그래프
▶ stairs(x,y) : 계단 그래프를 그린다.

<선 그리기>
▶ line(Ax,Ay) 또는 line3(Ax,Ay,Az)
   Ax=[x1,x2]   Ay=[y1,y2]   Az=[z1,z2]



MATLAB(4) 제어의 흐름   
<관계, 동등연산자>
▶ 동등(==), 다름(~=), 논리곱(&), 논리합(|), 부정(~)
   <(작음), >(큼), <=(작거나 같음), >=(크거나 같음)
   xor(A,B) 배타적 논리합
▶ 복소수 데이터의 관계 연산 : 허수부를 무시하고 연산된다.
▶ 복소수 데이터의 동등 연산 : 허수부를 고려한다.

<기타 관계를 나타내는 함수>
▶ isfinte() : 입력이 유한(1), 무한 또는 not a number(0)으로 반환
▶ isinf() : 위와 반대의 경우
▶ isnan() : 입력이 숫자인지 아닌지를 조사(Not A Number)
▶ isequal() : 복수의 입력 변수들이 수치적으로 같으면 1, 그외 0
▶ isnumeric() : 입력값이 수(1), 그 외의 경우 0
▶ isreal() : 입력값의 모든 요소가 실수이면 1, 복수수이면 0 반환
▶ ~isreal() : 입력값의 하나 이상의 복소수 존재시 1
▶ isglobal() : 입력 변수가 전역 변수일 경우 1.


<< 조 건 문 >>
▶ if 와 elseif : if로 시작해서 end로 끝을 맺어준다.
a. if 단독으로 사용된 경우
b. if와 else가 사용된 경우 => if에서 의 조건이 아닌 모든 것은 else가 된다.
c. if와 elseif와 else가 다 사용된 경우
  => if에서 조건이 아닌 나머지 경우가 elseif에서 검색되고 이것 역시 만족
  하지 않는 조건이 그 다음의 elseif, 또 그 다음..., 이렇게 되고 이 모든 조건
  을 만족하지 않는 조건이 바로 else가 된다.
★ 각각의 쓰임새가 다르기 때문에 이를 숙지하고 있어야 한다.

<< switch 문 >>
여러가지 경우를 평가할 때 유용하다.
C언어에서는 (,)대신 (:)가 사용, otherwise대신 default, end대신 {~~}사용
▶ switch(a)
        case 수식 1,
                문장 1;
        case 수식 2,
                문장 2;
        case 수식 3,
                문장 3,
             ......
        otherwise,
                문장 xx;
   end

<< 반 복 문 >>
● while (n<=100)
       s=s+n;
       n=n+1;
   end
● while(1)
   ....
   end           % 이 경우엔 무한 반복하게 된다(Ctrl + C로 정지시킬 수 있음)
● MATLAB에는 C언어의 증가 연산자와 감소연산자(++, --)가 없다.

★ for k=k의촉값 : k의증분값 : k의 최종값
        문장
   end

~!~ TIP ~!~
o C언어에서는 배열의 인덱스로서 i j를 사용하지만
  MATLAB에서는 i j가 허수로 최급되므로 인덱스로의 사용을 삼가는 게 좋다.
o error('message') : 메시지 문자열을 명령 프롬프트에 출력 후 종료.
o warning('message') : 오류 메시지만 출력. 종료 안하고 계속 진행.
o disp() : 변수명을 출려가지 않고 그 변수의 값만 출력
o input() : 키보드로부터 어떤 값을 입력받을 때 사용
  R = input('Input the Value = ');
  문자를 입력받고자 할 때 R = input('출력메시지','s');
o for나 while을 행렬로 대체할 수 있다면 실행속도가 상대적으로 느린
  for, while문 대신 행렬식 연산을 이용하는게 더 좋다.

<< 분 기 문 >>
:: 어떤 특수한 상황에서 for나 while같은 반복문을 탈출하기 위해 사용
▶ break : 例를 들어 while의 논리식이 영원한 참이라면? 무한루프를 돌게 된다.
  이때 if와 break를 적절히 사용해서 원하는바 대로 루프를 빠져나올수 있다.
▶ return : break는 break가 존재하는 그 루프만을 빠져나가지만 return은
   그 루프를 바져나감과 동시에 현재의 값을 m-file로 작성된 MATLAB 함수의
   반환값으로 반환시켜 버린다. C언어의 return문과 같은 역할



MATLAB(5) M-file사용   
(1) 스크립트로서의 사용
◎ 명령어 또는 함수들의 "일괄처리가 주 목적이다.
◎ workspace에서의 변수들과 m-file 내의 변수들이 서로 영향을 끼친다.
   (함수와의 가장 큰 차이라고 볼 수 있다)

(2) 함수로서의 사용
◎ 외부로부터 값을 입력받아서 연산을 수행한 후 다시 외부로 값을 반환해줌
◎ 파일명은 가급적 함수명과 동일하도록 사용한다.
◎ 변수의 범위 : global 변수 => 스크립트 경우처럼 workspace와 m-file 서로영향
                 local 변수 => m-file과 workspace에서의 변수 서로 영향 안 끼침

★ function 출력인자 = 함수이름(입력인자)

● function [out1,out2, ... ,outN] = function_name(input1,input2, ... ,inputM)
   다중입력, 다중 출력방식
● function out = function_name(input1,input2, ... ,inputM)
   다중입력, 단일 출력방식
● function function_name(input1,input2, ... ,inputM)
   다중입력, 출력은 없음. 주로 그래프 그리기처럼 출력인자가 필요없을 경우 사용
● function function_name()
   입력, 출력이 없음. m-file과 workspace간의 변수가 영향 안미침을 제외하고는 
   스크립트와 그 기능이 거의 같다.



MATLAB(6) 문자열 취급 & 메뉴윈도우   
문자열을 취급할 때에는 C언어와는 달리 작은 따옴표(' ')를 사용한다.
▶abs(str)  : str이 수이면 절대값계산, 문자열이면 ASCII값으로 반환
▶isstr(str) : str이 문자열이면 1, 그 외에는 0
▶strcmp(str1,str2) : 두 문자열을 비교해서 일치하면 1, 그 외 0 (대소문자구분)
▶upper(str) : 문자열을 대문자(uppercase)로 변환
▶lower(str) : 문자열을 소문자로 변환
▶char(str) : ASCII형태의 문자열을 실제 문자열로 변환
▶str2double(str) : 문자열이 숫자(실수)일 경우 숫자로 변환해 준다.


Dialog 및 메뉴 윈도우
▶menu('제목','아이템1','아이템2',...'아이템n')
  화면에 메뉴가 뜨며, 아이템 k를 선택하면 결과로 k값이 반환된다.
(예) choice=menu('음식','닭고기','김치','찌게'); 한 상태에서 김치를
      선택하면 choice값은 2가 되는 것이다.
▶inputdlg('프롬프트','타이틀') : 프롬프트는 문자열 포함 cell array이고
  이 cell array가 2개 이상일 경우 값을 입력받는 부분이 그 수만큼 생성
->값을 입력받으면 이는 문자열의 cell array가 되며 숫자로 변환하고자 할때
  str2double(str)과 같은 함수를 이용한다.



MATLAB(7) 파일의 입출력   
<<파일의 입출력>>
(1) save와 load를 사용한 파일의 입출력
→MATLAB의 save에 의해 저장된 2진 파일(MAT파일)
→ASCII파일. 텍스트 편집기 등을 사용해 저장된 문자없이 숫자만 이뤄진 것.

▶ save
save 파일명 : workspace에 있는 모든 변수를 한 파일로 저장
save 파일명 변수1, 변수2, ... ,변수n : 임의의 변수를 한 파일로 저장
save 파일명 -ascii : 기본 파일저장형식인 2진파일(MAT파일)을 ASCII파일로 저장

(!!중요!!)ASCII 파일로 저장할 경우
→ cell array는 ASCII로 저장되지 않는다.
→ 변수를 ASCII파일로 저장하면 변수명은 저장안되고 변수값만 저장된다.
→ 복소수 데이터를 ASCII 파일 저장시 실수부만 저장이 된다.

▶ load 파일명
→ MAT 파일로 저장된 경우 변수의 이름과 같이 정확히 로딩됨
→ 일반 ASCII로 저장된 형식의 경우 그 파일명이 그 데이터의 변수가 된다.


(2) I/O(입출력) 함수들을 사용하는 방법
절차 : 파일을 열기(fopen) → 정보를주고받기(읽기,쓰기) → 파일을 닫기(fclose)
▶ [FileID] = fopen('FileName','permission')
permission : a. 파일접근방식 'r'(읽기) 'w'(덮어쓰기) 'a'(이어쓰기)
                  b. 파일교환모드 b(2진모드) t(텍스트모드)
fpt = fopen('test.txt','rt')
파일 열기에 성공하면 3이 상의 값이 반환된다.
이제 변수 fpt는 C언어에서의 파일 포인터 역할을 하게 된다.

▶ FileClose = fclose(FileID)
파일 닫기에 성공하면 0의 값을 반환한다(FileClose변수를 굳이 쓸 필욘없음)
   fclose('all') : 현재 개방된 모든 파일을 닫고자 할 때


★ fscanf : 파일로부터 데이터를 읽어들이기 위해 사용
A = fscanf(FileID,'format',size)
[A count] = fscanf(FileID, 'format', size)
→size에서 결정된 크기만큼 읽어들인 후 A에 저장한다.
→count는 읽어들인 데이터의 개수를 나타낸다(n, inf, [m,n])
→포맷 %d %f %s %c %e(지수) %u(unsigned)

★ fprintf : 파일에 임의의 데이터를 쓰기 위해 사용된다.
count = fprintf(FileID,'format',인자1,인자2, ...)
파일에 성공적으로 data의 바이트 수가 count에 반환된다.
→ 포맷에 대해서는 328페이지 참조
→ \n(개행문자) \t(탭문자) \\(역슬래쉬) %%(퍼센트)
→ %-md
   -는 왼쪽 정렬맞추기. -가 없으면 오른쪽 맞추기
   m은 출력할 정수의 폭 (%-m.nf의 경우엔 소수점 이하 n자리까지의 부동소수)
   d는 파일 전환자정자 f u 등이 쓰이겠지?
(ex) fprintf(fpt,'%-5d',k)

[ 출처 : http://blog.naver.com/yaho1524?Redirect=Log&logNo=60088402143 ]

'Matlab' 카테고리의 다른 글

matlab  (0) 2015.04.03
Posted by bogus919
,

matlab

Matlab 2015. 4. 3. 17:53

http://iamaman.tistory.com/category/programming%20language/MATLAB

'Matlab' 카테고리의 다른 글

Matlab 명령어  (0) 2015.04.03
Posted by bogus919
,

convolution - C++ 구현

DSP 2015. 4. 3. 17:24

/*

 * http://sosal.kr/

 * 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;

    }

 

}

 


'DSP' 카테고리의 다른 글

mason's formula  (4) 2015.04.15
rect func fourier transform  (0) 2015.03.26
causal vs noncausal  (0) 2015.03.23
fourier property  (0) 2015.03.16
Properties of Fourier Transform  (0) 2015.03.16
Posted by bogus919
,

원 출처는 http://blog.naver.com/wjdhun8/40036925329 입니다.

간단하게 말하고 DC(직류)성분을 없애고 AC(교류)성분과 통과시킨다는 의미입니다. 

아날로그 회로에서 직결된상태(직류,교류모두 통과)에서 중간에 콘덴서를 넣어주면
직류는 차단되고 교류만 통과하게 되죠. 이때를 AC coupling이라 합니다. 
----------------------------------------------------------------------------

AC커플링이란 교류만 통과시키고 DC는 내부콘덴서로 CUT시키게 만듭니다. 

예를 들어 DC 100V 에 AC 1V 가 같이 중첩되어 있는 파형에서 교류만 자세하게 보고 싶을때 AC커플링으로 하면 DC 100V는 CUT되고 교류 1V만 들어오므로 전압렌지를 낮추어 자세하게 볼수 있죠. 

만약 이때 DC 커플링으로 한다면 DC100V 때문에 전압렌지를 올려야 하는데 그러면 교류 1V는 자세하게 관찰할 수 없게되죠. 

DC커플링은 콘덴서를 통하지 않고 직접 들어가므로 DC, AC모두 관찰가능합니다. 

오실로스코프의 경우 보통 AC커플링의 경우 -3dB(0.707배)가 되는 하한 주파수는 대략 5HZ정도 되므로 이보다 낮은 주파수는 교류라 해도 DC커플링으로 하여 관찰하는 것이 좋습니다. 

-------------------------------------------------------------------------------------------------------------------

커플링(Coupling)
커플링 조절은 입력신호가 전면부의 패널에 있는 BNC입력 커넥터에서 채널의 수직 편향 시스템으로 통과되는 방식을 결정합니다. 여기에는 DC Coupling, AC Coupling이 있습니다.

DC커플링은 신호에 직접 연결되도록 해줍니다. 따라서 신호의 모든 성분들(AC+DC)이 화면에 표시됩니다. AC커플링은 BNC커넥터와 감쇄기 사이에 직렬로 캐패시터를 넣습니다.
신 호중의 DC성분은 통과하지 못하게 되고 , 저주파 AC성분들 또한 차단되거나 크게 감쇄됩니다. 저주파 차단 주파수는 볼래 신호값의 71%를 나타내는 주파수입니다. 저주파 차단은 일차적으로 입력 커플링 커패시터값에 좌우되며 일반적인 값은 10Hz입니다.

------------------------------------------------------------------------------------------------------------------

AC Coupling / DC Coupling

간단히 말해서 AC Coupling 이란 신호의 입력단 바로 직후에 High Pass Filter를 통과시키는 것이라고 보면 된다. 

신호가 갖고 있는 회로적 요인으로 인한  정전압 성분을 제거하여 실제 신호성분만 뽑아내기 위해서 사용하는데 이 방법의 문제점은 실제 신호의 저주파 성분까지 제거해 버릴 수 있다는 점이다.

예를 들어 스트레인 게이지를 이용하여 정적  및 동적 스트레인을 동시에 다 측정해야 할 필요가 있을 경우 AC Coupling 을 사용하면 정적 성분을 잃어버리는 결과를 갖게 된다. 

대부분의 경우 AC Coupling을 사용하면 0.05~0.1Hz 근방에서 High Pass Filter의 cutoff 가 설정되고 이하의 주파수 성분은 거의 사라지게 되어 측정되지 않는다. ICP 타입의 가속도 센서는 약 10 Volt 정도의 정전압 성분을 가지는데 AC 커플링시켜 사용하면 이러한 DC편향 성분을 제거할 수 있다.

이와는 달리 DC Coupling이란 신호를 그대로 통과시켜 정전압 성분의 존재 유무와 상관없이 컨디셔너가 신호를 그대로 측정 장비에 넘기고 여기서도 그대로 측정하는 경우에 사용하는 Coupling방법이다.

Posted by bogus919
,

rect func fourier transform

DSP 2015. 3. 26. 00:14



time domain에서 rect func은 수많은 사인파들의 합으로 이루어져있음

여기서 수많은 사인파들은 서로 다른 freq를 갖는다.

frequency domain에서 각각의 freq에 따른 amplitude를 나타내면(fourier transform)

그 결과가 바로 sinc func이 됨.


'DSP' 카테고리의 다른 글

mason's formula  (4) 2015.04.15
convolution - C++ 구현  (0) 2015.04.03
causal vs noncausal  (0) 2015.03.23
fourier property  (0) 2015.03.16
Properties of Fourier Transform  (0) 2015.03.16
Posted by bogus919
,

causal vs noncausal

DSP 2015. 3. 23. 20:22

1. 인과성 (Causality) ㅇ 현재 출력이 현재,과거의 입력에 만 의존하는 성질 - 현재 응답이 미래 입력을 미리 요구하지 않음 - 입력이 시작되기 전에는 출력이 나오지 않음 (어느 정도 입력된 후부터 출력됨) ㅇ 인과성에 대한 필요충분조건 - 연속시스템 : 임펄스 응답 h(t) = 0 (t < 0) - 이산시스템 : 임펄스 응답 h[n] = 0 (n < 0) ㅇ 인과시스템 특징 - 물리적으로 실현가능한 시스템 . 이미 도착한 것으로부터 출력을 만들어내는 지극히 당연한 시스템 - 메모리(기억성) 여부 . 무기억 시스템은 항상 인과적임 - 위상 특성 . 인과적시스템은 영 위상일 수 없음 - 전달함수 특성 . 분모 다항식의 차수가 분자 다항식의 차수 보다 높아야 함 .. 극점(Pole)영점(Zero) 보다 많거나 같아야 함 - 임펄스응답 특성 . 임펄스응답계단함수가 될 때 즉, h(t) = u(t)이면 당연히 인과시스템 임 2. 비 인과성 (Non-causality) ㅇ 현재 출력이 현재,과거의 입력 뿐만 아니라 미래의 입력에도 영향을 받음 - 현재 응답이 미래 입력을 미리 요구하고 있음 - 만일 현재 출력이 미래 입력도 필요하다면 비인과적 . 例) y[n] = x[n+1] .. n=0 에서 y[0]=x[1] 즉, 현재 출력 y[0]이 미래 입력 x[1]을 필요로 한 경우임 - 즉, 입력이 시작되기 전부터 이미 출력이 있어 온 경우 ㅇ 비인과시스템의 대표적인 例 - 이상적인 LPF는 오히려 비인과적임 ( t<0 에서 h(t)≠0 ) - 따라서, 이상적인 필터함수에 근사화시키는 설계 방법이 쓰여지게됨



'DSP' 카테고리의 다른 글

convolution - C++ 구현  (0) 2015.04.03
rect func fourier transform  (0) 2015.03.26
fourier property  (0) 2015.03.16
Properties of Fourier Transform  (0) 2015.03.16
convolution 의미  (0) 2015.03.16
Posted by bogus919
,

fourier property

DSP 2015. 3. 16. 01:02

http://doctord.dyndns.org/courses/bei/ee301/EE235/EE235/Project/lesson17/lesson17.html

'DSP' 카테고리의 다른 글

convolution - C++ 구현  (0) 2015.04.03
rect func fourier transform  (0) 2015.03.26
causal vs noncausal  (0) 2015.03.23
Properties of Fourier Transform  (0) 2015.03.16
convolution 의미  (0) 2015.03.16
Posted by bogus919
,

The properties of the Fourier transform are summarized below. The properties of the Fourier expansion of periodic functions discussed above are special cases of those listed here. In the following, we assume $\;\;{\cal F}[x(t)]=X(j\omega)$ and ${\cal F}[y(t)]=Y(j\omega)$.

  • Linearity 

    \begin{displaymath}{\cal F}[a x(t)+b y(t)]=a{\cal F}[x(t)]+b{\cal F}[y(t)] \end{displaymath}

  • Time shift 

    \begin{displaymath}{\cal F}[x(t \pm t_0)]=X(j\omega)e^{\pm j\omega t_0} \end{displaymath}

    Proof: Let $t'=t\pm t_0$, i.e., $t = t' \mp t_0$, we have 
    $\displaystyle {\cal F}[x(t \pm t_0)]$$\textstyle =$$\displaystyle \int_{-\infty}^\infty x(t\pm t_0)
e^{-j\omega t} dt
=\int_{-\infty}^\infty x(t')e^{-j\omega(t'\mp t_0)} dt'$ 
     $\textstyle =$$\displaystyle e^{\pm j\omega t_0}
\int_{-\infty}^\infty x(t')e^{-j\omega t'} dt'=X(j\omega)e^{\pm j\omega t_0}$ 

  • Frequency shift 

    \begin{displaymath}{\cal F}^{-1}[X(j\omega \pm \omega_0)]=x(t)e^{\mp j\omega_0 t} \end{displaymath}

    Proof: Let $\omega'=\omega\pm \omega_0$, i.e., $\omega = \omega'\mp\omega_0$, we have 
    $\displaystyle {\cal F}^{-1}[X(j(\omega \pm \omega_0))]$$\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty X(j(\omega\pm \omega_0))
e^{j...
...{2\pi}\int_{-\infty}^\infty X(j\omega')e^{j\omega(\omega'\mp \omega_0)}d\omega'$ 
     $\textstyle =$$\displaystyle e^{\mp j\omega_0 t}\;\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega')e^{j\omega'}d\omega'
=x(t)e^{\mp j\omega_0 t}$ 

  • Time reversal 

    \begin{displaymath}{\cal F}[x(-t)]=X(-\omega) \end{displaymath}

    Proof: 

    \begin{displaymath}{\cal F}[x(-t)]=\int_{-\infty}^\infty x(-t)e^{-j\omega t}dt \end{displaymath}

    Replacing $t$ by $-t'$, we get 

    \begin{displaymath}{\cal F}[x(-t)]=-\int_{\infty}^{-\infty} x(t')e^{j\omega t'}dt'
=\int_{-\infty}^{\infty} x(t')e^{j\omega t'}dt'=X(-\omega) \end{displaymath}

  • Even and Odd Signals and Spectra

    If the signal $x(t)$ is an even (or odd) function of time, its spectrum $X(j\omega)$ is an even (or odd) function of frequency: 

    \begin{displaymath}\mbox{if}\;\;x(t)=x(-t)\;\;\;\mbox{then}\;\;\;X(j\omega)=X(-j\omega) \end{displaymath}

    and 

    \begin{displaymath}\mbox{if}\;\;x(t)=-x(-t)\;\;\;\mbox{then}\;\;\;X(j\omega)=-X(-j\omega) \end{displaymath}

    Proof: If $x(t)=x(-t)$ is even, then according to the time reversal property, we have 

    \begin{displaymath}X(j\omega)={\cal F}[x(t)]={\cal F}[x(-t)]=X(-\omega) \end{displaymath}

    i.e., the spectrum $X(j\omega)=X(-\omega)$ is also even. Similarly, if $x(t)=-x(-t)$ is odd, we have 

    \begin{displaymath}X(j\omega)={\cal F}[x(t)]={\cal F}[-x(-t)]=-X(-\omega) \end{displaymath}

    i.e., the spectrum $X(j\omega)=-X(-\omega)$ is also odd.

  • Time and frequency scaling 

    \begin{displaymath}{\cal F}[x(at)]=\frac{1}{a}X(\frac{\omega}{a})\;\;\;\;\mbox{or}\;\;\;\;
{\cal F}[ax(at)]=X(\frac{\omega}{a}) \end{displaymath}

    Proof: Let $u=at$, i.e., $t=u/a$, where $a>0$ is a scaling factor, we have 

    \begin{displaymath}{\cal F}[x(at)]=\int_{-\infty}^\infty x(at)e^{-j\omega t} dt ...
... x(u)e^{-j\omega u/a} d(u/a)
=\frac{1}{a}X(\frac{\omega}{a}) \end{displaymath}

    Note that when $a<1$, time function $x(at)$ is stretched, and $X(j\omega/a)$ is compressed; when $a>1$$x(at)$ is compressed and $X(j\omega/a)$ is stretched. This is a general feature of Fourier transform, i.e., compressing one of the $x(t)$ and $X(j\omega)$ will stretch the other and vice versa. In particular, when $a\rightarrow 0$$x(at)$is stretched to approach a constant, and $X(j\omega/a)/a$ is compressed with its value increased to approach an impulse; on the other hand, when $a \rightarrow \infty$$ax(at)$ is compressed with its value increased to approach an impulse and $X(j\omega/a)$ is stretched to approach a constant.

  • Complex Conjugation


    \begin{displaymath}\mbox{if}\;\;\;{\cal F}[x(t)]=X(j\omega), \;\;\;\;
\mbox{then}\;\;{\cal F}[x^*(t)]=X^*(-j\omega) \end{displaymath}

    Proof: Taking the complex conjugate of the inverse Fourier transform, we get 

    \begin{displaymath}x^*(t)=[\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega) e^{j\o...
...2\pi}\int_{-\infty}^\infty X^*(j\omega) e^{-j\omega t} d\omega \end{displaymath}

    Replacing $\omega$ by $-\omega'$ we get the desired result: 

    \begin{displaymath}x^*(t)=\frac{1}{2\pi}\int_{-\infty}^\infty X^*(-\omega') e^{j\omega't} d\omega'
={\cal F}^{-1}[X^*(-\omega)] \end{displaymath}

    We further consider two special cases:
    • If $x(t)=x^*(t)$ is real, then 
        $\displaystyle {\cal F}[x(t)]=X(j\omega)=X_r(j\omega)+jX_i(j\omega)$ 
       $\textstyle =$$\displaystyle {\cal F}[x^*(t)]=X^*(-\omega)=X_r(-\omega)-jX_i(-\omega)$ 

      i.e., the real part of the spectrum is even (with respect to frequency $\omega$), and the imaginary part is odd: 

      \begin{displaymath}\left\{ \begin{array}{l} X_r(j\omega)=X_r(-j\omega)  X_i(j\omega)=-X_i(-j\omega) \end{array}
\right. \end{displaymath}

    • If $x(t)=-x^*(t)$ is imaginary, then 
        $\displaystyle {\cal F}[x(t)]=X(j\omega)=X_r(j\omega)+jX_i(j\omega)$ 
       $\textstyle =$$\displaystyle {\cal F}[-x^*(t)]=-X^*(-j\omega)=-X_r(-j\omega)+jX_i(-j\omega)$ 

      i.e., the real part of the spectrum is odd, and the imaginary part is even: 

      \begin{displaymath}\left\{ \begin{array}{l} X_r(j\omega)=-X_r(-j\omega)  X_i(j\omega)=X_i(-j\omega) \end{array}
\right. \end{displaymath}

    If the time signal $x(t)$ is one of the four combinations shown in the table (real even, real odd, imaginary even, and imaginary odd), then its spectrum $X(j\omega)$ is given in the corresponding table entry:

     if $x(t)$ is realif $x(t)$ is imaginary
     $X_r$ even, $X_i$ odd$X_r$ odd, $X_i$ even
    if $x(t)$ is Even  
    $X_r$ and $X_i$ even$X_i=0$$X=X_r$ even$X_r=0$$X=X_i$ even
    if $x(t)$ is Odd  
    $X_r$ and $X_i$ odd$X_r=0$$X=X_i$ odd$X_i=0$$X=X_r$ odd

    Note that if a real or imaginary part in the table is required to be both even and odd at the same time, it has to be zero.

    These properties are summarized below:

     $x(t)=x_r(t)+jx_i(t)$$X(j\omega)=X_r(j\omega)+jX_i(j\omega)$
    1real $x(t)=x_r(t)$even $X_r(j\omega)$, odd $X_i(j\omega)$
    2real and even $x(-t)=x_r(t)$real and even $X_r(j\omega)$
    3real and odd $x(-t)=-x_r(t)$imaginary and odd $X_i(j\omega)$
    4imaginary $x(t)=x_i(t)$odd $X_r(j\omega)$, even $X_i(j\omega)$
    5imaginary and even $x(-t)=x_i(t)$imaginary and even $X_i(j\omega)$
    6imaginary and odd $x(-t)=-x_i(t)$real and odd $X_r(j\omega)$

    As any signal can be expressed as the sum of its even and odd components, the first three items above indicate that the spectrum of the even part of a real signal is real and even, and the spectrum of the odd part of the signal is imaginary and odd.

  • Symmetry (or Duality)


    \begin{displaymath}\mbox{if}\;\;\;{\cal F}[x(t)]=X(j\omega),\;\;
\mbox{then}\;\;{\cal F}[X(t)]=2\pi\;x(-j\omega) \end{displaymath}

    Or in a more symmetric form: 

    \begin{displaymath}\mbox{if}\;\;\;{\cal F}[x(t)]=X(f),\;\;
\mbox{then}\;\;{\cal F}[X(t)]=x(-f) \end{displaymath}

    Proof: As ${\cal F}[x(t)]=X(j\omega)$, we have 

    \begin{displaymath}x(t)={\cal F}^{-1}[X(j\omega)]
=\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega)e^{j\omega t}d\omega
\end{displaymath}

    Letting $t'=-t$, we get 

    \begin{displaymath}x(-t')=\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega)e^{-j\omega t'}d\omega \end{displaymath}

    Interchanging $t'$ and $\omega$ we get: 

    \begin{displaymath}2\pi x(-\omega)=\int_{-\infty}^\infty X(t')e^{-j\omega t'}dt'={\cal F}[X(t)] \end{displaymath}

    or 

    \begin{displaymath}x(-f)=\int_{-\infty}^\infty X(t')e^{-j2\pi ft'}dt'={\cal F}[X(t)] \end{displaymath}

    In particular, if the signal is even: 

    \begin{displaymath}x(t)=x(-t) \end{displaymath}

    then we have 

    \begin{displaymath}\mbox{if}\;\;\;{\cal F}[x(t)]=X(f),\;\;\mbox{then}\;\;{\cal F}[X(t)]=x(f) \end{displaymath}

    For example, the spectrum of an even square wave is a sinc function, and the spectrum of a sinc function is an even square wave.

  • Multiplication theorem


    \begin{displaymath}\int_{-\infty}^\infty x(t)y^*(t) dt
=\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega)Y^*(j\omega) d\omega \end{displaymath}

    Proof: 
      $\displaystyle \int_{-\infty}^\infty x(t)y^*(t) dt
=\int_{-\infty}^\infty x(t) [\frac{1}{2\pi}\int_{-\infty}^\infty Y^*(j\omega)e^{-j\omega t}d\omega]dt$ 
     $\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty Y^*(j\omega)[\int_{-\infty}^\...
...dt] d\omega
=\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega)Y^*(j\omega) d\omega$ 

  • Parseval's equation

    In the special case when $y(t)=x(t)$, the above becomes the Parseval's equation (Antoine Parseval 1799)

    \begin{displaymath}\int_{-\infty}^\infty \vert x(t)\vert^2 dt
=\frac{1}{2\pi}\i...
...^\infty S_X(j\omega) d\omega
= \mbox{Total energy in $x(t)$}
\end{displaymath}

    where 

    \begin{displaymath}S_X(j\omega)\stackrel{\triangle}{=}\vert X(j\omega)\vert^2 \end{displaymath}

    is the energy density function representing how the signal's energy is distributed along the frequency axes. The total energy contained in the signal is obtained by integrating $S(j\omega)$ over the entire frequency axes.

    The Parseval's equation indicates that the energy or information contained in the signal is reserved, i.e., the signal is represented equivalently in either the time or frequency domain with no energy gained or lost.

  • Correlation

    The cross-correlation of two real signals $x(t)$ and $y(t)$ is defined as 

    \begin{displaymath}R_{xy}(t)\stackrel{\triangle}{=}\int_{-\infty}^\infty x(\tau)y(\tau-t)d\tau
=\int_{-\infty}^\infty x(t+\tau)y(\tau)d\tau \end{displaymath}

    Specially, when $x(t)=y(t)$, the above becomes the auto-correlation of signal $x(t)$ 

    \begin{displaymath}R_{x}(t)\stackrel{\triangle}{=}\int_{-\infty}^\infty
x(\tau)x(\tau-t)d\tau \end{displaymath}

    Assuming ${\cal F}[x(t)]=X(j\omega)$, we have ${\cal F}[x(t-\tau)]=X(j\omega)e^{-j\omega\tau}$ and according to multiplication theorem, $R_x(\tau)$ can be written as 
    $\displaystyle R_x(\tau)$$\textstyle =$$\displaystyle \int_{-\infty}^\infty x(t)x(t-\tau)dt
=\frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega)X^*(j\omega)e^{j\omega\tau}d\omega$ 
     $\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty \vert X(j\omega)\vert^2e^{j\o...
...infty}^\infty S_X(j\omega) e^{j\omega\tau}d\omega
= {\cal F}^{-1}[S_X(j\omega)]$ 

    i.e., 

    \begin{displaymath}{\cal F}[R_x(t)]=S_X(j\omega) \end{displaymath}

    that is, the auto-correlation and the energy density function of a signal $x(t)$ are a Fourier transform pair.

  • Convolution Theorems

    The convolution theorem states that convolution in time domain corresponds to multiplication in frequency domain and vice versa: 

    \begin{displaymath}{\cal F}[x(t)*y(t)]=X(j\omega)\;Y(j\omega) \;\;\;\;\;\;(a)\end{displaymath}


    \begin{displaymath}{\cal F}[x(t)\;y(t)]=X(j\omega)*Y(j\omega) \;\;\;\;\;\;(b)\end{displaymath}

    Proof of (a): 
    $\displaystyle {\cal F}[x(t)*y(t)]$$\textstyle =$$\displaystyle \int_{-\infty}^\infty [ \int_{-\infty}^\infty
x(\tau)y(t-\tau)d\tau] e^{-j\omega t} dt$ 
     $\textstyle =$$\displaystyle \int_{-\infty}^\infty x(\tau) [ \int_{-\infty}^\infty
y(t-\tau) e^{-j\omega t} dt] d\tau$ 
     $\textstyle =$$\displaystyle \int_{-\infty}^\infty x(\tau) e^{-j\omega \tau}[ \int_{-\infty}^\infty
y(t-\tau) e^{-j\omega(t-\tau)} d(t-\tau)] d\tau$ 
     $\textstyle =$$\displaystyle X(j\omega) \; Y(j\omega)$ 

    Proof of (b): 
    $\displaystyle {\cal F}[x(t)\;y(t)]$$\textstyle =$$\displaystyle \int_{-\infty}^\infty x(t)\;y(t) e^{-j\omega t} dt$ 
     $\textstyle =$$\displaystyle \int_{-\infty}^\infty [\frac{1}{2\pi}\int_{-\infty}^\infty
X(j\omega') e^{j\omega't} d\omega'] \; y(t) e^{-j\omega t} dt$ 
     $\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega') [ \int_{-\infty}^\infty
y(t) e^{j\omega't} e^{-j\omega t} dt] d\omega'$ 
     $\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega') [\int_{-\infty}^\infty
y(t) e^{-j(\omega-\omega')t} dt] d\omega'$ 
     $\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega') Y(j(\omega-\omega')) d\omega'
= X(j\omega) * Y(j\omega)$ 

  • Time Derivative 

    \begin{displaymath}{\cal F}[\frac{d}{dt}x(t)]=j\omega\;X(j\omega) \end{displaymath}

    Proof: Differentiating the inverse Fourier transform $X(j\omega)$ with respect to $t$ we get: 
    $\displaystyle \frac{d}{dt} x(t)$$\textstyle =$$\displaystyle \frac{d}{dt} [\frac{1}{2\pi}
\int_{-\infty}^\infty X(j\omega)e^{j...
...frac{1}{2\pi}\int_{-\infty}^\infty X(j\omega) \frac{d}{dt}e^{j\omega t} d\omega$ 
     $\textstyle =$$\displaystyle \frac{1}{2\pi}\int_{-\infty}^\infty [j\omega X(j\omega)] e^{j\omega t} d\omega
= {\cal F}^{-1} [j\omega X(j\omega)]$ 

    Repeating this process we get 

    \begin{displaymath}{\cal F}[\frac{d^n}{dt^n} x(t)]=(j\omega)^nX(j\omega) \end{displaymath}

  • Time Integration

    First consider the Fourier transform of the following two signals: 

    \begin{displaymath}u(t)=\left\{ \begin{array}{ll} 0 & t<0 \ 1 & t>0 \end{array}...
...} -1/2 & t<0 \ 1/2 & t>0 \end{array}\right. =u(t)-\frac{1}{2}
\end{displaymath}


    \begin{displaymath}\frac{d}{dt}u(t)=\delta(t), \;\;\;\;\;\;\;
\frac{d}{dt} sgn(t)=\frac{d}{dt} [u(t)-\frac{1}{2}]=\delta(t) \end{displaymath}

    According to the time derivative property above 

    \begin{displaymath}X(j\omega)={\cal F}[x(t)]=\frac{1}{j\omega}{\cal F}[ \frac{d}{dt}x(t) ] \end{displaymath}

    we get 

    \begin{displaymath}{\cal F}[u(t)]=\frac{1}{j\omega}{\cal F}[ \frac{d}{dt}x(t)]=
\frac{1}{j\omega}{\cal F}[ \delta(t)]=\frac{1}{j\omega} \end{displaymath}

    and 

    \begin{displaymath}{\cal F}[sgn(t)]=\frac{1}{j\omega}{\cal F}[ \frac{d}{dt}sgn(t)]=
\frac{1}{j\omega}{\cal F}[ \delta(t)]=\frac{1}{j\omega} \end{displaymath}

    Why do the two different functions have the same transform?

    In general, any two function $f(t)$ and $g(t)=f(t)+c$ with a constant difference $c$ have the same derivative $d\;f(t)/dt$, and therefore they have the same transform according the above method. This problem is obviously caused by the fact that the constant difference $c$ is lost in the derivative operation. To recover this constant difference in time domain, a delta function needs to be added in frequency domain. Specifically, as function $sgn(t)$ does not have DC component, its transform does not contain a delta: 

    \begin{displaymath}{\cal F}[sgn(t)]=\frac{1}{j\omega} \end{displaymath}

    To find the transform of $u(t)$, consider 

    \begin{displaymath}u(t)=sgn(t)+\frac{1}{2} \end{displaymath}

    and 

    \begin{displaymath}{\cal F}[u(t)]={\cal F}[sgn(t)]+{\cal F}[\frac{1}{2}]
=\frac{1}{j\omega}+\pi \delta(\omega) \end{displaymath}

    The added impulse term $\pi \delta(\omega)$ directly reflects the constant $c=1/2$ in time domain.

    Now we show that the Fourier transform of a time integration is 

    \begin{displaymath}{\cal F}[\int_{-\infty}^t x(\tau) d\tau] =\frac{1}{j\omega}\;X(j\omega)
+\pi X(0)\delta(\omega) \end{displaymath}

    Proof:

    First consider the convolution of $x(t)$ and $u(t)$

    \begin{displaymath}x(t)*u(t)=\int_{-\infty}^{\infty} x(\tau)u(t-\tau) d\tau
=\int_{-\infty}^t x(\tau) d\tau \end{displaymath}

    Due to the convolution theorem, we have 

    \begin{displaymath}{\cal F}[\int_{-\infty}^t x(\tau) d\tau]=
{\cal F}[x(t)*u(t)]...
...\omega)]
=\frac{1}{j\omega}\;X(j\omega)+\pi X(0)\delta(\omega) \end{displaymath}

  • Frequency Derivative 

    \begin{displaymath}{\cal F}[tx(t)]=j\frac{d}{d\omega}X(j\omega) \end{displaymath}

    Proof: We differentiate the Fourier transform of $x(t)$ with respect to $\omega$ to get 
    $\displaystyle \frac{d}{d\omega}X(j\omega)$$\textstyle =$$\displaystyle \frac{d}{d\omega}[\int_{-\infty}^\infty
x(t)e^{-j\omega t}dt]
=\int_{-\infty}^\infty x(t)\frac{d}{d\omega}e^{-j\omega t}dt$ 
     $\textstyle =$$\displaystyle \int_{-\infty}^\infty x(t)(-jt)e^{-j\omega t}dt$ 

    i.e., 

    \begin{displaymath}{\cal F}[-jt x(t)]=\frac{d}{d\omega}X(j\omega) \end{displaymath}

    Multiplying both sides by $j$, we get 

    \begin{displaymath}j\frac{d}{d\omega}X(j\omega)
=\int_{-\infty}^\infty tx(t)e^{-j\omega t}dt
={\cal F}[tx(t)]
\end{displaymath}

    Repeating this process we get 

    \begin{displaymath}{\cal F}[t^n x(t)]=j^n \frac{d^n}{d\omega^n}X(j\omega) \end{displaymath}


'DSP' 카테고리의 다른 글

convolution - C++ 구현  (0) 2015.04.03
rect func fourier transform  (0) 2015.03.26
causal vs noncausal  (0) 2015.03.23
fourier property  (0) 2015.03.16
convolution 의미  (0) 2015.03.16
Posted by bogus919
,

convolution 의미

DSP 2015. 3. 16. 00:36

많은 학생들이 convolution의 의미를 모르고 그냥 배운대로 계산만 하는것 같다. 얼마전 아는 후배도 convolution의 의미에 대해 물어본적이 있는데 나도 학부시절 고민하던 것으로 혼자 골똘히 생각해 보다 이해하게 된 것인데 전자공학을 공부하는 학부생들의 이해를 돕고자 글을 올린다.


간단히 convolution의 의미에 대해 말하자면 시스템에 메모리가 있는 경우 한 시스템의 출력이 현재 입력에 의해서만 결정되는 것이 아닌 이전 입력(causal system 이라면)에 의해서도 영향을 받기 때문에 그에 대한 출력을 나타내기 위해 하는 연산이다.
예를 들어 종(鍾)을 LTI(Liner Time Invariant) 시스템이라고 가정한다면 종을 한번 치면 그 소리가 치는 순간만 나는게 아니라 치는 순간에 소리가 크게 났다가 점점 소리가 감쇠되며 작아진다.

이해를 돕고자 그림으로 나타내면 다음 그림의 첫번째 경우와 같다. 종을 한번 탕 치는 것을 impulse 입력이라 하고 한번 종을 쳤을 때 나는 소리를 삼각형으로 나타냇다.

그런데 종을 한번 치고 다시 치면 어떨까? 그림의 두번째 경우는 처음 종을 치고 잠시 후 이전보다 약하게 친 경우이다. 이 때는 종소리를 Linear system으로 가정했기 때문에 이전의 입력에 의해 나고 있는 소리에 현재 입력에 의해 나는 소리가 더해져 나타난다. 그리고 이것은 impulse 입력과 종소리의 convolution 과 같은 결과가 나올 것이다.

따라서 convolution은 한 LTI 시스템에 대해 현재와 이전의 입력에 대한 출력을 계산하기 위해 수행하는 것이다.


그림의 두번째 경우를 보면 왜 컨볼루션을 할 때 system이나 입력중 하나를 반전시켜야 하는지에 대해 알 수 있다.
한 시스템에 시간적으로 앞선 입력을 먼저 넣고 그 후에 시간적으로 나중에 발생한 입력을 넣어야 올바른 출력을 얻을 수 있기 때문에 시간적으로 앞선 입력을 먼저 넣기 위해 입력을 반전시키거나 시스템을 반전시키는 것이다.

입력을 반전시키지 않으면 처음에 종을 약하게 치고 그 후에 세게 친것과 같은 결과가 나오기 때문에 시간적으로 반대의 결과가 나온다.


'DSP' 카테고리의 다른 글

convolution - C++ 구현  (0) 2015.04.03
rect func fourier transform  (0) 2015.03.26
causal vs noncausal  (0) 2015.03.23
fourier property  (0) 2015.03.16
Properties of Fourier Transform  (0) 2015.03.16
Posted by bogus919
,