Advertisement
aprsc7

Half sine wave fourier

Nov 2nd, 2020 (edited)
1,982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.84 KB | None | 0 0
  1. % Program to give partial complex exponential Fourier sums of
  2. % a half rectified sine wave of unit amplitude in table 2-1
  3. clear
  4. clc
  5. k_max = input('Enter>>');
  6. num_kmax = length(k_max);
  7. for z = 1:num_kmax
  8.     k = [-k_max(z):k_max(z)];
  9.     L_k = length(k);
  10.     a_k = zeros(1, L_k); % Form vector of Fourierseries coefficients,
  11.    
  12.     a_k((L_k+1)/2+1) = -0.25*j; % all odd-terms are zero except A(1)
  13.     a_k((L_k+1)/2-1) = 0.25*j; % and A(-1) so define coefficient array
  14.    
  15.     for i=1:2:L_k % as a zero array and then
  16.         a_k(i)=1/(pi*(1-k(i)^2)); % fill in nonzero values
  17.     end;
  18.    
  19.     omega_0 = 2*pi;
  20.     t = 0:.005:3;
  21.     x = a_k*exp(j*omega_0*k'*t);
  22.    
  23.     subplot(num_kmax,1,z),plot(t,real(x)), ylabel('partialsum'),...
  24.     axis([0 3 -0.5 1.2]), text(.05,-.25,['max. har. =',num2str(k_max(z))]),...
  25.     text(2.0,-.25,['Name / Matric No']),
  26. end;
  27. xlabel('t');
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement