Fourier Series Representation of Periodic Functions
조회 수: 9 (최근 30일)
이전 댓글 표시
I have to represent a periodic functon with a fourier series where:
f(t) = 1, 0 <= t < 0.4
-1, 0.4 <=t < 0.5
With a period of 1 and N = 5.
Working off an example I found, I came up with the code below. I know it isn't correct and I'm really uncertain how and where to put the values for f(t). I also don't know if this does the same thing as integral(exp(-j*k*omega_0*t). I appreciate any help I can get.
syms k t T omega_0
N1 = 10;
a_k = piecewise(k == 0, .5, 2 / (k * omega_0 * T) * sin(k * omega_0 * T / 4));
T_val = 1;
phi_k = exp(1i * k * omega_0 * t);
mega_0_val = 2 * pi / T_val;
f_hat = symsum(a_k * phi_k, k, -N1, N1);
f_hat_substituted = subs(f_hat, [T, omega_0], [T_val, omega_0_val]);
t_val = linspace(-1, 1, 1000);
f_hat_evaluated = double(subs(f_hat_substituted, t, t_val));
figure;
plot(t_val, abs(f_hat_evaluated), 'LineWidth', 2);
xlabel('Time (t)');
ylabel('f(t)');
title('Approximated f(t)');
grid on;
axis([-1 1 -0.1 1.1]);
댓글 수: 0
답변 (1개)
Star Strider
2024년 10월 31일
I would write the piecewise call differently —
syms t omega
a_k = piecewise(0 <= t < 0.4, 1, 0.4 <= t < 0.5, -1)
figure
fplot(a_k, [-1 1])
grid
axis('padded')
xlabel('t')
ylabel('a_k')
title('Time Domain Representation')
A_k = int(a_k*exp(-1j*omega*t), t, 0, 0.5)
A_k = simplify(A_k, 500)
figure
fplot(real(A_k),[-1 1]*pi*25, '-b')
hold on
fplot(imag(A_k),[-1 1]*pi*25, '--b')
fplot(abs(A_k),[-1 1]*pi*25, '-r')
hold off
grid
axis('padded')
xlabel('\omega')
ylabel('Magnitude')
title('Fourier Transform')
You likely have a different intent than simply producing a plot of the Fourier transform. However thiis should get you started.
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!