Need help plotting this

1 view (last 30 days)
Dani German
Dani German on 11 May 2022
Commented: Dani German on 12 May 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

Accepted Answer

Torsten
Torsten on 11 May 2022
Edited: Torsten on 11 May 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)

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!