Question

A periodic signal, x(t) is shown below. A = 10, T-4 sec. -T Write a MATLAB script to plot the signal, using enough points to

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

MATLAB code is given below in bold letters.

clc;
close all;
clear all;

% define the signal parameters
A = 10;
T = 4;
w0 = 2*pi/T;

% define the symbolic variables
syms n t;

% define the signal
f = -A/T*t+A;

% evaluate the fourier series integral
an1 = 2/T*int(f*cos(n*w0*t),0,T);
bn1 = 2/T*int(f*sin(n*w0*t),0,T);
a0 = 1/T*int(f,0,T);

% obtain C by substituting n in c[n]
nmax = 100;
n = 1:nmax;
a = subs(an1);
b = subs(bn1);


% define the time vector
ts = 1e-1; % ts is sampling the
t = 0:ts:4*T-ts;

% directly plot the signal x(t)
t1 = 0:ts:4-ts;
x1 = -A/T*t1+A;
x = repmat(x1,1,4);

figure;
plot(t,x,'r','linewidth',2);grid on;
xlabel('time');ylabel('x(t)');
ylim([-5 15]);

% Now fourier series reconstruction
N = [5 50 100];

for p = 1:length(N)
for i = 1:length(t)
for k = 1:N(p)   
x(k,i) = a(k)*cos(k*w0*t(i)) + b(k)*sin(k*w0*t(i));
end
y(i) = a0+sum(x(:,i)); % Add DC term

end
figure;
plot(t,y,'color',rand(1,3),'linewidth',2); % Plot results
xlabel('Time (sec)','FontSize',14); grid on;
ylabel('x(t)','FontSize',14);ylim([-5 15]);
STRING = ['Approximation with Number of terms : ',num2str(N(p))];
title(STRING);
end

15 10 16 14 12 10 timeApproximation with Number of terms: 5 10 E.. 10 12 14 16 Time (sec)Approximation with Number of terms 50 10 10 12 14 16 Time (sec)Approximation with Number of terms 100 10E.... 10 12 14 16 Time (sec)

Add a comment
Know the answer?
Add Answer to:
A periodic signal, x(t) is shown below. A = 10, T-4 sec. -T Write a MATLAB script to plot the sig...
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