Question 4.8: Represent the ramp function shown in Figure 4.14 in terms of...

Represent the ramp function shown in Figure 4.14 in terms of Fourier series using MATLAB.

Annotation 2022-10-01 232526
The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

The MATLAB code for ramp function is written in the following parts:
Main module DOS4_2 calls MATLAB function ‘quad’. The function ‘quad’ numerically evaluates an integral using Simpson rule.

Function curve2 calculates the constant term a_{0}

Function curve2c calculates the a_{n} coefficients of cosine terms

Function curve2s calculates the b_{n} coefficients of sine terms

The Fourier representation of the ramp function with 15 terms is shown in Figure 4.15

Annotation 2022-10-01 232821

------------------
CODE DOS4_2 RAMP Function
------------------

% Dynamics of Structures by Ashok K. Jain I. I. T. Roorkee
% DOS4_2
% Fourier representation of a periodic force: Ramp function
% Calls: curve2, curve2c and curve2s
% curve2c: cosine constants; curve2s: sine constants
% The program calls function “quad” to integrate and find Fourier constants
% N: total number of terms to be included
% T: period of periodic force
% P: Amplitude of periodic force
%
close all;
clear all;

clc;
P = 10;
T = 2;
fprintf(‘Amplitude of periodic force = %.3g N\n’,P);
fprintf(‘Period of force = %.3g sec\n’,T);
a0 = quad(@(t)curve2(t,T,P),0,T,1e-9);
for N=1:15
for n=1:N
a(n) = quad(@(t)curve2c(t,n,T,P),0,T,1e-9);
b(n) = quad(@(t)curve2s(t,n,T,P),0,T,1e-9);
end
Outp = 0;
x=1;
for t=0:0.05:T*4
c=0;
s=0;
for n=1:N
c=c+a(n)*cos(t*2*pi*n/T);
s=s+b(n)*sin(t*2*pi*n/T);
end
Outp(x)=s+c+a0;
x=x+1;
end
plot(0:0.05:T*4,Outp,’.-’)
pause(1);
end
grid on;

------------------
CODE CURVE2
------------------

% curve2
% Called by: DOS4_2
% Fourier representation of a periodic force: Ramp function
%
function a = curve2(t,T,P)
%
% Ramp function
%
w = 2*pi/T;
for d=1:length(t)
if t(d)<=T
p1(d) = t(d)*P/T;
else

p1(d) = 0;
end
end
a = (1/T)*p1;
end

------------------
CODE CURVE2C
------------------

% curve2c
% Called by: DOS4_2
% Fourier representation of a periodic force: Ramp function
% Computes constants for cosine terms
%
function a = curve2c(t,n,T,P)
w = 2*pi/T;
for d=1:length(t)
if t(d)<=T
p1(d) = t(d)*P/T;
else
p1(d) = 0;
end
end
a = (2/T)*p1.*cos(w*t*n);
end

------------------
CODE CURVE2S
------------------

% curve2s
% Called by: DOS4_2
% Fourier representation of a periodic force: Ramp function
% Computes constants for sine terms
%
function b = curve2s(t,n,T,P)
w = 2*pi/T;
for d=1:length(t)
if t(d)<=T
p1(d) = t(d)*P/T;
else
p1(d) = 0;
end
end
b = (2/T)*p1.*sin(w*t*n);
end

Related Answered Questions

Question: 4.7

Verified Answer:

The MATLAB code is written in the following parts:...
Question: 4.3

Verified Answer:

The Fourier pair is given by Equation (4.9): [late...
Question: 4.2

Verified Answer:

The steady state response of an undamped SDOF subj...
Question: 4.1

Verified Answer:

The square pulse is having a period of T_{p...