フィルターのクリア

Why dosent my fourier output simulate the input?

1 回表示 (過去 30 日間)
Jamie  Chambers
Jamie Chambers 2017 年 2 月 18 日
コメント済み: Jamie Chambers 2017 年 2 月 20 日
This is my input signal:
clc
clear all
syms L psi f(x) t
L=2*pi;
psi=pi;
f(x)=(t-psi)^2;
ezplot(f(x),[0,2*pi])
xlabel ('period 0,2*pi')
ylabel ('amplitude')
title ('input signal')
pretty(f(x))
I'm trying to plot the Fourier using this code:
clc
clear all
syms n m L t psi x
L=2*pi;
psi=pi
f(x)=(t-psi)^2
A0=int(f(x),t,0,2*pi)/L
ezplot(A0,[0,2*pi])
hold on
for m=1:10
An=int(f(x)*cos(n*t),t,0,L)*(L/1);
An=subs(An,n,m);
Bn=int(f(x)*sin(n*t),t,0,L)*(L/1);
Bn=subs(Bn,n,m);
Fo=A0+sum((An*cos(n*pi)/L)*f(x)+(Bn*sin(n*pi)/L)*f(x))
Fo=subs(Fo,n,m);
ezplot(Fo,[0,2*pi])
ylim auto
hold on
end
I've tried numerous attempts but cant seen to generate the simulated input???? what a I doing wrong? Regards J
  1 件のコメント
John BG
John BG 2017 年 2 月 18 日
do you have the symbolic toolbox?

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

採用された回答

Frank Macias-Escriva
Frank Macias-Escriva 2017 年 2 月 19 日
Try this code bellow:
syms t n;
L = 2*pi;
f(t) = (t-pi)^2;
figure('Name', 'Original signal');
ezplot(f(t), [0, L]);
ylim auto;
N = 100;
A0 = int(f(t), t, 0, L)/L;
A(n) = int(f(t)*cos(n*t), t, 0, L) * (2/L);
B(n) = int(f(t)*sin(n*t), t, 0, L) * (2/L);
Fo(t) = A0 + symsum(A(n)*cos(n*t) + B(n)*sin(n*t), n, 1, N);
figure('Name', 'Generated signal');
ezplot(Fo(t), [0, L]);
ylim auto;
In this code, you avoid using for loops and keep using the symbolic toolbox for the entire solution. Also, note te use of "symsum" instead of "sum". Play with N for getting different accuracies of the generated signal.
Best,
fm
  1 件のコメント
Jamie  Chambers
Jamie Chambers 2017 年 2 月 20 日
I owe you a beer sir! thank you and regards Jamie :D

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by