%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % sqmmf.m - Generates a normalized square wave mmf and its % associated Fourier spectrum. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; clf; % Construct & plot square wave. n=1024; x=ones(1,n); x(n/2:n)=-x(n/2:n);ang=linspace(0,360,n); subplot(2,1,1); axis tight; plot(0,1.1,0,-1.1,ang,x); grid; title('Normalized air gap square wave mmf'); xlabel('Angular position, elect. deg.'); ylabel('mmf/Ni - pu'); % Determine Fourier coefficients & plot in percent. x=abs(fft(x)); x=x/max(x)*100; subplot(2,1,2); axis; plot([0:25],x(1:26)); grid; title('Fourier coefficients of square wave mmf'); xlabel('Harmonic number'); ylabel('Harmonic magnitude, %');