Need help plotting this

조회 수: 2 (최근 30일)
Mircea Prisada
Mircea Prisada 2022년 5월 11일
댓글: Mircea Prisada 2022년 5월 12일
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

채택된 답변

Torsten
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)
  댓글 수: 1
Mircea Prisada
Mircea Prisada 2022년 5월 12일
Awesome, thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by