Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can I build Fourier series of a periodic rectangle pulse group with Matlab 6.5?

Status
Not open for further replies.

turkerweb

Junior Member level 2
Joined
Oct 13, 2005
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
izmir
Activity points
1,600
can anybody help me?

How can i build fourier series of a periodic rectangle puls group with Matlab 6.5?

for example like this...
fourier6na.jpg


what must be Matlab codes of this problem?

pls help..:cry:
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
fourier series coefficients matlab

ezplot('sin(x) + sin(3*x)/3');

ezplot('sin(x) + sin(3*x)/3 + sin(5*x)/5 + sin(7*x)/7 + sin(9*x)/9');

ezplot('sum(sin([1:2:33] .* x) ./ [1:2:33])');
 

palosian

Junior Member level 1
Joined
Nov 30, 2005
Messages
16
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,403
fourier matlab

i have te matlab codes and i can it to if you need it
 

turkerweb

Junior Member level 2
Joined
Oct 13, 2005
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
izmir
Activity points
1,600
matlab code for fourier series

dear friends;

i have this codes but when i put this to Matlab ,i have take no result? :( i cant find where i do mistake:((( can u help me?

%Rectanqual wave signs with fourier series
%
fig_size = [232 84 774 624];
T0 = 8;
w0 = 2*pi/8;
t = linspace(-8,16,1001);
a0 = 0.25;
n = 1:50;
an = (1./(pi*n)) .* sin(n*pi/2);
bn = (1./(pi*n)) .* (1 - cos(n*pi/2));
x1 = a0;
for i = 1:10
x1 = x1 + an(i)*cos(i*w0*t) + bn(i)*sin(i*w0*t);
end
x2 = x1;
for i = 11:30
x2 = x2 + an(i)*cos(i*w0*t) + bn(i)*sin(i*w0*t);
end
x3 = x2;
for i = 31:50
x3 = x3 + an(i)*cos(i*w0*t) + bn(i)*sin(i*w0*t);
end
A0 = a0;
An = sqrt(an.^2 + bn.^2);
thn = atan2(-bn,an)*180/pi;
X0 = A0;
Xn = An/2;
figure(1),clf,plot([-8 -6],[1 1],'b-',[-6 -6],[1 0],'b--',[-6 0],[0 0],'b-',[0 2],[1 1],'b-',[2 8],[0 0],'b-',...
[8 10],[1 1],'b-',[10 16],[0 0],'b-',[0 0],[0 1],'b--',[2 2],[1 0],'b--',[8 8],[0 1],'b--',...
[10 10],[1 0],'b--',[16 16],[0 1],'b--'),...
axis([-8 16 -.5 1.5]),plotax,xlabel('Time (s)'),ylabel('Amplitude'),title('Periodic Pulse Train x(t)'),...
set(gcf,'Position',fig_size),text(5,-0.2,'T_0 = 8 s'),text(5,-0.3,'Pulse width = T_0/4')
figure(2),clf,subplot(311),plot(t,x1),subplot(312),plot(t,x2),subplot(313),plot(t,x3),...
subplot(311),ylabel('Amplitude'),title('Fourier Series Representation of x(t) with 10 Terms'),...
subplot(312),ylabel('Amplitude'),title('Fourier Series Representation of x(t) with 30 Terms'),...
subplot(313),ylabel('Amplitude'),title('Fourier Series Representation of x(t) with 50 Terms'),xlabel('Time (s)'),...
for i = 1:3,subplot(3,1,i),...
hold on,plot([0 2],[1 1],'r-',[2 8],[0 0],'r-',[8 10],[1 1],'r-',[10 16],[0 0],'r-',...
[0 0],[0 1],'r--',[2 2],[1 0],'r--',[8 8],[0 1],'r--',[10 10],[1 0],'r--',[16 16],[0 1],'r--',...
[-8 -6],[1 1],'r-',[-6 -6],[1 0],'r--',[-6 0],[0 0],'r-'),hold off,...
axis([-8 16 -0.5 1.5]),plotax
end
set(gcf,'Position',fig_size)
figure(3),clf,subplot(211),plot(0,a0,'ro',n,an,'o'),axis([-5 50 -0.2 0.5]),plotax,...
hold on,plot([10.5 10.5],[-0.2 0.5],'r--',[30.5 30.5],[-0.2 0.5],'r--'),hold off,...
xlabel('Harmonic Number'),ylabel('Amplitude'),title('Trig Fourier Series Coefficients a_n for x(t)'),...
subplot(212),plot(n,bn,'o'),axis([-5 50 -0.05 0.35]),plotax,...
hold on,plot([10.5 10.5],[-0.05 0.35],'r--',[30.5 30.5],[-0.05 0.35],'r--'),hold off,...
xlabel('Harmonic Number'),ylabel('Amplitude'),title('Trig Fourier Series Coefficients b_n for x(t)'),...
set(gcf,'Position',fig_size)
figure(4),clf,subplot(211),plot(0,A0,'ro',n*w0,An,'o'),axis([-2*w0 16 -0.1 0.5]),plotax,...
xlabel('Frequency (r/s)'),ylabel('Magnitde'),title('Cosine Fourier Series Magnitudes A_n for x(t)'),...
subplot(212),plot(n*w0,thn,'o'),v=axis;axis([-2*w0 16 -200 10]),plotax,...
xlabel('Frequency (r/s)'),ylabel('Phase (deg)'),title('Cosine Fourier Series Phases Theta_n for x(t)'),...
set(gcf,'Position',fig_size)
figure(5),clf,subplot(211),plot(0,X0,'ro',n*w0,Xn,'o',-n*w0,Xn,'o'),axis([-16 16 -0.1 0.3]),plotax,...
xlabel('Frequency (r/s)'),ylabel('Magnitde'),title('Exponential Fourier Series Magnitudes X_n for x(t)'),...
subplot(212),plot(n*w0,thn,'o',-n*w0,-thn,'o'),v=axis;axis([-16 16 v(3:4)]),plotax,...
xlabel('Frequency (r/s)'),ylabel('Phase (deg)'),title('Exponential Fourier Series Phases Theta_n for x(t)'),...
set(gcf,'Position',fig_size)
clear i v
%
% ÖDEV BİTTİ *****

Added after 3 minutes:

echo47 said:
ezplot('sin(x) + sin(3*x)/3');

ezplot('sin(x) + sin(3*x)/3 + sin(5*x)/5 + sin(7*x)/7 + sin(9*x)/9');

ezplot('sum(sin([1:2:33] .* x) ./ [1:2:33])');

u re super thnks and but i must show harmonic numbers of this series...i had written a code above but later i cant understand why i cant take result?can u check it pls...
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
fourier series in matlab

What is "plotax"? My MATLAB 7.0.1 complains, and I don't see it in the online help.
If I delete it, your code outputs several plots.
 

turkerweb

Junior Member level 2
Joined
Oct 13, 2005
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
izmir
Activity points
1,600
plot exponential matlab

echo47 said:
What is "plotax"? My MATLAB 7.0.1 complains, and I don't see it in the online help.
If I delete it, your code outputs several plots.

no...that code came from a university teacher..my matlab 6.5 and so i cant use that codes,i couldnt understand problem..u say problem that at """plotax""",,,thnks but i dont know what it used for there,i hadnt no idea so i wanted help from you...

and now ,i suppose we found what is fault..and so whats the true code do i write ...withouth using plotax...

thnks , especially to echo47
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
637
Reputation
1,272
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
fourier series matlab

When I delete the "plotax" words, your MATLAB code runs successfully, although it outputs some plots that I don't understand. Have you tried doing that?
 

turkerweb

Junior Member level 2
Joined
Oct 13, 2005
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
izmir
Activity points
1,600
fourier matlab code

echo47 said:
When I delete the "plotax" words, your MATLAB code runs successfully, although it outputs some plots that I don't understand. Have you tried doing that?

Yes,i tried like that,its succesfull..u re right ,my friend..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top