필터 지우기
필터 지우기

I need help with fourier matrix index integral, I can't find how to write it in matlab

조회 수: 2 (최근 30일)
I don't know how to type this into matlab. Fourier function with matrix index
Here is my mathcad code and I'm trying to learn how to write it in matlab:
The first part of my matlab code is i which corresponds with i(t) from mathcad photo. I can't find how to write the integral with matrice index.
%%
%current i(t)
T=20*10^-3;
t=0:T/1000:T;
w=2*pi*1/T;
i=100.*(t>1*T/12).*(t<5*T/12)-100.*(t>7*T/12).*(t<11*T/12);
u=sin(w*t).*10.*(t>0).*(t<T);
%plot i
figure(1)
plot(t,i, 'DisplayName', 'i(t)')
hold on
legend
xlabel('Time','FontSize',16)
title('3.20','FontSize',16)
%until here the code is working
%a0, an, ab
n = linspace(0, 50);
T=20*10^-3;
t=0:T/1000:T;
w=2*pi*1/T;
a0 = @(i,T) integral(@(t) 2./T.*i, 0, T);
an = @(i,T) integral(@(t) 2./T.*i.*cos(n*w*t), 0, T);
ab = @(i,T) integral(@(t) 2./T.*i.*sin(n*w*t), 0, T);
F=sum(an.*cos(n*w*t).+bn.*sin(n*w*t)
fourier=(a0/2)+F
%plot fourier + current
figure(2)
plot(t,i+fourier, 'DisplayName', 'fourier')
hold on
legend
xlabel('Time','FontSize',16)
title('3.20','FontSize',16)
It should plot like this:
Any help is appreciated thanks.

채택된 답변

Torsten
Torsten 2022년 5월 8일
편집: Torsten 2022년 5월 8일
n = 50;
T=20*10^-3;
t=0:T/1000:T;
w=2*pi*1/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) = 2/T*integral(@(t)f(t).*cos(w*i*t),0,T);
b(i) = 2/T*integral(@(t)f(t).*sin(w*i*t),0,T);
end
four = @(t) a0/2+sum((a(1:n).*cos((1:n)*w*t)+b(1:n).*sin((1:n)*w*t)));
four_eval = arrayfun(four,t)
plot(t,f(t))
hold on
plot(t,four_eval)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by