![]() |
||||||
|
| Script SA1_1.m | |||
|
|||
|
%==============================================
%Fourier Series and Integrals %============================================== % %construction of a square wave alfa=linspace(-pi,pi,100); delta=alfa(2)-alfa(1); alfa1=linspace(-pi,0,50); alfa2=linspace(0,pi,50); f02=ones(1,50); f01=-f02; %and plot plot(alfa1,f01,'ro-',alfa2,f02,'ro-') title('Fig.1 The square wave'); grid on; axis([-3.5 3.5 -1.5 1.5]), figure; % %the first harmonics using Fourier series fact=4/pi; f1=fact*sin(alfa); plot(alfa1,f01,'ro-',alfa2,f02,'ro-',alfa,f1,'bs-'); title('Fig.2 The square wave and the first harmonics') grid on; axis([-3.5 3.5 -1.5 1.5]), figure; % %the second harmonics using Fourier series alfa3=alfa*3; fact3=fact/3; f3=fact3*sin(alfa3); plot(alfa1,f01,'ro-',alfa2,f02,'r-o',alfa,f3,'gd-'); title('Fig.3 The square wave and the second harmonics') grid on; axis([-3.5 3.5 -1.5 1.5]);figure; % %the sum of the first and the second harmonics f13=f1+f3; plot(alfa1,f01,'ro-',alfa2,f02,'ro-',alfa,f13,'y-*'); title('Fig.4 The square wave and the sum of the first and the second harmonics') grid on; axis([-3.5 3.5 -1.5 1.5]);figure; % %the third harmonics using Fourier series alfa5=alfa*5; fact5=fact/5; f5=fact5*sin(alfa5); plot(alfa1,f01,'ro-',alfa2,f02,'ro-',alfa,f5,'bd-'); title('Fig.5 The square wave and the third harmonics') grid on; axis([-3.5 3.5 -1.5 1.5]);figure; % %The square wave and the sum of the first, the second and third harmonics f135=f1+f3+f5; plot(alfa1,f01,'ro-',alfa2,f02,'ro-',alfa,f135,'bd-'); title('Fig.6 The square wave and the sum of the first three harmonics') grid on; axis([-3.5 3.5 -1.5 1.5]); %============================================== % |
|||
| Top | |||