PROBLEM WITH THE PLOT OF FOURIER SERIES

4 vues (au cours des 30 derniers jours)
Daniel Beno
Daniel Beno le 25 Avr 2022
Réponse apportée : Yash le 4 Oct 2023
Hii everyone I have a small problem with the series,
the plot i am doind is not right this should be a plot at a height of 2 and I dont know why this is not what i get
this is what i want to plot when N=100 :
and this is what i get
this is my code :
clc;clear;close all;
syms t k
%D%
T=4; % Period Time
%D%
XT=[1,t,0]
ck=@(x,A,B)(1/T)*int((x*exp(2*pi*k*1i*t/-4)),t,[A,B])
ck1=ck(XT(1),0,1)
ck2=ck(XT(2),1,2)
ck3=ck(XT(3),2,4)
cktotal=ck1+ck2+ck3
%D.1%
NAGATIVESIDE5=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,-5,-1)
POSATIVESIDE5=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,+1,+5)
ALLBUTNOTZERO5=NAGATIVESIDE5+POSATIVESIDE5
%D.2%
NAGATIVESIDE10=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,-10,-1)
POSATIVESIDE10=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,1,10)
ALLBUTNOTZERO10=NAGATIVESIDE10+POSATIVESIDE10
%D.3%
NAGATIVESIDE100=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,-100,-1)
POSATIVESIDE100=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,1,100)
ALLBUTNOTZERO100=NAGATIVESIDE100+POSATIVESIDE100
%plots%
fplot(ALLBUTNOTZERO5,[-10 10],"r")
ylabel("fourier approximation N=-5-->5")
xlabel("time")
grid on
ylim([0 2])
fplot(ALLBUTNOTZERO10,[-10 10],"g")
ylabel("fourier approximation N=-10-->10")
xlabel("time")
grid on
ylim([0 2])
fplot(ALLBUTNOTZERO100,[-10 10],"b")
ylabel("fourier approximation N=-100-->100")
xlabel("time")
grid on
ylim([0 2])

Réponses (1)

Yash
Yash le 4 Oct 2023
Hi Daniel,
I understand that you are facing issues while calculating the Complex Fourier Series of the given piecewise function.
Upon reviewing your code, I have discovered that all the coefficients calculated by you are correct. However, you have not considered the coefficient for "k" equal to zero. You might have encountered a "Division by zero" error while substituting zero in the function for "ck". To overcome this issue, you can calculate the coefficient "c0" separately as follows:
c0 = (1/(2*L))*(int(XT(1),0,1)+int(XT(2),1,2)+ int(XT(3),2,4))
After calculating the coefficient "c0", you need to include it in your function calculation as shown below:
ALLBUTNOTZERO5=c0+NAGATIVESIDE5+POSATIVESIDE5;
By making these adjustments, the peak value should reach the desired value. You can refer to the obtained plot for N=100 below:
I hope this addresses your query.
Best Regards
Yash

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by