%谐波叠加 t = -2*pi:0.001:2*pi; g = zeros(size(t)); f = zeros(size(t)); for n = -11:11 g = 1j/(n*pi); f = f+g*exp(1j*0.5*t*n); end y = sawtooth(0.5*t,1); subplot(3,1,3); xlabel('t'); plot(t,y); hold on; plot(t,f); legend('y 原函数','f 谐波叠加波形图');
x = sawtooth(t,xmax) 为锯齿三角波函数,描述周期内从-1到1的线性变化,在xmax*T处达到最大值1而后回落到-1。
周期延拓 把一个区间上的函数拓展到整个区间。
很明显可以看出原函数周期T=4π,我不知该如何写出按周期T=2π延拓后得到的函数or2
图三不连续点两侧出现吉布斯现象。
任务二
Write a function called square_wave that computes the sum
k=1∑n2k−1sin[(2k−1)t]
for each of 1001 values oft uniformly spaced from 0 to4π inclusive. The input argument is a scalar non-negtive integern, and the output argument is a row vector of 1001 such sums–one sum for each value oft. You can test your function by calling it withn=20 or greater and plotting the result and you will see why the function is called “square_wave”.
functionf = square_wave(n) n = 200; t = linspace(0,4*pi,n); k = 1:n; for num_t = 1:n t_temp = t(num_t); numerator = sin((2*k-1) * t_temp); denominator = 2*k-1; result = numerator ./ denominator; f(num_t) = sum(result); end
plot(k,f);
如图所示,n=200时,波形近似为幅度A=0.8,周期T=100的方波。
1 2 3 4 5
%上接原程序 hold on; y = 0.8*square(2*pi/100*k); plot(k,y); axis([0,200,-1,1]);
任务三
What functionf(t) has the Fourier series
n=1∑∞nsin(nt)
You can evaluate the sum analytically or numerically. Either way, guess a closed form forf(t) and then sketch it.
Confirm your conjecture forf(t) by finding the Fourier series coefficientsfn forf(t). Compare your result to the expression in the previous part. What happens to the cosione terms?
Define the partial sum
fN(t)=n=1∑Nnsin(nt)
Plot somefN(t)′s. By what fraction doesfN(t) overshootf(t) at worst? Does that fraction tend to zero or to a finite value asN→∞ ? If it is a finite value, estimate it. (hint: Gibbs phenomenon)
Now define the average of the partial sums:
FN(t)=Nf1(t)+f2(t)+f3(t)+⋯+fN(t)
Plot someFN(t)′s. Compare your plots with those offN(t) that you made in the previous part, and qualitatively explain any differences.
1 2 3 4 5 6 7 8 9 10 11 12 13
m=[]; i=1; for t = -10:0.01:10, s = 0; for n = 1:1:10000 s = s + sin(n*t)/n; end m(i) = s; i=i+1; end t = -10:0.01:10; plot (t,m); xlim([-3*pi3*pi]); ylim([-22]);
1 2 3 4 5 6 7 8 9 10 11 12 13
t = -pi:0.01:pi; syms n; w1 = symsum(sin(n*t)/n,n,1,30); w2 = symsum(sin(n*t)/n,n,1,60); w3 = symsum(sin(n*t)/n,n,1,90); S = symsum(sin(n*t)/n,n,1,9999); plot(t,S); hold on plot(t,w1,'r'); hold on plot(t,w2,'g'); hold on plot(t,w3,'b');
1 2 3 4 5 6 7 8 9 10 11
t = -3:0.01:3; syms n syms y w1 = symsum(symsum(sin(n*t)/n,n,1,y),y,1,40)/40; w2 = symsum(symsum(sin(n*t)/n,n,1,y),y,1,80)/80; w3 = symsum(symsum(sin(n*t)/n,n,1,y),y,1,160)/160; plot(t,w1,'m'); hold on plot(t,w2,'b'); hold on plot(t,w3,'g');