Clear Filters
Clear Filters

Why does it return 0 value? (Plotting fourier series)

2 views (last 30 days)
clc
clear all
close all
L = 1;
syms x
n = [-4:4];
rectn = rectangularPulse(-1,1,x);
F_rectn = fourier(rectn);
rp1 = real(F_rectn)*cos(2*pi*n*x/L);
ip1 = imag(F_rectn)*sin(2*pi*n*x/L);
F_0 = F_rectn(x==0);
for i = 1:numel(n);
y1 = 1/L*(F_0 + 2*symsum(rp1(i),x,-4,4) - 2*symsum(ip1(i),x,-4,4));
fplot(y1)
end
Dear all, I want to plot function y1 based on variable x in loop of range n in [-4:4], but it returns y1 = 0? Can anyone please help me fix this plot?
  1 Comment
Paul
Paul on 4 Mar 2022
Is there a source for the equations the code is trying to implement?
For sure, one problem is that the computation of F_0 is incorrect.
L = 1;
syms x
n = [-4:4];
rectn = rectangularPulse(-1,1,x);
F_rectn = fourier(rectn);
F_rectn
F_rectn = 
simplify(F_rectn)
ans = 
We see that F_rectn is a function only of w. So what the code probably should try to do is
F_0 = subs(F_rectn,w,0)
but that won't work because it will divide by zero. So either F_0 will have to be hard coded to F_0 = 2, or an alternative code will be needed to compute F_0.
Having said that, it looks like the code has some other issues, like rp1 and ip1 are both functions of w and x, so it's likely that other correctsion will be needed as well.

Sign in to comment.

Answers (1)

Alberto Cuadra Lara
Alberto Cuadra Lara on 3 Mar 2022
Hello Tu,
Check the definition of F_0, it's empty
clc
clear all
close all
L = 1;
syms x
n = [-4:4];
rectn = rectangularPulse(-1,1,x);
F_rectn = fourier(rectn);
rp1 = real(F_rectn)*cos(2*pi*n*x/L);
ip1 = imag(F_rectn)*sin(2*pi*n*x/L);
F_0 = F_rectn(x==0)
F_0 = [ empty sym ]

Community Treasure Hunt

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

Start Hunting!