Sunteți pe pagina 1din 32

SIGNAL AND SYSTEM

FOURIER SERIES

By:
Andik Kurniawan S (02311740000061)

Lecturer :
Dr. Dhany Arifianto, ST., M.Eng

DEPARTMENT OF ENGINEERING PHYSICS


INDUSTRIAL TECHNOLOGY OF FACULTY
INSTITUT TECHNOLOGY OF SEPULUH NOPEMBER
SURABAYA
2019
Praktikum III
Kuliah Pemrosesan Sinyal
Praktikum IV pemrosesan sinyal akan membahas Deret Fourier.

Tujuan : - Memahami penerapan Deret Fourier


- Memahami dampak Fenomenon Gibb

Peralatan : laptop/PC dengan matlab dan DSP toolbox.

Percobaan 4.1

Prosedur :
1. Double-click Matlab/scilab
2. Buka text editor matlab (icon persegi putih, sisi kiri) atau menggunakan
sembarang text editor, seperti notepad, wordpad dll.
3. Ketik command line dibawah ini

%Fenomenon Gibb
t=linspace(-2,2,2000);
u=linspace(-2,2,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
k=2;
N=[1,3,7,19,49,70];
for n=1:6;
an=[];
for m=1:N(n)
an=[an,2*k*sin(m*pi/2)/(m*pi)];
end;
fN=k/2;
for m=1:N(n)
fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
subplot(3,2,n),plot(u,sq,'r','LineWidth',2);hold on;
plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5
2.5]);grid;
xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);
end;

4. Save dengan nama gibb.m; letakkan pada direktori dimana matlab


dieksekusi (lihat “current folder”). Lalu run. Apa yang anda amati ?
From the graphic we know that the higher value of n,
the effect of the gibb phenomenon is that the wave is
more minimalist compared to the small value of n, the
results of the graph above show that when the value of
n = 70 has a minimum wave less than the value of n =
1,3,7,19,49. In accordance with the theory of the
phenomenon of gibb that to reduce wave by increasing
iteration.

5. Lakukan perubahan pada N=[1,3,7,19,49,70]; Apa yang terjadi ?


Jelaskan mengapa !

%Fenomenon Gibb
t=linspace(-2,2,2000);
u=linspace(-2,2,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
k=2;
N=[4,8,16,32,64,128];
for n=1:6;
an=[];
for m=1:N(n)
an=[an,2*k*sin(m*pi/2)/(m*pi)];
end;
fN=k/2;
for m=1:N(n)
fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
subplot(3,2,n),plot(u,sq,'r','LineWidth',2);hold on;
plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5
2.5]);grid;
xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);
end;
At the value of n = 128 the value of the ripple effect
due to the phenomenon of gibb which occurs more
minimalist and almost perfectly forms a step signal with
amplitude 2. Which the results of this graph show that
the greater the value of N, iteration, the effects of the
gibb phenomenon, the wave effect more minimalist.

6. Dengan variabel N menyesuaikan (lihat langkah no.5), perpendek dan


perpanjang lebar kotak pada variabel sq. Apa yang anda amati ?

%Fenomenon Gibb
t=linspace(-2,2,2000);
u=linspace(-1,1,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
k=2;
N=[4,8,16,32,64,128];
for n=1:6;
an=[];
for m=1:N(n)
an=[an,2*k*sin(m*pi/2)/(m*pi)];
end;
fN=k/2;
for m=1:N(n)
fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
subplot(3,2,n),plot(u,sq,'r','LineWidth',2);hold on;
plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5
2.5]);grid;
xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);
end;
%Fenomenon Gibb
t=linspace(-2,2,2000);
u=linspace(-5,5,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
k=2;
N=[4,8,16,32,64,128];
for n=1:6;
an=[];
for m=1:N(n)
an=[an,2*k*sin(m*pi/2)/(m*pi)];
end;
fN=k/2;
for m=1:N(n)
fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
subplot(3,2,n),plot(u,sq,'r','LineWidth',2);hold on;
plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5
2.5]);grid;
xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);
end;
When the amplitude of the step signal does not change,
only the range of the step signal changes, so the
resulting sinusoidal signal also does not change, the
fourier series that occurs in the step signal with the
same amplitude, but different spans are the same. So,
With a greater N value, the gibb phenomenon that produces
wave is more minimalist.
Percobaan 4.2
Prosedur :
1. Double-click Matlab/scilab
2. Buka text editor matlab (icon persegi putih, sisi kiri) atau menggunakan
sembarang text editor, seperti notepad, wordpad dll.
3. Ketik command line dibawah ini
% *** Plot truncatated FS for various numbers of terms. ***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 2; wo = 2*pi/To; % fundamental period and frequency
D0 = 0.5; % signal offset
t = -2:0.01:4; % time over which we'll plot signal
N = [1 5 10 50]; % +/- values at which we'll truncate FS
for i = 1:4, % compute truncated FS for above N values
f = D0*ones(size(t)); % start out with DC bias term
for n = -N(i):-1, % loop over negative n
Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

subplot(2,2,i); % plot truncated FS representation of f(t)


plot(t,f); % and actual signal
hold on;
plot([-2 -1 -1 0 0 1 1 2 2 3 3 4 4],[1 1 0 0 1 1 0 0 1 1 0 0 1],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);
end;

% *** Plot exponential magnitude and phase spectra for 1st 4


harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2
To = 2; wo = 2*pi/To; % fundamental period and frequency
D0 = 0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn and w

for n = -4:-1, % loop over negative n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store fouriercoef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of f(t)


stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four Harmonics');

4. Apa yang anda amati ?


5. Mengapa perlu off-set ?
If off-set = 0, so
% *** Plot truncatated FS for various numbers of terms. ***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 2; wo = 2*pi/To; % fundamental period and frequency
D0 = 0; % signal offset
t = -2:0.01:4; % time over which we'll plot signal
N = [1 5 10 50]; % +/- values at which we'll truncate FS
for i = 1:4, % compute truncated FS for above N values
f = D0*ones(size(t)); % start out with DC bias term
for n = -N(i):-1, % loop over negative n
Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

subplot(2,2,i); % plot truncated FS representation of f(t)


plot(t,f); % and actual signal
hold on;
plot([-2 -1 -1 0 0 1 1 2 2 3 3 4 4],[1 1 0 0 1 1 0 0 1 1 0 0 1],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);
end;

% *** Plot exponential magnitude and phase spectra for 1st 4


harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2
To = 2; wo = 2*pi/To; % fundamental period and frequency
D0 = 0; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn and w

for n = -4:-1, % loop over negative n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store fouriercoef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of f(t)


stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four Harmonics');

From the graph that has been generated by using a


signal offset of 0.5, the results of the fourier
series signal in the form of signals begin at f (t)
= 0.5 when using a signal offset value of 0, the
results of the fourier series signal in the form of
signals starts at f (t) = 0 also affects the results
of the magnitude spectrum of the First Four
Harmonics. So, Signal offset functions as the
initial value for the Fourier Series signal from the
step signal which also affects the magnitude and
phase spectrum.

6. Ubah parameter n lebih besar dan lebih kecil. Apa yang anda peroleh ?

% *** Plot truncatated FS for various numbers of terms.


***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 2; wo = 2*pi/To; % fundamental period and
frequency
D0 = 0.5; % signal offset
t = -2:0.01:4; % time over which we'll plot
signal
N = [1 2 3 4]; % +/- values at which we'll truncate
FS
for i = 1:4, % compute truncated FS for above
N values
f = D0*ones(size(t)); % start out with DC bias term
for n = -N(i):-1, % loop over
negative n
Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS
terms
end;

for n = 1:N(i), % loop over


positive n
Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS
terms
end;

subplot(2,2,i); % plot truncated FS representation of


f(t)
plot(t,f); % and actual signal
hold on;
plot([-2 -1 -1 0 0 1 1 2 2 3 3 4 4],[1 1 0 0 1 1 0 0 1 1
0 0 1],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);
end;
% *** Plot exponential magnitude and phase spectra for
1st 4 harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2
To = 2; wo = 2*pi/To; % fundamental period and
frequency
D0 = 0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn
and w

for n = -4:-1, % loop over negative n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store
fouriercoef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store
Fourier coef.
w(i) = n*wo; % store associated
frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum


of f(t)
stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four
Harmonics');

subplot(2,1,2); % plot phase spectrum of


f(t)
stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four
Harmonics');
% *** Plot truncatated FS for various numbers of terms.
***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 2; wo = 2*pi/To; % fundamental period and
frequency
D0 = 0.5; % signal offset
t = -2:0.01:4; % time over which we'll plot
signal
N = [1 5 50 500]; % +/- values at which we'll
truncate FS
for i = 1:4, % compute truncated FS for above
N values
f = D0*ones(size(t)); % start out with DC bias term
for n = -N(i):-1, % loop over
negative n
Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS
terms
end;

for n = 1:N(i), % loop over


positive n
Dn = (1 - exp(-j*n*pi))/(j*2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS
terms
end;

subplot(2,2,i); % plot truncated FS representation of


f(t)
plot(t,f); % and actual signal
hold on;
plot([-2 -1 -1 0 0 1 1 2 2 3 3 4 4],[1 1 0 0 1 1 0 0 1 1
0 0 1],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);
end;

% *** Plot exponential magnitude and phase spectra for


1st 4 harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2
To = 2; wo = 2*pi/To; % fundamental period and
frequency
D0 = 0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn
and w

for n = -4:-1, % loop over negative n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store
fouriercoef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = (1 - exp(-j*n*pi))/(j*2*pi*n); %Compute&store
Fourier coef.
w(i) = n*wo; % store associated
frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum


of f(t)
stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four
Harmonics');

subplot(2,1,2); % plot phase spectrum of


f(t)
stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four
Harmonics');
the greater the value of n, the fourier series generated
by the number of waves more and the risk effect smaller
and vice versa.
Percobaan 4.3
Prosedur :
1. Double-click Matlab/scilab
2. Buka text editor matlab (icon persegi putih, sisi kiri) atau menggunakan
sembarang text editor, seperti notepad, wordpad dll.
3. Ketik command line dibawah ini
% *** Plot truncatated FS for various numbers of terms. ***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 1; wo = 2*pi/To; % fundamental period and frequency
D0 = -0.5; % signal offset
t = -1:0.01:2; % time over which we'll plot signal
N = [1 5 10 50]; % +/- values at which we'll truncate FS
for i = 1:4, % compute truncated FS for above N values
f = D0*ones(size(t)); % start out with DC bias term
for n = -N(i):-1, % loop over negative n
Dn = j/(2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = j/(2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;
subplot(2,2,i); % plot truncated FS representation of f(t)
plot(t,f); % and actual signal
hold on;
plot([-1 0 0 1 1 2],[-1 0 -1 0 -1 0],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);

end;

% *** Plot exponential magnitude and phase spectra for 1st 4


harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2

To = 1; wo = 2*pi/To; % fundamental period and frequency


D0 = -0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn and w
for n = -4:-1, % loop over negative n
Dn(i) = j/(2*pi*n); % Compute & store fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = j/(2*pi*n); % Compute & store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of f(t)


stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four Harmonics');
4. Apa bedanya dengan percobaan 2.2 ?

The different is on the function that we want to convert


to fourier series. On the experiment 2.2 the function we
want to convert is step function but on this section is
ramp function.

5. Apa perbedaan antara percobaan 2.2 dan percobaan 2.3 pada


magnitude spectrum dan fase dari spectrum ?

Magnitude spectrum from the experiment 2.2 is do more


fluctuate than magnitude spectrum from the experiment 2.3.
For the phase spectrum its for the experiment 2.2 its do
fluctuate like the magnitude spectrum but for the
experiment 2.3 its do switching the sign negative to
positive.

6. Silakan rubah periode dasar (fundamental period) dengan berbagai


angka (minimal empat buah periode yang berbeda). Apa perubahan
yang terjadi pada magnitude spectrum dan fase spectrum ?

% *** Plot truncatated FS for various numbers of terms.


***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 2; wo = 2*pi/To; % fundamental period and
frequency
D0 = -0.5; % signal offset
t = -1:0.01:2; % time over which we'll plot
signal
N = [1 5 10 50]; % +/- values at which we'll
truncate FS
for i = 1:4, % compute truncated FS for
above N values
f = D0*ones(size(t)); % start out with DC bias
term
for n = -N(i):-1, % loop over negative n
Dn = j/(2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = j/(2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;
subplot(2,2,i); % plot truncated FS representation
of f(t)
plot(t,f); % and actual signal
hold on;
plot([-1 0 0 1 1 2],[-1 0 -1 0 -1 0],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);

end;

% *** Plot exponential magnitude and phase spectra for


1st 4 harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2

To = 2; wo = 2*pi/To; % fundamental period and frequency


D0 = -0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn
and w
for n = -4:-1, % loop over negative n
Dn(i) = j/(2*pi*n); % Compute & store fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = j/(2*pi*n); % Compute & store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of


f(t)
stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four
Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four
Harmonics');
% *** Plot truncatated FS for various numbers of terms.
***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 4; wo = 2*pi/To; % fundamental period and
frequency
D0 = -0.5; % signal offset
t = -1:0.01:2; % time over which we'll plot
signal
N = [1 5 10 50]; % +/- values at which we'll
truncate FS
for i = 1:4, % compute truncated FS for
above N values
f = D0*ones(size(t)); % start out with DC bias
term
for n = -N(i):-1, % loop over negative n
Dn = j/(2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = j/(2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;
subplot(2,2,i); % plot truncated FS representation
of f(t)
plot(t,f); % and actual signal
hold on;
plot([-1 0 0 1 1 2],[-1 0 -1 0 -1 0],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);

end;

% *** Plot exponential magnitude and phase spectra for


1st 4 harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2

To = 4; wo = 2*pi/To; % fundamental period and frequency


D0 = -0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn
and w
for n = -4:-1, % loop over negative n
Dn(i) = j/(2*pi*n); % Compute & store fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = j/(2*pi*n); % Compute & store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of


f(t)
stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four
Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four
Harmonics');
% *** Plot truncatated FS for various numbers of terms.
***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 8; wo = 2*pi/To; % fundamental period and
frequency
D0 = -0.5; % signal offset
t = -1:0.01:2; % time over which we'll plot
signal
N = [1 5 10 50]; % +/- values at which we'll
truncate FS
for i = 1:4, % compute truncated FS for
above N values
f = D0*ones(size(t)); % start out with DC bias
term
for n = -N(i):-1, % loop over negative n
Dn = j/(2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = j/(2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;
subplot(2,2,i); % plot truncated FS representation
of f(t)
plot(t,f); % and actual signal
hold on;
plot([-1 0 0 1 1 2],[-1 0 -1 0 -1 0],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);

end;

% *** Plot exponential magnitude and phase spectra for


1st 4 harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2

To = 8; wo = 2*pi/To; % fundamental period and frequency


D0 = -0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn
and w
for n = -4:-1, % loop over negative n
Dn(i) = j/(2*pi*n); % Compute & store fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = j/(2*pi*n); % Compute & store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of


f(t)
stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four
Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four
Harmonics');
% *** Plot truncatated FS for various numbers of terms.
***
clear; % clear matlab's memory
figure(1); clf; % open and clear figure 1
To = 16; wo = 2*pi/To; % fundamental period and
frequency
D0 = -0.5; % signal offset
t = -1:0.01:2; % time over which we'll plot
signal
N = [1 5 10 50]; % +/- values at which we'll
truncate FS
for i = 1:4, % compute truncated FS for
above N values
f = D0*ones(size(t)); % start out with DC bias
term
for n = -N(i):-1, % loop over negative n
Dn = j/(2*pi*n); % Fourier coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;

for n = 1:N(i), % loop over positive n


Dn = j/(2*pi*n); % Fourier
coefficient
f = f + real(Dn*exp(j*n*wo*t)); % add FS terms
end;
subplot(2,2,i); % plot truncated FS representation
of f(t)
plot(t,f); % and actual signal
hold on;
plot([-1 0 0 1 1 2],[-1 0 -1 0 -1 0],':');
hold off;
xlabel('t ');
ylabel('f(t)');
titlevec = ['Truncated f(t) FS for n = ' num2str(-
N(i)),',..,',num2str(N(i))];
title(titlevec);

end;

% *** Plot exponential magnitude and phase spectra for


1st 4 harmonics
clear; % clear matlab's memory
figure(2); clf; % open and clear figure 2

To = 16; wo = 2*pi/To; % fundamental period and


frequency
D0 = -0.5; % signal offset, 0 frequency term
i = 1; % vector index to help store Dn
and w
for n = -4:-1, % loop over negative n
Dn(i) = j/(2*pi*n); % Compute & store fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index
end;

Dn(i) = D0; w(i) = 0; % store 0 frequency terms


i = i + 1; % increment vector index

for n = 1:4, % loop over positive n


Dn(i) = j/(2*pi*n); % Compute & store Fourier coef.
w(i) = n*wo; % store associated frequency
i = i + 1; % increment vector index;
end;

subplot(2,1,1); % plot magnitude spectrum of


f(t)
stem(w,abs(Dn),'filled');
xlabel('\omega ');
ylabel('|D_n|');
title('Magnitude Spectrum of f(t) Showing First Four
Harmonics');

subplot(2,1,2); % plot phase spectrum of f(t)


stem(w,angle(Dn),'filled');
xlabel('\omega ');
ylabel('\angle D_n ');
title('Phase Spectrum of f(t) Showing First Four
Harmonics');
From changing the value To it is found that the greater
the fundamental value of the period the smaller the
resulting frequency value and vice versa in the magnitude
and phase spectrum of the First Four Harmonics.

S-ar putea să vă placă și