Professional Documents
Culture Documents
clear all;
[x,FS]=wavread('a.wav');
fs=16000;
figure(1)
plot(x)
legend('Waveform')
ylabel('Magnitude')
xlabel('sample')
figure(2)
frame_1=0.02*fs;
xframe=x(5*frame_1:6*frame_1);
plot(xframe);
legend('Sinyal satu sampel')
ylabel('Magnitude')
xlabel('sample')
figure(3)
ms2=fs/500;
ms20=fs/50;
r=xcorr(xframe,ms20,'coeff');
d=(-ms20:ms20)/fs;
plot(d,r)
r=r(ms20+1:2*ms20+1)
[rmax,tx]=max(r(ms2:ms20))
Sinyal a.wav
0.15
Waveform
0.1
0.05
0
Magnitude
-0.05
-0.1
-0.15
-0.2
0 1000 2000 3000 4000 5000 6000 7000 8000 9000
sample
0.08
Sinyal satu sampel
0.06
0.04
0.02
Magnitude
-0.02
-0.04
-0.06
-0.08
-0.1
0 50 100 150 200 250 300 350
sample
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-0.02 -0.015 -0.01 -0.005 0 0.005 0.01 0.015 0.02
rmax =
0.5729
tx =
106
Sinyal u.wav
0.2
Waveform
0.15
0.1
0.05
Magnitude
-0.05
-0.1
-0.15
-0.2
0 1000 2000 3000 4000 5000 6000 7000 8000
sample
0.15
Sinyal satu sampel
0.1
0.05
0
Magnitude
-0.05
-0.1
-0.15
-0.2
0 50 100 150 200 250 300 350
sample
1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-0.02 -0.015 -0.01 -0.005 0 0.005 0.01 0.015 0.02
rmax =
0.6745
tx =
76
clear all;
[x,FS]=wavread('a.wav');
fs=16000;
figure(1)
frame_1=0.02*fs;
xframe=x(6*frame_1:8*frame_1);
plot(xframe);
legend('Sinyal dua sampel')
ylabel('Magnitude')
xlabel('sample')
figure(2)
Y=fft(xframe.*hamming(length(xframe)));
hz8000=8000*length(Y)/fs;
f=(0:hz8000)*fs/length(Y);
plot(f,20*log10(abs(Y(1:length(f)))+eps));
legend('Spectrum')
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
figure(3)
ms1=fs/1000;
ms20=fs/50;
C=fft(log(abs(Y)+eps));
q=(ms1:ms20)/fs;
plot(q,abs(C(ms1:ms20)));
legend('Cepstrum')
xlabel('Quefrency (s)')
ylabel('Amplitude')
[c,fx]=max(abs(C(ms1:ms20)))
fprintf('Fx = %g Hz\n',fs/(ms1+fx-1))
0.08
Sinyal dua sampel
0.06
0.04
0.02
Magnitude
-0.02
-0.04
-0.06
-0.08
0 100 200 300 400 500 600 700
sample
20
Spectrum
10
-10
Magnitude (dB)
-20
-30
-40
-50
-60
0 1000 2000 3000 4000 5000 6000 7000 8000
Frequency (Hz)
60
Cepstrum
50
40
Amplitude
30
20
10
0
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
Quefrency (s)
c =
53.3173
fx =
Fx = 842.105 Hz
[x,fs]=wavread('a.wav');
x=resample(x,10000,fs);
fs=10000;
figure(1)
frame_1=0.02*fs;
xframe=x(5*frame_1:6*frame_1);
t=(0:length(xframe)-1)/fs;
plot(t,xframe);
legend('1 Frame Waveform');
ylabel('Magnitude')
xlabel('Time')
figure(2)
Y=fft(xframe.*hamming(length(xframe)));
hz5000=5000*length(Y)/fs;
f=(0:hz5000)*fs/length(Y);
plot(f,20*log10(abs(Y(1:length(f)))+eps));
legend('Spectrum');
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
figure(3)
ncoeff=2+fs/1000;
a=lpc(x,ncoeff);
[h,f]=freqz(1,a,512,fs);
plot(f,20*log10(abs(h)+eps));
legend('LP Filter')
xlabel('Frequency (Hz)');
ylabel('Gain (dB)');
r=roots(a);
r=r(imag(r)>0.01);
ffreq=sort(atan2(imag(r),real(r))*fs/(2*pi));
for i=1:length(ffreq)
fprintf('Formant %d Frequency %.1f\n',i,ffreq(i));
end
Sinyal a.wav
0.08
1 Frame Waveform
0.06
0.04
0.02
Magnitude
-0.02
-0.04
-0.06
-0.08
-0.1
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
Time
10
Spectrum
0
-10
-20
Magnitude (dB)
-30
-40
-50
-60
-70
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)
60
LP Filter
50
40
30
20
Gain (dB)
10
-10
-20
-30
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)
Sinyal u.wav
0.15
1 Frame Waveform
0.1
0.05
0
Magnitude
-0.05
-0.1
-0.15
-0.2
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
Time
20
Spectrum
10
-10
Magnitude (dB)
-20
-30
-40
-50
-60
-70
-80
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)
70
LP Filter
60
50
40
30
Gain (dB)
20
10
-10
-20
-30
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)
Formant 1 Frequency 313.1
Formant 2 Frequency 487.4
Formant 3 Frequency 889.8
Formant 4 Frequency 2492.4
Formant 5 Frequency 3575.8
Formant 6 Frequency 4358.5
[x,fs]=wavread('ada.wav');
x=resample(x,10000,fs);
fs=10000;
figure(1)
frame_1=0.02*fs;
xframe=x(15*frame_1:16*frame_1);
t=(0:length(xframe)-1)/fs;
plot(t,xframe);
legend('1 Frame Waveform');
ylabel('Magnitude')
xlabel('Time')
figure(2)
ms2=fs/500;
ms20=fs/50;
r=xcorr(xframe,ms20,'coeff');
d=(-ms20:ms20)/fs;
plot(d,r)
r=r(ms20+1:2*ms20+1)
[rmax,tx]=max(r(ms2:ms20))
figure(3)
ncoeff=2+fs/1000;
a=lpc(x,ncoeff);
[h,f]=freqz(1,a,512,fs);
plot(f,20*log10(abs(h)+eps));
legend('LP Filter')
xlabel('Frequency (Hz)');
ylabel('Gain (dB)');
r=roots(a);
r=r(imag(r)>0.01);
ffreq=sort(atan2(imag(r),real(r))*fs/(2*pi));
for i=1:length(ffreq)
fprintf('Formant %d Frequency %.1f\n',i,ffreq(i));
end
-3
x 10
6
1 Frame Waveform
2
Magnitude
-2
-4
-6
0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02
Time
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-0.02 -0.015 -0.01 -0.005 0 0.005 0.01 0.015 0.02
50
LP Filter
40
30
20
10
Gain (dB)
-10
-20
-30
-40
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Frequency (Hz)