noble.m
Upload User: bfhydb
Upload Date: 2016-02-25
Package Size: 172k
Code Size: 5k
Category:

Audio program

Development Platform:

Matlab

  1. %sub band coding using noble identities for decimation and interpolation
  2. %author: Rao Farhat Masood
  3. close all;
  4. clear all;
  5. num=18000;
  6. [x,fs] = wavread('e:projmyvoice',num);
  7. x=x(:,1)';
  8. lnx=length(x);
  9. L = 2; 
  10. len  = 25;   
  11. wc = 1/L; %cut-off frequency is pi/2.
  12. freq=-pi:2*pi/(lnx-1):pi;% the frequency vector 
  13. lp = fir1(len-1, wc,'low');
  14. hp = fir1(len-1, wc,'high');
  15. %============================================================================
  16. %decimating the signals first
  17. ydl=x(1:2:lnx);
  18. ydh=x(2:2:lnx);
  19. %Now convolving 
  20. yl=conv(ydl,lp);
  21. yh=conv(ydh,hp);
  22. %===================
  23. %Again decimating Yl and Yh in 2nd stage
  24. s0=yl(1:2:end);
  25. s1=yl(2:2:end);
  26. s2=yh(1:2:end);
  27. s3=yh(2:2:end);
  28. % now finally convolving to get the four bands
  29. b0 =conv(yl,lp);
  30. b1=conv(yl,hp);
  31. b2 =conv(yh,lp);
  32. b3=conv(yh,hp);
  33. %=============================================================================
  34. % Time domain plots of signal and filters
  35.  figure(1); 
  36.  subplot(311);
  37.  plot(x);axis([0 lnx min(x) max(x)]);ylabel('speech=x');
  38.  Title('Speech and decimated bands in time ');
  39.  subplot(312);
  40.  plot(ydl),ylabel('ydl');axis([0 length(ydl) min(ydl) max(ydl)]);
  41.  subplot(313);
  42.  plot(ydh),ylabel('ydh');axis([0 length(ydh) min(ydh) max(ydh)]);
  43.  pause
  44.  %================================================================
  45.  %filters in time
  46.  figure(2);
  47.  subplot(211);
  48.  stem(lp);axis([0 length(lp) (min(lp)+0.1) (max(lp)+0.1)]);
  49.  ylabel('lp');title('Filters in time');
  50.  subplot(212);
  51.  stem(hp);axis([0 length(hp) min(hp)+0.1 max(hp)+0.1]);
  52.  ylabel('hp');
  53.  pause
  54. %==============================================================================
  55. %plotting filter response of filters and the two speech bands(lower and upper) in freq domian
  56. figure(3);
  57. X=fftshift(fft(x,lnx));
  58. Lp=fftshift(fft(lp,lnx));
  59. Hp=fftshift(fft(hp,lnx));
  60. YL=fftshift(fft(yl,lnx));
  61. Yh=fftshift(fft(yh,lnx));
  62. subplot(321), 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');
  63. subplot(323), plot(freq/pi, abs(Lp),'g');ylabel('|Lp|');axis([0 pi/pi  min(abs(Lp)) max(abs(Lp))]);
  64. subplot(324), plot(freq/pi, abs(Hp), 'g');ylabel('|Hp|');axis([0 pi/pi min(abs(Hp)) max(abs(Hp))]);
  65. subplot(325), plot(freq/pi, abs(YL), 'y');ylabel('|YL|');axis([0 pi/pi min(abs(YL)) max(abs(YL))]);legend('Low bandafter filtering');
  66. subplot(326), plot(freq/pi, abs(Yh), 'y');ylabel('|Yh|');axis([0 pi/pi min(abs(Yh)) max(abs(Yh))]);legend('High band after filtering');
  67. pause
  68. %=================================================================
  69. %freq plots of decimated signals(four bands)
  70. figure(4);
  71. title('Four bands in freq domain');
  72. subplot(411);
  73. 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');
  74. subplot(412);
  75. plot(freq/pi,abs(fftshift(fft(b1,lnx))));ylabel('|B1|');axis([0 pi/pi min(abs(fft(b0))) max(abs(fft(b1)))]);
  76. subplot(413);
  77. plot(freq/pi,abs(fftshift(fft(b2,lnx))));ylabel('|B2|');axis([0 pi/pi min(abs(fft(b2))) max(abs(fft(b2)))]);
  78. subplot(414);
  79. plot(freq/pi,abs(fftshift(fft(b3,lnx))));ylabel('|B3|');axis([0 pi/pi min(abs(fft(b3))) max(abs(fft(b3)))]);
  80. pause;
  81. %=================================================================
  82. %Listening to decimation results                            
  83. %wavplay(x,fs);
  84. % wavplay(b0,fs/2);
  85. % wavplay(b1,fs/2);
  86. % wavplay(b2,fs/2);
  87. % wavplay(b3,fs/2);
  88. %===================================================================
  89. % now synthesizing  
  90. %reconstruction filters
  91. L=2;
  92. hr = L*fir1(len-1, wc,'low');
  93. % hp = L*fir1(len-1, wc,'high');
  94. Sso=conv(b0,hr);
  95. Ss1=conv(b1,hr);
  96. Ss2=conv(b2,hr);
  97. Ss3=conv(b3,hr);
  98. N1=length(Sso);
  99. sb0=zeros(1,L*N1);
  100. sb1=zeros(1,L*N1);
  101. sb2=zeros(1,L*N1);
  102. sb3=zeros(1,L*N1);
  103. sb0(L:L:end)=Sso;
  104. sb1(L:L:end)=Ss1;
  105. sb2(L:L:end)=Ss2;
  106. sb3(L:L:end)=Ss3;
  107. %=================================================
  108. Slow=sb0-sb1;
  109. Shigh=sb2-sb3;
  110. sub1=conv(hr,Slow);
  111. sub2=conv(hr,Shigh);
  112. subll=zeros(1,length(sub1)*2);
  113. subhh=zeros(1,length(sub2)*2);
  114. subll(L:L:end)=sub1;
  115. subhh(L:L:end)=sub2;
  116. sub=subll-subhh;
  117. %================================================================
  118. %Freq plots of final two bands and their merging into a single band
  119. figure(5);
  120. subplot(311);
  121. 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');
  122. subplot(312);
  123. plot(freq/pi,abs(fftshift(fft(subhh,lnx))));ylabel('|High band|');axis([0 pi/pi min(abs(fft(subhh))) max(abs(fft(subhh)))]);
  124. subplot(313);
  125. plot(freq/pi,abs(fftshift(fft(sub,lnx))));ylabel('|Band|');axis([0 pi/pi min(abs(fft(sub))) max(abs(fft(sub)))]);
  126. pause;
  127. %============================================================
  128. %Comparison
  129. figure(6);
  130. subplot(211), 
  131. plot(freq/pi, abs(X));ylabel('|X|');axis([0 pi/pi min(abs(X)) max(abs(X))]);title('Comparison');
  132. legend('original band');
  133. subplot(212);
  134. plot(freq/pi,abs(fftshift(fft(sub,lnx))),'r');ylabel('|Band|');axis([0 pi/pi min(abs(fft(sub))) max(abs(fft(sub)))]);
  135. legend('Synthesized Band');
  136. %=====================================================================
  137. %wavplay(sub,fs);
  138. %wavplay(sub,fs);
  139. % fs1=fs/4;
  140. % wavwrite(b0,fs1,nbits,'bandn0');
  141. % wavwrite(b1,fs1,nbits,'bandn1');
  142. % wavwrite(b2,fs1,nbits,'bandn2');
  143. % wavwrite(b3,fs1,nbits,'bandn3');
  144. % wavwrite(sub,fs,nbits,'nobl');