-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLPC_Vocoder.m
152 lines (124 loc) · 3.42 KB
/
LPC_Vocoder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
%Author: Yunyang Zeng
%% a) LPC vocoder
%% Read audio
clear
close all
[welc,Fs]=audioread("welcome16k.wav");
welc=welc(1:end-mod(length(welc),160));
N=320;
window=hamming(N);
a_list=[];
g_list=[];
%white_noise=wgn(N,1,0);
seq_odd=[];
resyn_even=[];
resyn_odd=[];
seq_even=[];
P=14;
for i=0:(length(welc)-N)/160
seg=welc(160*i+1:160*i+N);
wind_seg=window.*seg;
if mod(i,2)==0
seq_even=[seq_even wind_seg];
else
seq_odd=[seq_odd wind_seg];
end
%{
[a,g]=lpc(wind_seg,14);
a_list=[a_list;a];
g_list=[g_list; g];
if i==0
[resyn,zi]=filter(g,a,white_noise,zeros(length(a)-1,1));
else
[resyn,zi]=filter(g,a,white_noise,zi);
end
%}
end
%% Resynthesize with white noise exitation
for j=1:64
sequence=seq_even(:,j);
[a,g]=lpc(sequence,P);
white_noise=wgn(N,1,0);
phi=zeros(P+1,1);
for m=0:P
phi(m+1)=dot(sequence(1:N-m),sequence(1+m:N));
end
G=sqrt(a*phi);
if j==1
[resyn,zi]=filter(G,a,white_noise,zeros(length(a)-1,1));
else
[resyn,zi]=filter(G,a,white_noise,zi);
end
resyn_even=[resyn_even; resyn];
end
for k=1:63
sequence=seq_odd(:,k);
[a,g]=lpc(sequence,P);
white_noise=wgn(N,1,0);
phi=zeros(P+1,1);
for m=0:P
phi(m+1)=dot(sequence(1:N-m),sequence(1+m:N));
end
G=sqrt(a*phi);
if k==1
[resyn,zi]=filter(G,a,white_noise,zeros(length(a)-1,1));
else
[resyn,zi]=filter(G,a,white_noise,zi);
end
resyn_odd=[resyn_odd; resyn];
end
resyn_white_noise=[resyn_even(1:160); 0.5.*(resyn_even(161:end-160)+resyn_odd); resyn_even(end-160+1: end)];
resyn_white_noise=resyn_white_noise./max(abs(resyn_white_noise));
audiowrite("resyn_white_noise.wav",resyn_white_noise,16000);
%% Resynthesize with periodic pulse train exitation
f=100;
fs=16000;
impulse_train=zeros(N,1);
impulse_train(1:1/f*fs:end)=1;
resyn_even_impulse=[];
resyn_odd_impulse=[];
for j=1:64
sequence=seq_even(:,j);
[a,g]=lpc(sequence,P);
phi=zeros(P+1,1);
for m=0:P
phi(m+1)=dot(sequence(1:N-m),sequence(1+m:N));
end
G=sqrt(a*phi);
if j==1
[resyn,zi]=filter(G,a,impulse_train,zeros(length(a)-1,1));
else
[resyn,zi]=filter(G,a,impulse_train,zi);
end
resyn_even_impulse=[resyn_even_impulse; resyn];
end
for k=1:63
sequence=seq_odd(:,k);
[a,g]=lpc(sequence,P);
phi=zeros(P+1,1);
for m=0:P
phi(m+1)=dot(sequence(1:N-m),sequence(1+m:N));
end
G=sqrt(a*phi);
if k==1
[resyn,zi]=filter(G,a,impulse_train,zeros(length(a)-1,1));
else
[resyn,zi]=filter(G,a,impulse_train,zi);
end
resyn_odd_impulse=[resyn_odd_impulse; resyn];
end
resyn_impulse=[resyn_even_impulse(1:160); 0.5.*(resyn_even_impulse(161:end-160)+resyn_odd_impulse); resyn_even_impulse(end-160+1: end)];
resyn_impulse=resyn_impulse./max(abs(resyn_impulse));
audiowrite("resyn_impulse.wav",resyn_impulse,16000);
figure();
colormap jet
spectrogram(welc,hamming(320),160,512,16000,"yaxis");
title("Original signal");
figure();
colormap jet
spectrogram(resyn_impulse,hamming(320),160,512,16000,"yaxis");
title("Resynthesized signal with impulse train excitation");
figure();
colormap jet
spectrogram(resyn_white_noise,hamming(320),160,512,16000,"yaxis");
title("Resynthesized signal with white noise excitation");