Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please do you mind looking at the code provided and make some adjustment to answ

ID: 2248089 • Letter: P

Question

please do you mind looking at the code provided and make some adjustment to answer the question below? thanks


Here's the code for generating the Fourier series for the in-class Practice problem 17.2, assuming that T 1 and ft -9 ft = 9; ce = ft/pi; t = -2:4/10000:2; N = input ('Number of harmonics '); fw = zeros (1, length(t)); fN-fN+ft/2 for k=1:N end plot (t,fN) title(li Practice Problem xlabel('Time (sec)) ylabel(I'f(t)']) 17.2, N ', num2 st r (N))) = Try running this program for various values of N. Show me the derived Fourier series expression v(t) for following periodic signal, then modify the code to generate the Fourier series. You can set T 1 and Vm1, and use the same limits as above for the plot. o(t) 2T 3T Turn in just the following: (1) A listing of your Matlab code (2) Plots for N 3,10, and 100 for the above figure (3) Answer the following: What do you observe happening at t kT as the number of harmonic terms N is increased? Look at N-1000. Check the plots for Exercise 1(a) you did above. Do you observe something similar? (Hnt: read p. 764 in your textbook, 6h ed; p. 766. 5th ed.)

Explanation / Answer

Script:

T = 1;
ft = 9;
c0 = ft/pi;
t = -2:4/10000:2;
w0 = 2*pi/T;

%N= input ('Number of Harmonics');

N = 3;

fN = zeros(1,length(t));
fN= fN + ft/2;
for k=1:N
fN = fN - c0/k*sinc(k*w0*t);
end

plot(t,fN);

N= 9;
fN = zeros(1,length(t));
fN= fN + ft/2;
for k=1:N
fN = fN - c0/k*sinc(k*w0*t);
end

plot(t,fN);

N= 10;
fN = zeros(1,length(t));
fN= fN + ft/2;
for k=1:N
fN = fN - c0/k*sinc(k*w0*t);
end

plot(t,fN);

N= 1000;
fN = zeros(1,length(t));
fN= fN + ft/2;
for k=1:N
fN = fN - c0/k*sinc(k*w0*t);
end

plot(t,fN);

N= 9;
fN = zeros(1,length(t));
fN= fN + ft/2;
for k=1:N
fN = fN - c0/k*sinc(k*w0*t);
end

plot(t,fN);

Function:

function [a,b,yfit] = Fseries(x,y,n,scale,sincos)

if nargin<3

error('MATLAB:Fseries:MissingInputs','Required inputs are x, y, and n')
end
checkinputs();

% scale x to [-pi,pi]
if scale
x1 = min(x);
x2 = max(x);
x = pi*(2*(x-x1)/(x2-x1) - 1);
end

% make design matrix
nx = x*(1:n);
if isequal(sincos,'b')
F = [0.5*ones(size(x)),cos(nx),sin(nx)];
elseif isequal(sincos,'c')
F = [0.5*ones(size(x)),cos(nx)];
else
F = sin(nx);
end

% do fit
c = Fy;

% extract coefficients
if isequal(sincos,'b')
a = c(1:n+1);
b = c(n+2:end);
elseif isequal(sincos,'c')
a = c;
b = zeros(n,1);
else
a = zeros(n+1,1);
b = c;
end

% evaluate fit
yfit = F*c;

% transpose yfit back to a row, if y was a row
if xrow
yfit = yfit';
end


function checkinputs
% x & y values
if isnumeric(x) && isvector(x) && isnumeric(y) && isvector(y)
if ~isequal(size(x),size(y))
throwAsCaller(MException('MATLAB:Fseries:UnequalData','x and y must be same size'))
end
% transpose x & y to columns if they are rows
if size(x,2)>1
x = x';
y = y';
xrow = true;
else
xrow = false;
end
% remove anything not finite and real
idx = ~(isfinite(x) & isfinite(y) & isreal(x) & isreal(y));
x(idx) = [];
y(idx) = [];
if isempty(x)
throwAsCaller(MException('MATLAB:Fseries:NoData','x and y contain no real, finite data'))
end
else
throwAsCaller(MException('MATLAB:Fseries:WrongDataType','x and y values must be numeric vectors'))
end
% number of terms
if isscalar(n) && isnumeric(n)
if n<0
throwAsCaller(MException('MATLAB:Fseries:NegativeTerms','Number of terms (n) cannot be negative!'));
end
else
throwAsCaller(MException('MATLAB:Fseries:WrongDataType','n must be a numeric scalar'))
end
% optional scaling argument
if exist('scale','var')
if ~islogical(scale)
throwAsCaller(MException('MATLAB:Fseries:WrongDataType','Scaling parameter must be logical (true/false)'))
end
else
scale = true;
end
% optional type argument
if exist('sincos','var')
if ischar(sincos)
sincos = lower(sincos);
if ismember(sincos,{'s','sin','sine'})
sincos = 's';
elseif ismember(sincos,{'c','cos','cosine'})
sincos = 'c';
else
throwAsCaller(MException('MATLAB:Fseries:WrongFourierType',['Unknown type: ',sincos]))
end
else
throwAsCaller(MException('MATLAB:Fseries:WrongDataType','Type must be string (''sin'' or ''cos'')'))
end
else
sincos = 'b';
end
end

end

Tri_pulse:

T = 1;
Vm = 1;

t = 0 : 1/1e3 : pi*T; % 1 kHz sample freq for 1 s
d = 0 : T : 3*T; % 3 Hz repetition frequency
y = Vm.*pulstran(t,d,'tripuls',2*T,1) - 0.5;

[a,b,c ]=Fseries(t,y,10)