Azzera filtri
Azzera filtri

Fourier Series of a Squarewave

2 visualizzazioni (ultimi 30 giorni)
Salik Mallick
Salik Mallick il 29 Set 2020
Modificato: Ameer Hamza il 29 Set 2020
Why is this script not running for a Fourier Series of a Squarewave?
T=2
ao=1/2
an=0
bn= (-1/n*pi)*[ (-1)^n - 1 ])
%% Problem 1_Practice_Problem_17.1
display('Problem 1_Practice_Problem_17.1')
N = 10000;
Wo = pi;
t = -1:.001:11;
f = zeros(1,length(t));
for n = 1:2*n:N
an = [1-[(-1)^n]/n*pi;
f=f + an*cos(Wo*n*t);
end
% Plotting and plot formatting is done here
plot(t,f)
axis([-1 11 -1.1 1.1])
title(['Fourier Series Representation w/ ' num2str(N) ' Terms'],'FontSize',16)
xlabel('Time')
ylabel('Function Value')

Risposta accettata

Ameer Hamza
Ameer Hamza il 29 Set 2020
Modificato: Ameer Hamza il 29 Set 2020
Check this code
ao=1/2;
an=0;
%% Problem 1_Practice_Problem_17.1
disp('Problem 1_Practice_Problem_17.1')
N = 10000;
Wo = pi;
t = -1:.001:11;
f = zeros(1,length(t));
for n = 1:2:N
bn = (1-(-1)^n)./(n*pi);
f = f + an*cos(Wo*n*t) + bn*sin(Wo*n*t);
end
% Plotting and plot formatting is done here
plot(t,f)
axis([-1 11 -1.1 1.1])
title(['Fourier Series Representation w/ ' num2str(N) ' Terms'],'FontSize',16)
xlabel('Time')
ylabel('Function Value')

Più risposte (0)

Categorie

Scopri di più su Visual Exploration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by