[問題] Fourier轉換
題目是這樣
┌cosx , 0 < x < π/2
f(x) ┤ ,f(x+π)=f(x)
└0 , π/2 < x < π
以下是我的程式碼
--------------------------------------------------------
1 syms x;
2 T=pi;
3 w0=2*pi/T;
4 p=T/2;
5 t=[-p:0.01:p];
6 fx=cos(x)*(heaviside(x)-heaviside(x-pi/2));
7 ft=cos(t)*(heaviside(t)-heaviside(t-pi/2));
8 fn=0.;k=0;
9 for n=-10:10
10 k=k+1;
11 wn(k)=n*w0;
12 c=double(1./T*int(fx*exp(-i*wn(k)*x),x,-p,p));
13 d(k)=abs(c);
14 fn=fn+c*exp(i.*wn(k)*t);
15 end
16 subplot(3,1,1),plot(t,real(fn),t,ft,'r')
17 subplot(3,1,2),plot(wn,d,'o')
18 subplot(3,1,3),bar(wn,d)
--------------------------------------------------------
Run出來的結果一直出現
Error using *
Inner matrix dimensions must agree.
有沒有眼尖的大大可以幫幫忙THX^^~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.249.230.135
→
05/01 23:48, , 1F
05/01 23:48, 1F
→
05/01 23:48, , 2F
05/01 23:48, 2F
→
05/02 01:08, , 3F
05/02 01:08, 3F