You are on page 1of 13

Muhammad Feeizal Antareza

101132581957223
PR-6

a.

Program

figure(2)

fs=8000;
Hasil

T=1/fs;
n=0:1:239;
t=n*T;
x1=5*cos(2*pi*500*t);
x2=5*cos(2*pi*1200*t + 0.25*pi);
x3=5*cos(2*pi*1800*t + 0.5*pi);
x=x1+x2+x3;
N=length(x);
index_t=[0:1:N-1];
f=[0:1:N-1]*8000/N;
%Map frequency bin to frequency (Hz)
xf=abs(fft(x))/N;
x_b=x.*bartlett(N)';
%Apply triangular window function
xf_b=abs(fft(x_b))/N;
%Calculate amplitude spectrum
subplot(2,2,1);plot(index_t,x);grid
xlabel('Time index n'); ylabel('x(n)');
subplot(2,2,3); plot(index_t,x_b);grid
xlabel('Time index n'); ylabel('Triangular windowed x(n)');
subplot(2,2,2);plot(f,xf);grid;axis([0 8000 0 1]);
xlabel('Frequency (Hz)'); ylabel('Ak (no window)');
subplot(2,2,4); plot(f,xf_b);grid; axis([0 8000 0 1]);
xlabel('Frequency (Hz)'); ylabel('Triangular windowed Ak');

b.

Program (disatukan)

clear
clc
fs=8000;
T=1/fs;
n=0:1:239;
figure(3)
t=n*T;
fs=8000;
x1=5*cos(2*pi*500*t);
T=1/fs;
x2=5*cos(2*pi*1200*t + 0.25*pi);
n=0:1:239;
x3=5*cos(2*pi*1800*t + 0.5*pi);
t=n*T;
x=x1+x2+x3;
x1=5*cos(2*pi*500*t);
N=length(x);
x2=5*cos(2*pi*1200*t
index_t=[0:1:N-1]; + 0.25*pi);
x3=5*cos(2*pi*1800*t
f=[0:1:N-1]*8000/N; + 0.5*pi);
%Map frequency bin to frequency (Hz)
x=x1+x2+x3;
xf=abs(fft(x))/N;
%Calculate amplitude spectrum
N=length(x);
figure(1)
index_t=[0:1:N-1];
x_r=x.*rectwin(N)';
%Apply triangular window function
f=[0:1:N-1]*8000/N;
%Map
frequency
bin tospectrum
frequency (Hz)
xf_r=abs(fft(x_r))/N;
%Calculate
amplitude
xf=abs(fft(x))/N;
subplot(2,2,1);plot(index_t,x);grid
x_hm=x.*hamming(N)';
%Apply Hamming window function
xlabel('Time index n'); ylabel('x(n)');
xf_hm=abs(fft(x_hm))/N;
%Calculate amplitude spectrum
subplot(2,2,3); plot(index_t,x_r);grid
subplot(2,2,1);plot(index_t,x);grid
xlabel('Time index n'); ylabel('Rectangular windowed x(n)');
xlabel('Time
index n'); ylabel('x(n)'); 8000 0 1]);
subplot(2,2,2);plot(f,xf);grid;axis([0
subplot(2,2,3);
plot(index_t,x_hm);grid
xlabel('Frequency
(Hz)'); ylabel('Ak (no window)');
xlabel('Time
index
n'); ylabel('Hamming
windowed
subplot(2,2,4);
plot(f,xf_r);grid;
axis([0
8000 0x(n)');
1]);
subplot(2,2,2);plot(f,xf);grid;axis([0
fs 0 1]);
xlabel('Frequency (Hz)'); ylabel('Rectangular
windowed Ak');
xlabel('Frequency
(Hz)'); ylabel('Ak (no window)');
%using Bartlett window
subplot(2,2,4); plot(f,xf_hm);grid;axis([0 fs 0 1]);
xlabel('Frequency (Hz)'); ylabel('Hamming windowed Ak');

Hasil
b.(1)

b.(2)

b.(3)

c.

Terlihat bahwa spectral leakage mulai dari


rectatngular, triangular, sampai pada hamming semakin
tidak ada (semakin kecil bahkan tidak ada).

clear all; close all


figure(1)
load v0.dat; % load speech data at the current folder
x = v0;
% provided by the instructor
fs=12800;
% sampling rate
lg=length(x);
% length of xnal vector
T=1/fs;
% sampling period
t=[0:1:lg-1]*T;
% time instants in second
D=abs(fft(x))/lg;
k=0:1:lg-1;
f=k*fs/lg;
subplot(2,1,1);
plot(t,x);grid
title('v0')
xlabel('t')
ylabel('x')
subplot(2,1,2);
plot(f(1,500:lg*5/128),D(1,500:lg*5/128));grid
xlabel('frekuensi(Hz)')
ylabel('signal spectrum')

figure(2)
load v1.dat; % load speech data at the current folder
x = v1;
% provided by the instructor
fs=12800;
% sampling rate
lg=length(x);
% length of xnal vector
T=1/fs;
% sampling period
t=[0:1:lg-1]*T;
% time instants in second
D=abs(fft(x))/lg;
k=0:1:lg-1;
f=k*fs/lg;
subplot(2,1,1);
plot(t,x);grid
title('v1')
xlabel('t')
ylabel('x')
subplot(2,1,2);
plot(f(1,500:lg*5/128),D(1,500:lg*5/128));grid
xlabel('frekuensi(Hz)')
ylabel('signal spectrum')

figure(3)
load v2.dat; % load speech data at the current folder
x = v2;
% provided by the instructor
fs=12800;
% sampling rate
lg=length(x);
% length of xnal vector
T=1/fs;
% sampling period
t=[0:1:lg-1]*T;
% time instants in second
D=abs(fft(x))/lg;
k=0:1:lg-1;
f=k*fs/lg;
subplot(2,1,1);
plot(t,x);grid
title('v2')
xlabel('t')
ylabel('x')
subplot(2,1,2);
plot(f(1,500:lg*5/128),D(1,500:lg*5/128));grid
xlabel('frekuensi(Hz)')
ylabel('signal spectrum')

figure(4)
load v3.dat; % load speech data at the current folder
x = v3;
% provided by the instructor
fs=12800;
% sampling rate
lg=length(x);
% length of xnal vector
T=1/fs;
% sampling period
t=[0:1:lg-1]*T;
% time instants in second
D=abs(fft(x))/lg;
k=0:1:lg-1;
f=k*fs/lg;
subplot(2,1,1);
plot(t,x);grid
title('v3')
xlabel('t')
ylabel('x')
subplot(2,1,2);
plot(f(1,500:lg*5/128),D(1,500:lg*5/128));grid
xlabel('frekuensi(Hz)')
ylabel('signal spectrum')

figure(5)
load v4.dat; % load speech data at the current folder
x = v4;
% provided by the instructor
fs=12800;
% sampling rate
lg=length(x);
% length of xnal vector
T=1/fs;
% sampling period
t=[0:1:lg-1]*T;
% time instants in second
D=abs(fft(x))/lg;
k=0:1:lg-1;
f=k*fs/lg;
subplot(2,1,1);
plot(t,x);grid
title('v4')
xlabel('t')
ylabel('x')
subplot(2,1,2);
plot(f(1,500:lg*5/128),D(1,500:lg*5/128));grid
xlabel('frekuensi(Hz)')
ylabel('signal spectrum')

figure(6)
load v5.dat; % load speech data at the current folder
x = v5;
% provided by the instructor
fs=12800;
% sampling rate
lg=length(x);
% length of xnal vector
T=1/fs;
% sampling period
t=[0:1:lg-1]*T;
% time instants in second
D=abs(fft(x))/lg;
k=0:1:lg-1;
f=k*fs/lg;
subplot(2,1,1);
plot(t,x);grid
title('v5')
xlabel('t')
ylabel('x')
subplot(2,1,2);
plot(f(1,500:lg*5/128),D(1,500:lg*5/128));grid
xlabel('frekuensi(Hz)')
ylabel('signal spectrum')

Hasil

You might also like