clear; clc; fprintf('Fouriercomponenten of a square wave\n\n'); A = input('Amplitude A of the square wave [V]: '); T = input('Period T of the square wave [ms]: '); fprintf('\n'); w0 = 2*pi/T; amp = 4*A/pi; tv = 0:T/50:2*T; ehv = amp*sin(w0*tv); dhv = (amp/3)*sin(3*w0*tv); vhv = (amp/5)*sin(5*w0*tv); blv = A*(sign(ehv)); epdhv = ehv + dhv; epdpvhv = epdhv + vhv; maxamp=max(ehv); mA=ceil(maxamp); figure(1); set(clf,'PaperType','A4'); set(clf,'Color',[1,1,1]); subplot(221); plot(tv, blv, tv, ehv, tv, dhv, tv, vhv); xlabel('time [ms]','Fontsize',8); title('first three harmonics','Fontsize',8); set(gca,'Fontsize',8); subplot(222); plot(tv, blv, tv, ehv); xlabel('time [ms]','Fontsize',8); title('first harmonic','Fontsize',8); set(gca,'Fontsize',8); subplot(223); plot(tv, blv, tv, epdhv); xlabel('time [ms]','Fontsize',8); title('sum first and third harmonic','Fontsize',8); set(gca,'Fontsize',8); subplot(224); plot(tv, blv, tv, epdpvhv); xlabel('time [ms]','Fontsize',8); title('sum of all harmonics','Fontsize',8); set(gca,'Fontsize',8);