processing single symbol thru speex
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 30 May 2015 03:26:56 +0000 (03:26 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 30 May 2015 03:26:56 +0000 (03:26 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2167 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/cellmodem.m

index 7477d06fb216a2867a59f42e4afa26a25b22e576..ac0e0c3ba09e97c22ea83554e2186fc9c2f95a02 100644 (file)
 graphics_toolkit ("gnuplot");
 lsp;
 
+codec_cmd = "speexenc --bitrate 4000 in.raw - | speexdec - out.raw"
+
 lpc_order = 4;
 Fs = 8000;
-fo = 100;             % pitch frequency of voice 
+fo = 200;             % pitch frequency of voice 
 wo = 2*pi*fo/Fs;      % pitch in rads
 N  = Fs*0.04;         % frame length
+frames = Fs/N;        % frames to play through codec
+gain = 100;
+
+s = [];
+w_log = [];
+w__log = [];
+
+for f=1:frames
 
-% construct LSP symbol
+  % construct LSP symbol
 
-w = [0.1 0.4  0.5 0.8]*pi
+  w = [0.1 0.4  0.5 0.8]*pi;
 
-% synthesise speech signal
+  % synthesise speech signal
 
-a=lsptoa(w)
-l=pi/wo;
-ex = zeros(1,N);
-for m=1:l
+  a=lsptoa(w);
+  w_log = [w_log; w];
+  l=pi/wo;
+  ex = zeros(1,N);
+  for m=1:l
     ex += cos(wo*m*(1:N));
+  end
+  s = [s filter(1, a, ex)];
 end
-s = filter(1, a, ex);
 
-% insert codec here (e.g. write to file, run codec, read file)
+% play through codec
 
-% extract received symbol from channel
+s *= gain;
+f=fopen("in.raw","wb");
+fwrite(f,s,"short");
+fclose(f);
+system(codec_cmd);
+f=fopen("out.raw","rb");
+s_ = fread(f,Inf,"short");
+fclose(f);
 
-a_ = lpcauto(s, lpc_order)
-w_ = atolsp(a_)
+% extract received symbols from channel and evaluate
+
+for f=1:frames
+  a_ = lpcauto(s_((f-1)*N+1:f*N), lpc_order);
+  w_ = atolsp(a_);
+  w__log = [w__log; w_];
+end
 
 figure(1);
 clf;
 subplot(211)
 plot(s)
+axis([1 Fs/10 -4000 4000]);
 subplot(212)
-plot(w,'g+',w_','r+');
-axis([0 lpc_order+1 0 pi])
+plot(s_);
+axis([1 Fs/10 -4000 4000]);
+
+figure(2)
+plot(w_log, 'g', w__log, 'r+')