用matlab計算連續函式卷積的表示式
阿新 • • 發佈:2018-12-20
卷積計算起來較為繁瑣, 若能夠用matlab輔助計算則會簡單很多. 通過使用卷積定理和MATLAB符號函式, 便可以計算連續函式的卷積表示式.
本文主要包括如下幾個部分: 1. 利用符號函式計算Fourier變換和Fourier反變換 2. 利用符號函式進行卷積計算 3. 以訊號與系統考研題中的例題為例進行說明1. 利用符號函式計算Fourier變換和Fourier反變換
Matlab提供了fourier 和 ifourier 兩個內建函式. 下面是fourier的幫助fourier Fourier integral transform. F = fourier(f) is the Fourier transform of the symbolic expression or function f with default independent variable x. If f does not contain x, then the default variable is determined by SYMVAR. By default, the result F is a function of w. If f = f(w), then F is returned as a function of the variable v, F = F(v). By definition, F(w) = c*int(f(x)*exp(s*i*w*x),x,-inf,inf). You can set the parameters c,s to any numeric or symbolic values by setting the preference SYMPREF('FourierParameters',[c,s]). By default, the values are c = 1 and s = -1. F = fourier(f,v) returns F as a function of the variable v instead of the default variable w: F(v) = c*int(f(x)*exp(s*i*v*x),x,-inf,inf). F = fourier(f,u,v) treats f as a function of the variable u instead of the default variable x: F(v) = c*int(f(u)*exp(s*i*v*u),u,-inf,inf). Examples: syms t v w x f(x) fourier(1/t) returns -pi*sign(w)*1i fourier(exp(-x^2),x,t) returns pi^(1/2)*exp(-t^2/4) fourier(exp(-t)*heaviside(t),v) returns 1/(1+v*1i) fourier(diff(f(x)),x,w) returns w*fourier(f(x),x,w)*1i
ifourier Inverse Fourier integral transform. f = ifourier(F) is the inverse Fourier transform of the symbolic expression or function F with default independent variable w. If F does not contain w, then the default variable is determined by SYMVAR. By default, the result f is a function of x. If F = F(x), then f is returned as a function of the variable t, f = f(t). By definition, f(x) = abs(s)/(2*pi*c) * int(F(w)*exp(-s*i*w*x),w,-inf,inf). You can set the parameters c,s to any numeric or symbolic values by setting the preference SYMPREF('FourierParameters',[c,s]). By default, the values are c = 1 and s = -1. f = ifourier(F,u) returns f as a function of the variable u instead of the default variable x: f(u) = abs(s)/(2*pi*c) * int(F(w)*exp(-s*i*w*u),w,-inf,inf). f = ifourier(F,v,u) treats F as a function of the variable v instead of the default variable w: f(u) = abs(s)/(2*pi*c) * int(F(v)*exp(-s*i*v*u),v,-inf,inf). Examples: syms t u v w f(x) ifourier(w*exp(-3*w)*heaviside(w)) returns 1/(2*pi*(-3+x*1i)^2) ifourier(1/(1 + w^2),u) returns exp(-abs(u))/2 ifourier(v/(1 + w^2),v,u) returns -(dirac(1,u)*1i)/(w^2+1) ifourier(fourier(f(x),x,w),w,x) returns f(x)
syms t fourier(exp(-2*abs(t-1)))得到如下結果:
>> fourier(exp(-2*abs(t-1))) ans = - exp(-w*1i)/(- 2 + w*1i) + exp(-w*1i)/(2 + w*1i)本題的參考答案為: 對比可知, 通過MATLAB得到的結果與實際結果相同. 同理, 我們也可以計算Fourier的反變換. 如下所示
>> syms w >> ifourier(dirac(w)) ans = 1/(2*pi)
2. 利用符號函式進行卷積計算
通過計算Fourier變換和反變換, 我們便可以結合卷積定理, 如式\ref{eq1}所示, 求出任意兩個函式的卷積. $$x(t)*h(t)=F^{-1}(X(jw)\dot H(jw)) \tag{1} \label{eq1}$$ 例如, 我們用$x(t)=e^{cos(3t+\frac{1}{4}\pi)}$與$\delta(t-3)$的卷積進行驗證, 有dirac函式的性質, 結果顯然應為$x(t)=e^{cos(3(t-3)+\frac{1}{4}\pi)}$syms t >> xt = exp((cos(3*t + 0.25*pi))) xt = exp(cos(3*t + pi/4)) >> f_xt=fourier(xt) f_xt = fourier(exp(cos(3*t + pi/4)), t, w) >> f_ht=fourier(dirac(t-3)) f_ht = exp(-w*3i) >> result = ifourier(f_xt * f_ht) result = exp(cos(3*x + pi/4 - 9))結果正確.
3. 以訊號與系統考研題中的例題為例進行說明
題目為: 若$x(t)=\frac{sint}{t}$, 則積分$\int_{-\pi}^{\pi}[x^2(t)*sin(t+\frac{\pi}{3})]dt$的值為多少? 正解為0, 方法是求出$x^2(t)$和$sin(t+\frac{\pi}{3})$的Fourier變換, 通過卷積定理, 再利用三角函式的週期性即可得到結果為0. (歡迎補充更簡單的方法~) 用MATLAB則可通過如下程式碼求解:syms t ft = sin(t)*sin(t)/(t*t); ft = sin(t)*sin(t)/(t*t); vt = sin(t+pi/3); f_ft = fourier(ft); f_vt = fourier(vt); f_anss = f_ft * f_vt; fv = ifourier(f_anss); result = int(fv, [-pi, pi])輸出為:
result = 0可見, 利用MATLAB能夠比較好地計算連續函式卷積結果的表示式, 並可以用來解決實際的問題. 其中, dirac函式, li表示的虛部, 以及fourier和ifourier函式都是之前沒用過的新函式.