plot exponential Fourier series !!
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, my instructor asked me to plot exponential Fourier series as homework, my homework say ( plot exponential Fourier series from -N to N and with amplitude A, the program will plot figure when N = 1 then for N=2 to N = value that user input it ) but I have problem in my code the problem is : when I put the limits of summation from -N to N it doesn't work except if I put step of for loop two, but if I but it one it doesn't work. please look to my code to understand line 13, this is my code :
clear;
clf;
A = input('Enter Ampitude A : ');
M = input('Enter limts of Summation N, where Summation limes -N:N : ');
T0 = 2;
wo = 2*pi/T0;
c0 = 0;
for i = 0:M
N = i;
t = -5:0.01:5;
figure(1)
y = c0*ones(size(t));
for n = -N:2:N, %<<<<<<<<<<<<<<< the problem is here, it can't be ( -N:1:N ) or ( -N:N )
cn = 2/(1j*n*wo);
y = y + A*real(cn*exp(1j*n*wo*t));
end
cla;
P = T0/2;
plot([-5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5],...
[-A -A A A -A -A A A -A -A A A -A -A A A -A -A A A], ':');
hold;
plot(t,y);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Exponential Fourier Series with N = ',...
num2str(N)];
title(ttle);
hold;
pause(0.5);
end
1 commentaire
Neptune16
le 10 Nov 2019
hello. can you please explain what is use for this lines?
y = c0*ones(size(t));
for n = -N:2:N, %<<<<<<<<<<<<<<< the problem is here, it can't be ( -N:1:N ) or ( -N:N )
cn = 2/(1j*n*wo);
y = y + A*real(cn*exp(1j*n*wo*t));
Réponses (3)
Baltam
le 14 Avr 2016
It's because you are dividing by zero. When n = 0 then cn is infinity. Because of that, matlab can't plot your result.
If you do n = -N:2:N you don't have this problem if N is odd.
Try using:
nvec = [-N:-1:-1,1:N];
for n = nvec %<<<<<<<<<<<<<<< the problem is here, it can't be ( -N:1:N ) or ( -N:N )
cn = 2/(1j*n*wo);
y = y + A*real(cn*exp(1j*n*wo*t));
end
in your code. This leaves out the zero-frequency component.
Muhammad Shoaib
le 20 Fév 2023
clear;
clf;
A = input('Enter Ampitude A : ');
M = input('Enter limts of Summation N, where Summation limes -N:N : ');
T0 = 2;
wo = 2*pi/T0;
c0 = 0;
for i = 0:M
N = i;
t = -5:0.01:5;
figure(1)
y = c0*ones(size(t));
for n = -N:2:N, %<<<<<<<<<<<<<<< the problem is here, it can't be ( -N:1:N ) or ( -N:N )
cn = 2/(1j*n*wo);
y = y + A*real(cn*exp(1j*n*wo*t));
end
cla;
P = T0/2;
plot([-5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5],...
[-A -A A A -A -A A A -A -A A A -A -A A A -A -A A A], ':');
hold;
plot(t,y);
xlabel('t (seconds)'); ylabel('y(t)');
ttle = ['Exponential Fourier Series with N = ',...
num2str(N)];
title(ttle);
hold;
pause(0.5);
end
0 commentaires
Aman
le 9 Oct 2023
clear; clf; A = input('Enter Ampitude A : '); M = input('Enter limts of Summation N, where Summation limes -N:N : '); T0 = 2; wo = 2*pi/T0; c0 = 0; for i = 0:M N = i; t = -5:0.01:5; figure(1) y = c0*ones(size(t)); for n = -N:2:N, %<<<<<<<<<<<<<<< the problem is here, it can't be ( -N:1:N ) or ( -N:N ) cn = 2/(1j*n*wo); y = y + A*real(cn*exp(1j*n*wo*t)); end cla; P = T0/2; plot([-5 -4 -4 -3 -3 -2 -2 -1 -1 0 0 1 1 2 2 3 3 4 4 5],... [-A -A A A -A -A A A -A -A A A -A -A A A -A -A A A], ':'); hold; plot(t,y); xlabel('t (seconds)'); ylabel('y(t)'); ttle = ['Exponential Fourier Series with N = ',... num2str(N)]; title(ttle); hold; pause(0.5); end
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!