Question

Consider the function -1.0<xso x, (a) Find the Fourier series of the function f(x (b) Use any graphing software to plot the f

0 0
Add a comment Improve this question Transcribed image text
Answer #1


%Matlab code for Fourier Series clear all close all %All x-linspace (-1,3,3001); %Loop for creating the function for i= 1:lenlgnd(1Actual data; %plotting Fourier series of the function xlabel(time) ylabel (f(t) title(Fourier series of given functiFourier series of given function 3.5 Actual data tourier term-1 3 fourier term-2 fourier term-3 fourier term. fourier term-10

%Matlab code for Fourier Series
clear all
close all
%All time values
x=linspace(-1,3,3001);
%Loop for creating the function
for i=1:length(x)
    if x(i)>-1 && x(i)<=0
        zz(i)=x(i);
    elseif x(i)>0 && x(i)<=2
        zz(i)=2+2.*x(i)-(x(i)).^2;
    else
        zz(i)=2;
    end
end
%Plotting the function
hold on
plot(x,zz,'Linewidth',4)

a1=x(1); b1=x(end);
l=(b1-a1)/2;
%Fourier series of the function for finding a and b coefficients
fprintf('First 10 terms of Fourier series\n')
for j=1:50
    ss1=zz.*cos(j*pi*x/l);
    %all a values of the Fourier series
    aa(j)=(1/l)*trapz(x,ss1);
    ss2=zz.*sin(j*pi*x/l);
    %all b values of the Fourier series
    bb(j)=(1/l)*trapz(x,ss2);
    if j<=10
        fprintf('\tFourier term a(%d) is %f\n',j,aa(j))
        fprintf('\tFourier term b(%d) is %f\n\n',j,bb(j))
    end
end

N=[1 2 3 5 10 20 50];
%a0 value of Fourier series
aa0=(1/l)*trapz(x,zz);
s=aa0/2; k=1;
%Fourier series of the function
for i=1:50
  
    s=s+bb(i)*sin(i*pi*x/l)+aa(i)*cos(i*pi*x/l);
  
    if i==N(k)
      
        k=k+1;
        plot(x,s)
        lgnd{k}=sprintf('fourier term=%d',i);
      
    end
      

end
lgnd{1}='Actual data';
%Plotting Fourier series of the function
xlabel('time')
ylabel('f(t)')
title('Fourier series of given function')
legend(lgnd,'Location','northwest')
  
%%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%
   

Add a comment
Know the answer?
Add Answer to:
Consider the function -1.0
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