% demo of FS constructions % Jonathan (Y) Stein % resolution and number of terms t = (1:1024)/512; N=15; close all % triangular wave scrsz = get(0,'ScreenSize'); figure(1); set(1, 'Position', [ 1 1 scrsz(3)/2 scrsz(4)] ); figure(2); set(2, 'Position', [ scrsz(3)/2 1 scrsz(3)/2 scrsz(4)] ); y = zeros(size(t)); for i = 1:N j = 2*i-1; x = cos(2*pi*j*t)/(j*j) ; y = y + x; figure(1); hold on ; plot ( t, x ) ; title([ '\Sigma_{odd k} cos(2 \pi k t) / k^2 ' num2str(i) ]); figure(2); plot ( t, y ) ; if i==N title('triangle wave') ; end pause ; end close all % sawtooth wave figure(1); set(1, 'Position', [ 1 1 scrsz(3)/2 scrsz(4)] ); figure(2); set(2, 'Position', [ scrsz(3)/2 1 scrsz(3)/2 scrsz(4)] ); y = zeros(size(t)); for i = 1:N x = sin(2*pi*i*t)/i ; y = y + x; figure(1); hold on ; plot ( t, x ) ; title([ '\Sigma_k sin(2 \pi k t) / k ' num2str(i) ]); figure(2); plot ( t, y ) ; if i==N title('sawtooth') ; end pause ; end close all % square wave %figure(1); set(1, 'Position', [ 5 295 500 395]); %figure(2); set(2, 'Position', [520 295 500 395]); figure(1); set(1, 'Position', [ 1 1 scrsz(3)/2 scrsz(4)] ); figure(2); set(2, 'Position', [ scrsz(3)/2 1 scrsz(3)/2 scrsz(4)] ); y = zeros(size(t)); for i = 1:N j = 2*i-1; x = sin(2*pi*j*t)/j ; y = y + x; figure(1); hold on; plot ( t, x ) ; title([ '\Sigma_{odd k} sin(2 \pi k t) / k ' num2str(i) ]); figure(2); plot ( t, y ) ; if i==N title('square wave') ; end pause ; end close all % impulse figure(1); set(1, 'Position', [ 1 1 scrsz(3)/2 scrsz(4)] ); figure(2); set(2, 'Position', [ scrsz(3)/2 1 scrsz(3)/2 scrsz(4)] ); title('impulse'); y = zeros(size(t)); for i = 1:N i x = cos(2*pi*i*t) ; y = y + x; figure(1); hold on ; plot ( t, x ) ; title([ '\Sigma_k cos(2 \pi k t) ' num2str(i) ]); figure(2); plot ( t, y ) if i==N title('impulse') ; end pause end