Homework Help Question & Answers

MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax...

MATLAB

code starts here ---------

clear

T0=2;
w0=2*pi/T0;
f0=1/T0;
Tmax=4;
Nmax=15;

%---

i=1;
for t=-Tmax: .01:Tmax
T(i)=t;
if t>=(T0/2)
while (t>T0/2)
t=t-T0;
end
elseif t<=-(T0/2)
while (t<=-T0/2)
t=t+T0;
end
end
if abs(t)<=(T0/4)
y(i)=1;
else
y(i)=0;
end
i=i+1;
end
plot(T,y),grid, xlabel('Time (sec)'); title('y(t) square wave'); shg
disp('Hit return..');
pause
%---
a0=1/2;
F(1)=0; %dc freq
C(1)=a0;
for n=1:Nmax
a(n)=(2/(n*pi))*sin((n*pi)/2);
b(n)=0;
C(n+1)=sqrt(a(n)^2+b(n)^2);
F(n+1)=n*f0;
end
stem(F,abs,(C)), grid, title(['Line Spectrum: Harmonics = ' num2str(Nmax)]);
xlabel('Freq(Hz)'), ylabel('Cn'), shg
disp('Hit return...');
pause
%---
yest=a0*ones(1,length(T));
for n=1:Nmax
yest=yest+a(n)*cos(2*n*pi*T/T0)+b(n)*sin(2*n*pi*T/T0);
plot(T,y,T,yest),grid,
title(['Nmax = ' num2str(n)]), shg, pause(1)
end
code ends here ------

Modify the program so for the triangle waveform (A-1, T0 2) Triangular Wave 8A Znat 5 COS が形 n=1

Modify the program so for the triangle waveform (A-1, T0 2) Triangular Wave 8A Znat 5 COS が形 n=1
0 0
Add a comment
Answer #1

MATLAB code is given in bold letters.

clc;
close all;
clear all;
T0=2;
w0=2*pi/T0;
f0=1/T0;
Tmax=4;
Nmax=15;
i=1;
a0=0;
F(1)=0;
A = 1; T0 =2;
n = 1:2:15;
a= 8*A./(n*pi).^2;
b=0;
C=sqrt(a.^2+b^2);
F(n+1)=n*f0;
stem([0 n],[a0 abs(C)]), grid, title(['Line Spectrum: Harmonics = ' num2str(Nmax)]);
xlabel('k'), ylabel('Ck')
disp('Hit return...');
pause
%---
t = -4:0.01:4;


for k=1:length(t)
  
x(k) = a0+sum(C.*cos(2*pi*n*t(k)/T0));


end

figure;plot(t,x);xlabel('time');
ylabel('Amplitude');title('x(t)');grid on;
title('Fourier series approximation with N = 15');
ylim([-1.5 1.5]);

Line Spectrum. Harmonics = 15 0.9 0.8F... 0.7 0.6 0.5 0.4 0.3 0.2F..- 0.1 10

Add a comment
Know the answer?
Add Answer to:
MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coin

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
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.