You are on page 1of 20

Rizka Angelina

03411940000007
ADD A
A. spectral leakage uniform
%SIGNAL PARAMETERS
%Rizka Angelina
%03411940000007
F= [2*7 3*7 4*7];
A= [1 2 3];
tmin = 0;
tmax = 0.93;
Fs = 200;
dt = 1/Fs;
t = tmin:dt:tmax ;
N = length(t);
y1 = A(1)*sin(2*pi*F(1)*t);
y2 = A(2)*sin(2*pi*F(2)*t);
y3 = A(3)*sin(2*pi*F(3)*t);
ytot = y1+y2+y3 ;
figure (1)
subplot (2,1,1), plot(t,y1,'r'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y2,'b'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y3,'y'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)'), legend('y1','y2','y3')
hold on;
subplot (2,1,2), plot(t,ytot,'b'), title('Combined Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
%FFT
yf = fft(ytot);
m_yf = abs(yf);
a_yf = m_yf/N;
k = 0:N-1;
df = Fs/(N-1);
fmax = 1/dt;
f = 0:df:fmax
% f = linspace(0,fmax,250);
figure(2), subplot(2,1,1)
plot(f,a_yf), title('amplitude spectrum (double-sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
axis([0 max(f) 0 max(a_yf)*1.2])
%One Sided
N1 = floor(N/2)+1;
f1 = f(1:N1);
yf1 = 2*yf(1:N1);
m_yf1 = abs(yf1);
a_yf1 = m_yf1/N;
figure(2), subplot(2,1,2)
plot(f1,a_yf1), title('Original Amplitude Spectrum (Single Sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
%Windowing
L=length(yf);
kw=rectwin(L);
figure (3)
Rizka Angelina
03411940000007
ADD A
plot(kw)
title('Rectangular Window')
yy=ytot.*kw';
yyf=fft(yy);
m_yyf=abs(yyf);
a_yyf=m_yyf/N;
figure
plot(f,a_yf,'r-')
title('FFT without windowing')
hold on
plot(f,a_yyf.*1.0,'r-') %Correction Factor 2.49
title('FFT with Windowing')
legend('leakage','windowed, less leakage')
Rizka Angelina
03411940000007
ADD A
Rizka Angelina
03411940000007
ADD A

B. Spectral leakage Hamming

clear all, clc


% spectral leakage hamming
%SIGNAL PARAMETERS
F= [2*7 3*7 4*7];
A= [1 2 3];
tmin = 0;
tmax = 0.93;
Fs = 200;
dt = 1/Fs;
t = tmin:dt:tmax ;
N = length(t);
y1 = A(1)*sin(2*pi*F(1)*t);
y2 = A(2)*sin(2*pi*F(2)*t);
y3 = A(3)*sin(2*pi*F(3)*t);
ytot = y1+y2+y3 ;
figure (1)
subplot (2,1,1), plot(t,y1,'r'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y2,'b'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y3,'g'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)'), legend('y1','y2','y3')
hold on;
subplot (2,1,2), plot(t,ytot,'b'), title('Combined Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
%FFT
yf = fft(ytot);
m_yf = abs(yf);
Rizka Angelina
03411940000007
ADD A
a_yf = m_yf/N;
k = 0:N-1;
df = Fs/(N-1);
fmax = 1/dt;
f = 0:df:fmax
% f = linspace(0,fmax,250);
figure(2), subplot(2,1,1)
plot(f,a_yf), title('amplitude spectrum (double-sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
axis([0 max(f) 0 max(a_yf)*1.2])
%One Sided
N1 = floor(N/2)+1;
f1 = f(1:N1);
yf1 = 2*yf(1:N1);
m_yf1 = abs(yf1);
a_yf1 = m_yf1/N;
figure(2), subplot(2,1,2)
plot(f1,a_yf1), title('Original Amplitude Spectrum (Single Sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
%Windowing
L=length(yf);
kw=hamming(L);
figure (3)
plot(kw)
title('Hamming Window')
yy=ytot.*kw';
yyf=fft(yy);
m_yyf=abs(yyf);
a_yyf=m_yyf/N;
figure
plot(f,a_yf,'b-')
title('FFT without windowing')
hold on
plot(f,a_yyf.*1.85,'r-') %Correction Factor 2.49
title('FFT with Windowing')
legend('leakage','windowed, less leakage')
Rizka Angelina
03411940000007
ADD A

C. Spectral leakage Flattop

clear all, clc


% spectral leakage flattop
%SIGNAL PARAMETERS
F= [2*7 3*7 4*7];
A= [1 2 3];
tmin = 0;
tmax = 0.93;
Fs = 200;
dt = 1/Fs;
Rizka Angelina
03411940000007
ADD A
t = tmin:dt:tmax ;
N = length(t);
y1 = A(1)*sin(2*pi*F(1)*t);
y2 = A(2)*sin(2*pi*F(2)*t);
y3 = A(3)*sin(2*pi*F(3)*t);
ytot = y1+y2+y3 ;
figure (1)
subplot (2,1,1), plot(t,y1,'r'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y2,'b'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y3,'g'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)'), legend('y1','y2','y3')
hold on;
subplot (2,1,2), plot(t,ytot,'b'), title('Combined Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
%FFT
yf = fft(ytot);
m_yf = abs(yf);
a_yf = m_yf/N;
k = 0:N-1;
df = Fs/(N-1);
fmax = 1/dt;
f = 0:df:fmax
% f = linspace(0,fmax,250);
figure(2), subplot(2,1,1)
plot(f,a_yf), title('amplitude spectrum (double-sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
axis([0 max(f) 0 max(a_yf)*1.2])
%One Sided
N1 = floor(N/2)+1;
f1 = f(1:N1);
yf1 = 2*yf(1:N1);
m_yf1 = abs(yf1);
a_yf1 = m_yf1/N;
figure(2), subplot(2,1,2)
plot(f1,a_yf1), title('Original Amplitude Spectrum (Single Sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
%Windowing
L=length(yf);
kw=flattopwin(L);
figure (3)
plot(kw)
title('Flattop Window')
yy=ytot.*kw';
yyf=fft(yy);
m_yyf=abs(yyf);
a_yyf=m_yyf/N;
figure
plot(f,a_yf,'b-')
title('FFT without windowing')
hold on
Rizka Angelina
03411940000007
ADD A
plot(f,a_yyf.*4.18,'r-') %Correction Factor 2.49
title('FFT with Windowing')
legend('leakage','windowed, less leakage')
Rizka Angelina
03411940000007
ADD A

D. Spectral Leakage Blackman

% spectral leakage blackman


%SIGNAL PARAMETERS
F= [2*7 3*7 4*7];
A= [1 2 3];
tmin = 0;
tmax = 0.93;
Fs = 200;
Rizka Angelina
03411940000007
ADD A
dt = 1/Fs;
t = tmin:dt:tmax ;
N = length(t);
y1 = A(1)*sin(2*pi*F(1)*t);
y2 = A(2)*sin(2*pi*F(2)*t);
y3 = A(3)*sin(2*pi*F(3)*t);
ytot = y1+y2+y3 ;
figure (1)
subplot (2,1,1), plot(t,y1,'r'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y2,'b'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y3,'g'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)'), legend('y1','y2','y3')
hold on;
subplot (2,1,2), plot(t,ytot,'b'), title('Combined Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
%FFT
yf = fft(ytot);
m_yf = abs(yf);
a_yf = m_yf/N;
k = 0:N-1;
df = Fs/(N-1);
fmax = 1/dt;
f = 0:df:fmax
% f = linspace(0,fmax,250);
figure(2), subplot(2,1,1)
plot(f,a_yf), title('amplitude spectrum (double-sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
axis([0 max(f) 0 max(a_yf)*1.2])
Rizka Angelina
03411940000007
ADD A
%One Sided
N1 = floor(N/2)+1;
f1 = f(1:N1);
yf1 = 2*yf(1:N1);
m_yf1 = abs(yf1);
a_yf1 = m_yf1/N;
figure(2), subplot(2,1,2)
plot(f1,a_yf1), title('Original Amplitude Spectrum (Single Sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
%Windowing
L=length(yf);
kw=blackman(L);
figure (3)
plot(kw)
title('Blackman Window')
yy=ytot.*kw';
yyf=fft(yy);
m_yyf=abs(yyf);
a_yyf=m_yyf/N;
figure
plot(f,a_yf,'b-')
title('FFT without windowing')
hold on
plot(f,a_yyf.*2.80,'r-') %Correction Factor 2.49
title('FFT with Windowing')
legend('leakage','windowed, less leakage')
Rizka Angelina
03411940000007
ADD A
Rizka Angelina
03411940000007
ADD A

E. Spectral Leakage Kaisar

MATLAB SCRIPT :
clear all, clc
% spectral leakage kaiser
%SIGNAL PARAMETERS
F= [2*7 3*7 4*7];
A= [1 2 3];
Rizka Angelina
03411940000007
ADD A
tmin = 0;
tmax = 0.93;
Fs = 200;
dt = 1/Fs;
t = tmin:dt:tmax ;
N = length(t);
y1 = A(1)*sin(2*pi*F(1)*t);
y2 = A(2)*sin(2*pi*F(2)*t);
y3 = A(3)*sin(2*pi*F(3)*t);
ytot = y1+y2+y3 ;
figure (1)
subplot (2,1,1), plot(t,y1,'r'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y2,'b'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y3,'g'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)'), legend('y1','y2','y3')
hold on;
subplot (2,1,2), plot(t,ytot,'b'), title('Combined Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
%FFT
yf = fft(ytot);
m_yf = abs(yf);
a_yf = m_yf/N;
k = 0:N-1;
df = Fs/(N-1);
fmax = 1/dt;
f = 0:df:fmax
% f = linspace(0,fmax,250);
figure(2), subplot(2,1,1)
Rizka Angelina
03411940000007
ADD A
plot(f,a_yf), title('amplitude spectrum (double-sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
axis([0 max(f) 0 max(a_yf)*1.2])
%One Sided
N1 = floor(N/2)+1;
f1 = f(1:N1);
yf1 = 2*yf(1:N1);
m_yf1 = abs(yf1);
a_yf1 = m_yf1/N;
figure(2), subplot(2,1,2)
plot(f1,a_yf1), title('Original Amplitude Spectrum (Single Sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
%Windowing
L=length(yf);
kw=kaiser(L,10);
figure (3)
plot(kw)
title('Kaiser Window')
yy=ytot.*kw';
yyf=fft(yy);
m_yyf=abs(yyf);
a_yyf=m_yyf/N;
figure
plot(f,a_yf,'b-')
title('FFT without windowing')
hold on
plot(f,a_yyf.*2.49,'r-') %Correction Factor 2.49
title('FFT with Windowing')
legend('leakage','windowed, less leakage')
Rizka Angelina
03411940000007
ADD A
Rizka Angelina
03411940000007
ADD A

F. Spectral Leakage Hanning

clear all, clc


% spectral leakage hanning
%SIGNAL PARAMETERS
F= [2*7 3*7 4*7];
A= [1 2 3];
tmin = 0;
tmax = 0.93;
Fs = 200;
Rizka Angelina
03411940000007
ADD A
dt = 1/Fs;
t = tmin:dt:tmax ;
N = length(t);
y1 = A(1)*sin(2*pi*F(1)*t);
y2 = A(2)*sin(2*pi*F(2)*t);
y3 = A(3)*sin(2*pi*F(3)*t);
ytot = y1+y2+y3 ;
figure (1)
subplot (2,1,1), plot(t,y1,'r'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y2,'b'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
subplot (2,1,1), plot(t,y3,'g'), title('Original Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)'), legend('y1','y2','y3')
hold on;
subplot (2,1,2), plot(t,ytot,'b'), title('Combined Signal')
xlabel ('t (second)'), ylabel('y(t) (meter)')
hold on;
%FFT
yf = fft(ytot);
m_yf = abs(yf);
a_yf = m_yf/N;
k = 0:N-1;
df = Fs/(N-1);
fmax = 1/dt;
f = 0:df:fmax
% f = linspace(0,fmax,250);
figure(2), subplot(2,1,1)
plot(f,a_yf), title('amplitude spectrum (double-sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
axis([0 max(f) 0 max(a_yf)*1.2])
Rizka Angelina
03411940000007
ADD A
%One Sided
N1 = floor(N/2)+1;
f1 = f(1:N1);
yf1 = 2*yf(1:N1);
m_yf1 = abs(yf1);
a_yf1 = m_yf1/N;
figure(2), subplot(2,1,2)
plot(f1,a_yf1), title('Original Amplitude Spectrum (Single Sided)')
xlabel('f (Hz)'), ylabel('Y(f)')
%Windowing
L=length(yf);
kw=hanning(L);
figure (3)
plot(kw)
title('Hanning Window')
yy=ytot.*kw';
yyf=fft(yy);
m_yyf=abs(yyf);
a_yyf=m_yyf/N;
figure
plot(f,a_yf,'b-')
title('FFT without windowing')
hold on
plot(f,a_yyf.*2.0,'r-') %Correction Factor
title('FFT with Windowing')
legend('leakage','windowed, less leakage')
Rizka Angelina
03411940000007
ADD A

You might also like