Need help plotting this
Afficher commentaires plus anciens
Hello, I don't know how to plot waves in matlab with fourier function. It should plot like this.

Here is the code
n = 36;
T=20*10^-3;
t=0:T/1000:T;
w=2*pi*1/T;
%f=i(t)
f=@(t)0+100.*(t>1*T/12).*(t<5*T/12)-100.*(t>7*T/12).*(t<11*T/12);
a0 = 2/T*integral(@(t)f(t),0,T);
for i=1:n
%a(i)=an
a(i) = 2/T*integral(@(t)f(t).*cos(w*i*t),0,T);
%b(i)=ab
b(i) = 2/T*integral(@(t)f(t).*sin(w*i*t),0,T); %until here the code works fine
%v(i)=vn
v(i)=atan(a(i)./b(i));
%r(i)=rn
r(i)=(a(i)./(sin(v(i))));
end
in=@(t) (r(1:n).*sin((1:n)*w*t+v(1:n)));
in_eval = arrayfun(in,t);
%plot column trace rn/r1*100
figure(5)
plot(t,in(n(1)),'DisplayName', 'in(1,t)')
hold on
plot(t,in(n(5)),'DisplayName', 'in(5,t)')
hold on
plot(t,in(n(7)),'DisplayName', 'in(7,t)')
xlabel('Time','FontSize',16)
title('3.12','FontSize',16)
The integral part of code is originated from here:

an and bn are matrix indexes
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Vector Fields dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!