Code covered by the BSD License  

Highlights from
cofficients of fourier series

from cofficients of fourier series by davood shaghaghi
This function is written to calculate the cofficients of fourier series.

[]=fs(x,T0,n,type)
%%This function is written to calculate the cofficients of fourier series.
%% in the function arguments, fs(x,T0,n,type), note that :
%%     x    : the fuction that you might to calculate it's  fourier series,
%%            note that you should enter one period of the periodic function(x).
%%             Be careful! You should enter one period of signal in range [-T/2,T/2] 
%%              ,not [0 T] or other ranges.
%%     T0   : Period of function.
%%     n    : Number of cofficients must be calculated.
%%     type : type 0 to calculate the magnitude and phase of cofficients.
%%            type 1 to calculate the real and imaginary part of cofficients.


  %% *****************************************************************************
  %% *                       by : Davood Shaghaghi                               *
  %% * Electrical Engineering Department, Hamedan University of Technology(HUT)  * 
  %% *                 Email: davood.shaghaghi@gmail.com                         * 
  %% *                           April 14, 2010                                  *
  %% *              Copying is permitted with source citation!                   *
  %% ***************************************************************************** 
                                                    
function []=fs(x,T0,n,type)
syms t
k=[-n:n];
ak=(1/T0)*int(x*exp(-k*(2*pi/T0)*t*i),t,-T0/2,T0/2);
akd=subs(ak);
subplot(3,1,1)
ezplot(x)
if type ==1
    subplot(3,1,2)
    stem(k,real(ak))
    for xx=1:2*n+1
    text(xx-n-1-.1,0.1,['',num2str(real(akd(xx)))],...
	'VerticalAlignment','middle',...
	'HorizontalAlignment','left',...
	'FontSize',8)
     end
    title('real part of fourier series cofficients')
    xlabel('k')
    subplot(3,1,3)
    stem(k,imag(ak))
     for xx=1:2*n+1
    text(xx-n-1-.1,0.1,['',num2str(imag(akd(xx)))],...
	'VerticalAlignment','middle',...
	'HorizontalAlignment','left',...
	'FontSize',8)
     end
    title('imaginary part of fourier series cofficients')
     xlabel('k')
     disp('real part of cofficients :');
     disp(real(akd));
     disp('-------------------------------------------')
     disp('imaginary part of cofficients :');
     disp(imag(akd));
 end
if type ==0
    subplot(3,1,2)
    stem(k,abs(ak))
     for xx=1:2*n+1
    text(xx-n-1-.1,0.1,['',num2str(abs(akd(xx)))],...
	'VerticalAlignment','middle',...
	'HorizontalAlignment','left',...
	'FontSize',8)
     end
    title('magnitude of fourier series cofficients')
     xlabel('k')
    subplot(3,1,3)
    stem(k,angle(akd)*360/2/pi)
     for xx=1:2*n+1
    text(xx-n-1-.1,0.1,['',num2str(angle((akd(xx)))*360/2/pi)],...
	'VerticalAlignment','middle',...
	'HorizontalAlignment','left',...
	'FontSize',8)
     end
    title('phase of fourier series cofficients')
     xlabel('k')
     disp('amplitude of cofficients :');
     disp(abs(akd));
     disp('-------------------------------------------')
     disp('angle of cofficients :');
     disp(angle(akd));
end
 shg
 beep
 end   

Contact us