# Subband coding for speech signal using Matlab

Status
Not open for further replies.

#### kirjmaru

##### Newbie level 4 Hi guys
I do a project. It's subband coding for speech coding using Matlab. But I don't know code using Matlab
I have some code, but just filter bank and multirate. I have to complete quantization and encode
where can I find full code

Last edited:

#### phongphanp

##### Full Member level 5 Why you donn't try to study the subband coding by you own such as what,when,why questions ? Finding code to study you can load such a files at mathworks web site. In you direction, I think about Physics , not at all. Because each tool designed for specific work.

#### lordy

##### Junior Member level 2 i agree with phongphanp.
last one week im seeing the similar post every one want just code and do the project done, where is learning gone?

@kirjmaru

dont just fined the code it is useless.

for learning matlab just check the tutorials on net u will get thousands of tutorial.

#### kirjmaru

##### Newbie level 4 Hi, guys
I write the code, but I don't know it true or false. and I don't know write quantization for subband b0, b1, b2, b3. Please help me
num=40000;
[x,fs,nbits] = wavread('sub1.wav',num);% tin hieu vao
x=x ,1)';
lnx=length(x);
L = 2;
len = 26;
wc=1/2;
freq=-pi:2*pi/(lnx-1) i;% the frequency vector
ho=fir1(len-1,wc,'low');% Bo loc thong thap h0 for k = 1:length(ho)
h1(k) = ((-1)^k)*ho(k); % Bo loc thong cao h1 end
%--Dan loc phan tich---%
% level 1
yl=filter(ho,1,x);% Cho tin hieu vao qua bo loc thong thap ho yh=filter(h1,1,x);% Cho tin hieu vao qua bo loc thong cao h1 ydl=downsample(yl,2);% Giam toc do lay mau cua tin hieu
ydh=downsample(yh,2);% Giam toc do lay mau cua tin hieu
%level 2
s0=filter(lp,1,ydl);% Cho tin hieu qua bo loc thong thap
s1=filter(hp,1,ydl);% Cho tin hieu qua bo loc thong cao
s2=filter(lp,1,ydh);
s3=filter(hp,1,ydh);
% giảm tốc độ lấy mẫu của 4 băng cuối
%b0 =s0(1:2:length(s0));
%b1=s1(1:2:length(s1));
%b2 =s2(1:2:length(s2));
%b3=s3(1:2:length(s3));
b0=downsample(s0,2);
b1=downsample(s1,2);
b2=downsample(s2,2);
b3=downsample(s3,2);

%--Dan loc tong hop--%

L=2;
% level 1
Ss0=upsample(b0,2);% Tang toc do lay mau
Ss1=upsample(b1,2);% Tang toc do lay mau
Ss2=upsample(b2,2);
Ss3=upsample(b3,2);
%Passing through reconstruction filters
% making a low pass filter with cutoff at 1/L and gain L
g0=L*lp;% Bo loc khoi phuc
g1=-L*hp;% Bo loc khoi phuc
% finding the freq response of the filter
sb0=filter(g0,1,Ss0);
sb1=filter(g1,1,Ss1);
sb2=filter(g0,1,Ss2);
sb3=filter(g1,1,Ss3);
Slow=sb0+sb1;
Shigh=sb2+sb3;
% level 2
subl=upsample(Slow,2);
subh=upsample(Shigh,2);
subll=filter(g0,1,subl);
subhh=filter(g1,1,subh);
sub=subll+subhh;
wavwrite(sub,'sub11.wav');

%-------------%
%Time domain plots of signal and filters
*figure(1);*
*subplot(311);
*plot(x);
*axis([0 lnx min(x) max(x)]);
*%axis([10000 11000 *min(x) max(x)]);
*ylabel('speech');
*title('Speech and filters in time domain');
*subplot(312);
*stem(lp);axis([0 length(lp) (min(lp)+0.1) (max(lp)+0.1)]);
*ylabel('lp');
*subplot(313);
*stem(hp);axis([0 length(hp) min(hp)+0.1 max(hp)+0.1]);
*ylabel('hp');
*
%==============================================================================
%plotting filter response of filters and the two speech bands(lower and upper) in freq domian
figure(2);
X=fftshift(fft(x,lnx));
Lp=fftshift(fft(lp,lnx));
Hp=fftshift(fft(hp,lnx));
YL=fftshift(fft(yl,lnx));
Yh=fftshift(fft(yh,lnx));
subplot(511), plot(freq/pi, abs(X));ylabel('|X|');axis([0 pi/pi min(abs(X)) max(abs(X))]);title('Freq domain representation of speech and the two bands');
subplot(512), plot(freq/pi, abs(Lp));ylabel('|Lp|');axis([0 pi/pi *min(abs(Lp)) max(abs(Lp))]);
subplot(513), plot(freq/pi, abs(Hp));ylabel('|Hp|');axis([0 pi/pi min(abs(Hp)) max(abs(Hp))]);
subplot(514), plot(freq/pi, abs(YL));ylabel('|YL|');axis([0 pi/pi min(abs(YL)) max(abs(YL))]);legend('Low bandafter filtering');
subplot(515), plot(freq/pi, abs(Yh));ylabel('|Yh|');axis([0 pi/pi min(abs(Yh)) max(abs(Yh))]);legend('High band after filtering');

%subplot(511);plot(abs(Lp));
%subplot(512);plot(abs(Hp));
%subplot(513);plot(abs(X));
%subplot(514);plot(abs(YL));
%subplot(515);plot(abs(Yh));
%pause
%freq plots of decimated signals(four bands)
figure(3);
title('Four bands in freq domain');
subplot(411);
plot(abs(fftshift(fft(b0,lnx))));
%plot(freq/pi,abs(fftshift(fft(b0,lnx))));ylabel('|B0|');axis([0 pi/pi min(abs(fft(b0))) max(abs(fft(b0)))]);title('Four bands in freq domain');
subplot(412);
plot(abs(fftshift(fft(b1,lnx))));
%plot(freq/pi,abs(fftshift(fft(b1,lnx))));ylabel('|B1|');axis([0 pi/pi min(abs(fft(b0))) max(abs(fft(b1)))]);
subplot(413);
plot(abs(fftshift(fft(b2,lnx))));
%plot(freq/pi,abs(fftshift(fft(b2,lnx))));ylabel('|B2|');axis([0 pi/pi min(abs(fft(b2))) max(abs(fft(b2)))]);
subplot(414);
plot(abs(fftshift(fft(b3,lnx))));
%plot(freq/pi,abs(fftshift(fft(b3,lnx))));ylabel('|B3|');axis([0 pi/pi min(abs(fft(b3))) max(abs(fft(b3)))]);
%pause;
%Freq plots of final two bands and their merging into a single band
figure(4);
subplot(311);
plot(freq/pi,abs(fftshift(fft(subll,lnx))));ylabel('|low band|');axis([0 pi/pi min(abs(fft(subll))) max(abs(fft(subll)))]);title('Final two bands in synthesis');
subplot(312);
plot(freq/pi,abs(fftshift(fft(subhh,lnx))));ylabel('|High band|');axis([0 pi/pi min(abs(fft(subhh))) max(abs(fft(subhh)))]);
subplot(313);
plot(freq/pi,abs(fftshift(fft(sub,lnx))));ylabel('|Band|');axis([0 pi/pi min(abs(fft(sub))) max(abs(fft(sub)))]);
%pause;
%============================================================
%Comparison
figure(5);
subplot(211),*
plot(freq/pi, abs(X));ylabel('|X|');axis([0 pi/pi min(abs(X)) max(abs(X))]);title('Comparison');
legend('original band');
subplot(212);
plot(freq/pi,abs(fftshift(fft(sub,lnx))));ylabel('|Band|');axis([0 pi/pi min(abs(fft(sub))) max(abs(fft(sub)))]);
legend('Synthesized Band');

#### phongphanp

##### Full Member level 5 kirjmaru, Do you try Gibbs Sampling, yet ?

#### kirjmaru

##### Newbie level 4 kirjmaru, Do you try Gibbs Sampling, yet ?
No, I don't know it
I just need quantization subband b0 with 8 bit, b1 with 8 bit, b2 with 4 bit and b3 with 4 bit
And dequantization
If I do this, my first signal : frequency sample is 8kHz, quantization 8 bit--> 8*8=64kbit/s
Now subband: each subband have frequency sample is 2kHz--> 2*8+2*8+2*4+2*4=48kbit/s
--> It's reduce without change quality

#### phongphanp

##### Full Member level 5 Sure, you need change the data test set to get more difference output in algorithm testing . And change sampling rate such as 1 bit/s and >40kbit/s , then the difference output will has high piority.

Status
Not open for further replies.