Question



Exercise 5. Let f(t) denote the 2-periodic function f(t) = 1+2 - <t< . a) Make a representative plot of f(t) showing at least
0 0
Add a comment Improve this question Transcribed image text
Answer #1


%Matlab code for Fourier Series clear all close all All time values t=linspace(-pi,pi, 1001); function value zz=1./(1+t. 2); elseif i==20 plot(t,s) lgnd{5}=sprintf(Fourier sum for $d terms, i); elseif i==50 plot(t,s) lgnd{6}=sprintf(Fourier sum foPlotting of Actual data and Fourier sum - Actual plot Fourier sum for 3 terms Fourier sum for 5 terms Fourier sum for 7 terms

%Matlab code for Fourier Series
clear all
close all
%All time values
t=linspace(-pi,pi,1001);
%function value
zz=1./(1+t.^2);

figure(1)
%Plotting the function
plot(t,zz,'Linewidth',2)
xlabel('t')
ylabel('f(t)')
title('Plotting of Actual data and Fourier sum')
a1=t(1); b1=t(end);
l=(b1-a1)/2;
%Fourier series of the function for finding a and b coefficients
for j=1:50
    ss1=zz.*cos(j*pi*t/l);
    %all a values of the Fourier series
    aa(j)=(1/l)*trapz(t,ss1);
    ss2=zz.*sin(j*pi*t/l);
    %all b values of the Fourier series
    bb(j)=(1/l)*trapz(t,ss2);
end

%a0 value of Fourier series
aa0=(1/l)*trapz(t,zz);
t=linspace(-3.*pi,3.*pi,6001);
s=aa0/2;
fprintf('Yes this function is continuous and differentiable.\n\n')
%all an and bn terms
fprintf('Printing few terms for Fourier series\n')
for i=1:10
    fprintf('\tThe value of a%d=%f and b%d=%f. \n\n',i,aa(i),i,bb(i))
end
lgnd{1}='Actual plot';
%Fourier series of the function
hold on
for i=1:50
  
    s=s+bb(i)*sin(i*pi*t/l)+aa(i)*cos(i*pi*t/l);
    if i==3
        plot(t,s)
        lgnd{2}=sprintf('Fourier sum for %d terms',i);
    elseif i==5
        plot(t,s)
        lgnd{3}=sprintf('Fourier sum for %d terms',i);
    elseif i==7
        plot(t,s)
        lgnd{4}=sprintf('Fourier sum for %d terms',i);
      
    elseif i==20
        plot(t,s)
        lgnd{5}=sprintf('Fourier sum for %d terms',i);
      
    elseif i==50
        plot(t,s)
        lgnd{6}=sprintf('Fourier sum for %d terms',i);
      
    end
end
legend(lgnd,'Location','northwest')

figure(2)
plot(aa)
xlabel('count')
ylabel('a_k amplitude')
title('a_k plot')
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%
   

Add a comment
Know the answer?
Add Answer to:
Exercise 5. Let f(t) denote the 2-periodic function f(t) = 1+2 - <t< . a) Make...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT