Matlab code for square wave generation from fourier series (symsum fails for upperlimit greater than 1000 in my case)
30 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rishav Raj
am 15 Jan. 2020
Kommentiert: Rishav Raj
am 7 Mär. 2020
function [a0,An,Bn]=mysquare(T,N)
syms t n
w0=2*pi/T;
a0=1/T*(int(1,t,0,T/2));
an=2/T*(int(1*cos(n*w0*t),t,0,T/2));
bn=2/T*(int(1*sin(w0*n*t),t,0,T/2));
An=symsum(an.*cos(n*w0*t),n,1,N);
Bn=symsum(bn.*sin(n*w0*t),n,1,N);
%main script
T=4;
[a0,an,bn]=mysquare(T,10000);
ft=a0+an+bn;
fplot(ft);
This works fine for N<=1000 but for larger values it takes alot of time and no result.
0 Kommentare
Akzeptierte Antwort
Charan Jadigam
am 4 Mär. 2020
Hi,
The function 'symsum' is trying to find a closed form expression as an answer and it is unable to do so.
Instead, as a workaround, use ‘sum’ function to solve the equation. The usage in your example would be,
An=sum(subs(an.*cos(n*w0*t),n,1:10000));
Bn=sum(subs(bn.*sin(n*w0*t),n,1:10000));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!