Fourier Series Representation of Periodic Functions
23 ビュー (過去 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 日 15:02
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!