用matlab计算连续函数卷积的表达式
生活随笔
收集整理的這篇文章主要介紹了
用matlab计算连续函数卷积的表达式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文地址: https://www.computationalimaging.cn/2018/11/matlab.html
卷積計算起來較為繁瑣, 若能夠用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的幫助 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) 顯然, 有了這兩個函數, 我們便可以利用符號變量計算Fourier變換和反變換.
例如, 對于奧本海姆<信號與系統(第2版)>習題4.1(b)
計算$f(t)=e^{-2|t-1|}$的傅里葉變換
我們便可利用MATLAB進行計算:
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函數都是之前沒用過的新函數.?
總結
以上是生活随笔為你收集整理的用matlab计算连续函数卷积的表达式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数组2——查找第k小元素
- 下一篇: AndroidStudio开发高德地图有