Need help plotting this

1 visualización (últimos 30 días)
Dani German
Dani German el 11 de Mayo de 2022
Comentada: Dani German el 12 de Mayo de 2022
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

Respuesta aceptada

Torsten
Torsten el 11 de Mayo de 2022
Editada: Torsten el 11 de Mayo de 2022
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
end
%v(i)=vn
v=atan(a./b);
%r(i)=rn
r=a./sin(v);
in=@(n,t) r(n)*sin(n*w*t+v(n));
%plot column trace rn/r1*100
figure(5)
plot(t,in(1,t),'DisplayName', 'in(1,t)')
hold on
plot(t,in(5,t),'DisplayName', 'in(5,t)')
hold on
plot(t,in(7,t),'DisplayName', 'in(7,t)')
xlabel('Time','FontSize',16)
title('3.12','FontSize',16)
  1 comentario
Dani German
Dani German el 12 de Mayo de 2022
Awesome, thanks for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Vector Fields en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by