comparison toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/synlpc.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function synWave = synlpc(aCoeff,source,sr,G,fr,fs,preemp)
2 % USAGE: synWave = synlpc(aCoeff,source,sr,G,fr,fs,preemp);
3 %
4 % This function synthesizes a (speech) signal based on a LPC (linear-
5 % predictive coding) model of the signal. The LPC coefficients are a
6 % short-time measure of the speech signal which describe the signal as the
7 % output of an all-pole filter. This all-pole filter provides a good
8 % description of the speech articulators; thus LPC analysis is often used in
9 % speech recognition and speech coding systems. The LPC analysis is done
10 % using the proclpc routine. This routine can be used to verify that the
11 % LPC analysis produces the correct answer, or as a synthesis stage after
12 % first modifying the LPC model.
13 %
14 % The results of LPC analysis are a new representation of the signal
15 % s(n) = G e(n) - sum from 1 to L a(i)s(n-i)
16 % where s(n) is the original data. a(i) and e(n) are the outputs of the LPC
17 % analysis with a(i) representing the LPC model. The e(n) term represents
18 % either the speech source's excitation, or the residual: the details of the
19 % signal that are not captured by the LPC coefficients. The G factor is a
20 % gain term.
21 %
22 % LPC synthesis produces a monaural sound vector (synWave) which is
23 % sampled at a sampling rate of "sr". The following parameters are mandatory
24 % aCoeff - The LPC analysis results, a(i). One column of L+1 numbers for each
25 % frame of data. The number of rows of aCoeff determines L.
26 % source - The LPC residual, e(n). One column of sr*fs samples representing
27 % the excitation or residual of the LPC filter.
28 % G - The LPC gain for each frame.
29 %
30 % The following parameters are optional and default to the indicated values.
31 % fr - Frame time increment, in ms. The LPC analysis is done starting every
32 % fr ms in time. Defaults to 20ms (50 LPC vectors a second)
33 % fs - Frame size in ms. The LPC analysis is done by windowing the speech
34 % data with a rectangular window that is fs ms long. Defaults to 30ms
35 % preemp - This variable is the epsilon in a digital one-zero filter which
36 % serves to preemphasize the speech signal and compensate for the 6dB
37 % per octave rolloff in the radiation function. Defaults to .9378.
38 %
39 % This code was graciously provided by:
40 % Delores Etter (University of Colorado, Boulder) and
41 % Professor Geoffrey Orsak (Southern Methodist University)
42 % It was first published in
43 % Orsak, G.C. et al. "Collaborative SP education using the Internet and
44 % MATLAB" IEEE SIGNAL PROCESSING MAGAZINE Nov. 1995. vol.12, no.6, pp.
45 % 23-32.
46 % Modified and debugging plots added by Kate Nguyen and Malcolm Slaney
47
48 % (c) 1998 Interval Research Corporation
49 % A more complete set of routines for LPC analysis can be found at
50 % http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
51
52
53
54 if (nargin < 5), fr = 20; end;
55 if (nargin < 6), fs = 30; end;
56 if (nargin < 7), preemp = .9378; end;
57
58 msfs = round(sr*fs/1000);
59 msfr = round(sr*fr/1000);
60 msoverlap = msfs - msfr;
61 ramp = [0:1/(msoverlap-1):1]';
62 [L1 nframe] = size(aCoeff); % L1 = 1+number of LPC coeffs
63
64 [row col] = size(source);
65 if(row==1 | col==1) % continous stream; must be
66 % windowed
67 postFilter = 0; duration = length(source); frameIndex = 1;
68 for sampleIndex=1:msfr:duration-msfs+1
69 resid(:,frameIndex) = source(sampleIndex:(sampleIndex+msfs-1))';
70 frameIndex = frameIndex+1;
71 end
72 else
73 postFilter = 1; resid = source;
74 end
75
76 [row col] = size(resid);
77 %if ~(col==nframe)
78 % error('synLPC: numbers of LPC frames and source frames do not match');
79 if col<nframe
80 nframe=col;
81 end
82
83 for frameIndex=1:nframe
84 % Calculate the filter response
85 % by evaluating the z-transform
86 % if 1
87 % gain=0;
88 % cft=0:(1/255):1;
89 % for index=1:L1-1
90 % gain = gain + aCoeff(index,frameIndex)*exp(-i*2*pi*cft).^index;
91 % end
92 % gain = abs(1./gain);
93 % spec(:,frameIndex) = 20*log10(gain(1:128))';
94 % plot(20*log10(gain));
95 % title(frameIndex);
96 % drawnow;
97 % end
98
99 % Calculate the filter response
100 % from the filter's impulse
101 % response (to check above).
102 % if 0
103 % impulseResponse = filter(1, aCoeff(:,frameIndex), [1 zeros(1,255)]);
104 % freqResp = 20*log10(abs(fft(impulseResponse)));
105 % plot(freqResp);
106 % end
107
108
109 A = aCoeff(:,frameIndex);
110 residFrame = resid(:,frameIndex)*G(frameIndex);
111 synFrame = filter(1, A', residFrame); % synthesize speech from LPC
112 % coeffs
113 if(frameIndex==1) % add synthesize frames using a
114 synWave = synFrame(1:msfr); % trapezoidal window
115 else
116 synWave = [synWave; overlap+synFrame(1:msoverlap).*ramp; ...
117 synFrame(msoverlap+1:msfr)];
118 end
119 if(frameIndex==nframe)
120 synWave = [synWave; synFrame(msfr+1:msfs)];
121 else
122 overlap = synFrame(msfr+1:msfs).*flipud(ramp);
123 end
124 %length(synWave)
125 end;
126
127 if(postFilter)
128 synWave = filter(1, [1 -preemp], synWave);
129 end
130