
Fourier series visualization Given x(t) in the figure below. Find the Fourier series for x(t). Write a Matlab script to plot three periods of the approximation obtained by truncating the Fourier series to N=1,N=5, and N=11 : x(t)=∑k=−NNakejkω0t. To help with the Matlab coding, a code example for the square wave considered in lecture is given below; this example creates one of three subplots in a 1-by-3 array. Note that you'll potentially need to make adjustments to the following lines of code: 2,5,6,11,13 j=sqrt(−1);% imaginary unit T=4;% period (seconds) t=[0:0.001:3∗ T];% time samples across three periods w0 =2∗pi/T;% fundamental frequency ( rad/sec ) N=11;% number of harmonics a0=0.5;% DC coefficient x=a0∗ ones (size(t));% start with DC approximation to x(t) % Now add in harmonics with proper amplitude and phase; % here I use the cosine series form, for convenience. for k=1:N% loop over n, adding nth harmonic ak=sin(pi∗k/2)/(pi∗k); x=x+2∗abs(ak)∗cos(w0∗k∗t+angle(ak));% add nth cosine end subplot (1,3,3);plot(t,x);% Change third entry of "subplot" command % to plot result: 1 row, 3 columns, 1st, 2nd, or 3rd plot grid;temp=sprintf ('Fourier Series Approximation, N=%i ', N ); title (temp); xlabel ('time (seconds)'); ylabel ('amplitude') axis([0max(t)−0.51.5])% limit axes to my liking