Can you give an example of how to do fourier series of any function in MATLAB?

1 件のコメント

Torsten
Torsten 2022 年 11 月 17 日
編集済み: Torsten 2022 年 11 月 17 日
Define a function handle to define the function you want the fourier coefficients of and evaluate the integrals to determine the Fourier coefficients either using "int" if you are confident to get analytic expressions or else "integral" to get numerical approximations. The latter approach will only be applicable to get partial sums of the Fourier series.

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2022 年 11 月 17 日

0 投票

I am in no way certain what you want.
Calculating a numerical transform is straightforward, however calculating a symbolic version of the same function may not be possible because not all integrals have closed-form solutions.
An example of a numerical transform —
Fs = 250;
L = 150;
t = linspace(0, L-1, L)/Fs;
s = sin(2*pi*t*50) .* exp(-(t-0.3).^2 * 50);
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft(s(:).*hann(L), NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(t, s)
grid
xlabel('t')
ylabel('s(t)')
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency')
ylabel('Magnitude')
% syms omega t
% s = sin(2*pi*t*50) * exp(-(t-0.3)^2 * 50)
%
% FTss(omega) = int(s*exp(1j*omega*t), t, -Inf, Inf)
%
% figure
% fplot(FTss, [0 100])
% grid
The numerical transform code should work with any ‘s’ function you care to use with it. Just be certain that the data are regularly (uniformly) sampled. A function (nufft) for non-uniformly sampled data is available as well.
.

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

質問済み:

2022 年 11 月 17 日

編集済み:

2022 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by