Sei sulla pagina 1di 4

fs = 8000 %Frekuensi sampling 8000 Hz

nbits = 16; % Jumlah bit kuantisasi 16 bit


channels = 2; % channels=2, stereo, channels=1,
sec = 3; % Lama suara direkam dalam detik
[x,fs] = audioread('test1.wav');
[y,fs] = audioread('test2.wav');
n = [1:length(x)];
k = 0:500; w=(pi/500)*k;
X = x(:,1)' * (exp(-j*pi/500)).^ (n'*k);
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
subplot(2,2,1); plot(k/500,magX);grid
xlabel('frequency in pi units');title('Magnitude Part')
subplot(2,2,3); plot(k/500,angX/pi);grid
xlabel('frequency in pi units');title('Angle Part')

Y = y(:,1)' * (exp(-j*pi/500)).^ (n'*k);


magY = abs(Y); angY = angle(Y);
realY = real(Y); imagY = imag(Y);
subplot(2,2,2); plot(k/500,magY);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,4); plot(k/500,angY/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

x1 = x(:,1)' .*cos(0.5*pi*n);
y1 = y(:,1)' .*sin(0.5*pi*n);

X1 = x1 * (exp(-j*pi/500)).^ (n'*k);
magX1 = abs(X1); angX1 = angle(X1);
realX1 = real(X1); imagX1 = imag(X1);
figure(2);
subplot(2,2,1); plot(k/500,magX1);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,3); plot(k/500,angX1/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

Y1 = y1 * (exp(-j*pi/500)).^ (n'*k);
magY1 = abs(Y1); angY1 = angle(Y1);
realY1 = real(Y1); imagY1 = imag(Y1);
subplot(2,2,2); plot(k/500,magY1);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,4); plot(k/500,angY1/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

r = x1+y1;
R = r*(exp(-j*pi/500)).^ (n'*k);
figure(3);
magR = abs(R); angR = angle(R);
realR = real(R); imagR = imag(R);
subplot(2,2,1); plot(k/500,magR);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,3); plot(k/500,angR/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

x2 = r .*cos(0.5*pi*n);
y2 = r .*sin(0.5*pi*n);

X2 = x2 * (exp(-j*pi/500)).^ (n'*k);
magX2 = abs(X2); angX2 = angle(X2);
realX2 = real(X2); imagX2 = imag(X2);
figure(4);
subplot(2,2,1); plot(k/500,magX2);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,3); plot(k/500,angX2/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

Y2 = y2 * (exp(-j*pi/500)).^ (n'*k);
magY2 = abs(Y2); angY2 = angle(Y2);
realY2 = real(Y2); imagY2 = imag(Y2);
subplot(2,2,2); plot(k/500,magY2);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,4); plot(k/500,angY2/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

b = [1 0 -1];
a = [1];
rx = filter(b,a,x2);
ry = filter(b,a,y2);

RX = rx * (exp(-j*pi/500)).^ (n'*k);
magRX = abs(RX); angRX = angle(RX);
realRX = real(RX); imagRX = imag(RX);
figure(5);
subplot(2,2,1); plot(k/500,magRX);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,3); plot(k/500,angRX/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

RY = ry * (exp(-j*pi/500)).^ (n'*k);
magRY = abs(RY); angRY = angle(RY);
realRY = real(RY); imagRY = imag(RY);
subplot(2,2,2); plot(k/500,magRY);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,4); plot(k/500,angRY/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

wp = 0.2*pi; ws = 0.3*pi;
tr_width=ws-wp;
M =ceil(6.6*pi/tr_width) + 1;
n =[0:1:M-1];
wc=(ws+wp)/1;
hd=ideal_lp(wc,M);
w_ham=(hamming(M))';
h=hd.*w_ham;
[db,mag,ha,w]=freqz_m(h,(1));
delta_w = 2*pi/1000;
Rp=-(min(db(1:1:wp/delta_w+1)));
As=-round(max(db(ws/delta_w+1:1:501)));
Figure(6);
sublpot(1,1,1);
subplot(2,2,1);stem(n,hd); title('Ideal Impulse Response');
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('hd(n)');
subplot(2,2,2);stem(n,w_ham); title('Hamming Window');
axis([0 M-1 0 1.1]); xlabel('n'); ylabel('w(n)');
subplot(2,2,3);stem(n,h); title('Actual Impulse Response');
axis([0 M-1 -0.1 0.3]); xlabel('n'); ylabel('h(n)');
subplot(2,2,4);plot(w/pi,db);
title('Magnitude Response in dB'); grid on;
axis([0 1 100 10]); xlabel('frequency in pi units');
ylabe('Decibels');

rx=filter(h,a,X2);
ry2=filter(h,a,Y2);

nn=1:lenght(rx2);
RX2 = rx2 * (exp(-j*pi/500)).^ (n'*k);
magRX2 = abs(RX2); angRX2 = angle(RX2);
realRX2 = real(RX2); imagRX2 = imag(RX2);
figure(7);
subplot(2,2,1); plot(k/500,magRX2);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,3); plot(k/500,angRX2/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

RY2 = ry2 * (exp(-j*pi/500)).^ (n'*k);


magRY2 = abs(RY2); angRY2 = angle(RY2);
realRY2 = real(RY2); imagRY2 = imag(RY2);
subplot(2,2,2); plot(k/500,magRY2);grid
xlabel('frequency in pi units'); title('Magnitude Part')
subplot(2,2,4); plot(k/500,angRY2/pi);grid
xlabel('frequency in pi units'); title('Angle Part')

Potrebbero piacerti anche