Fourier Series Approximation Matlab HW1:     You are given a finite step function   x(t)=-1, 0<t<4          1, 4<t<8 .           Hand...

50.1K

Verified Solution

Question

Mechanical Engineering

Fourier Series Approximation Matlab HW1:
   

You are given a finite step function  
x(t)=-1, 0         1, 4


         

Hand calculate the FS coefficients of x(t) by assuminghalf- range expansion,  for each case below and modify thecode.


Approximate x(t) by cosine series only (This iseven-half range expansion). Modify the below code and plot theapproximation showing its steps changing by included number of FSterms in the approximation.


Approximate x(t) by sine series only (This is odd-halfrange expansion).. Modify the below code and plot the approximationshowing its steps changing by included number of FS terms in theapproximation.

You are given a code below which belongs to adifferent function, if you run this code it works and you will seeit belongs to ft=1 0Upload to BB learn using the Matlab HW1 link:
A multi page pdf file that shows

The hand calculations of FS coefficients


The original function plotted


The approximated functions plotted for b andc.


A Comment on how FS expansion approximatesdiscontinuities in the function.

MATLAB CODE
_____________________________________________________________________________________________________________________________________________________________________
clear all
close all
% Example MATLAB M-file that plots a Fourier series
% Set up some input values
P = 4; %period = 2P
num_terms = 100; %approximate infinite series with finite number ofterms
% Miscellaneous setup stuff
format compact;  % Gets rid of extra lines in output.Optional.
% Initialize x-axis values from -1.25L to 1.25L. Middle number isstep size. Make
% middle number smaller for smoother plots
t = -4:0.001:4;
x=zeros(length(t),1);   % reseting original half rangeexpanded function array
x(0<=t & t<2)=1;       %forming the original half range expanded function array for thepurpose of plotting only
x(2x(t<0 & -2x(t<-2 & t>-4)=0;
figure     %plotting original half rangeexpanded function
plot(t,x)
axis([-4.5 4.5 -0.5 1.5])
%Starting to approximate f(t)
% Initialize y-axis values.  y = f(t)
f = zeros(size(x'));
% Add a0/2 to series
a0 = 1;
f = f + a0/2;
% Loop num_terms times through Fourier series, accumulating inf.
figure
for n = 1:num_terms
   
 
   
   % Formula for an.
   an = (2/(n*pi))*sin(n*pi/2);
       bn=0;
   
   % Add cosine and sine into f
   f = f + an*cos(n*pi*t/P) +bn*sin(n*pi*t/P);
   
   % Plot intermediate f.  You can commentthese three lines out for faster
   % execution speed.  The function pause(n)will pause for about n
   % seconds.  You can raise or lower forfaster plots.
   plot(t,f);
   set(gca,'FontSize',16);
   title(['Number of terms = ',num2str(n)]);
   grid on;
   if n < 5
       pause(0.15);
   else
       pause(0.1);
   end
   xlabel('even approx');
end;

Answer & Explanation Solved by verified expert
4.0 Ratings (658 Votes)
    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students