Need help plotting this
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Torsten
2022-5-11
编辑:Torsten
2022-5-11
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)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!