Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/MakeVowel.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 y=MakeVowel(len, pitch, sampleRate, f1, f2, f3) | |
2 % MakeVowel(len, pitch [, sampleRate, f1, f2, f3]) - Make a vowel with | |
3 % "len" samples and the given pitch. The sample rate defaults to | |
4 % be 22254.545454 Hz (the native Mactinosh Sampling Rate). The | |
5 % formant frequencies are f1, f2 & f3. Some common vowels are | |
6 % Vowel f1 f2 f3 | |
7 % /a/ 730 1090 2440 | |
8 % /i/ 270 2290 3010 | |
9 % /u/ 300 870 2240 | |
10 % | |
11 % The pitch variable can either be a scalar indicating the actual | |
12 % pitch frequency, or an array of impulse locations. Using an | |
13 % array of impulses allows this routine to compute vowels with | |
14 % varying pitch. | |
15 % | |
16 % Alternatively, f1 can be replaced with one of the following strings | |
17 % 'a', 'i', 'u' and the appropriate formant frequencies are | |
18 % automatically selected. | |
19 % Modified by R. Duda, 3/13/94 | |
20 | |
21 % (c) 1998 Interval Research Corporation | |
22 | |
23 if nargin < 2, | |
24 fprintf('Format: y = MakeVowel(len, pitch [, sampleRate, f1, f2, f3])\n'); | |
25 return; | |
26 end; | |
27 | |
28 if nargin < 6; f3 = 0; end; | |
29 if nargin < 5; f2 = 0; end; | |
30 if nargin < 4, | |
31 f1 = 0; | |
32 else | |
33 if isstr(f1) | |
34 if f1 == 'a' | f1 == '/a/' | |
35 f1=730; f2=1090; f3=2440; | |
36 elseif f1 == 'i' | f1 == '/i/' | |
37 f1=270; f2=2290; f3=3010; | |
38 elseif f1 == 'u' | f1 == '/u/' | |
39 f1=300; f2=870; f3=2240; | |
40 end | |
41 end; | |
42 end; | |
43 | |
44 if nargin < 3, | |
45 sampleRate = 22254.545454; | |
46 elseif sampleRate < 1000, % Apparently for test purposes | |
47 sampleRate = 22254.545454; | |
48 end; | |
49 | |
50 % GlottalPulses(pitch, fs, len) - Generate a stream of | |
51 % glottal pulses with the given pitch (in Hz) and sampling | |
52 % frequency (sampleRate). A vector of the requested length is returned. | |
53 y=zeros(1,len); | |
54 if length(pitch) > 1, % If true, use to determine points | |
55 points=pitch; % Check for valid sequence of points | |
56 if any(points~=sort(points)), | |
57 error('Values in pitch array must be in ascending order.') | |
58 end; | |
59 if points(1) < 1, | |
60 error('Values in pitch array cannot be less than 1.'); | |
61 end; | |
62 kmax=sum(points <= len); | |
63 if kmax == 0, | |
64 error('All values in pitch array exceed "len"; none should.'); | |
65 elseif kmax < length(points), | |
66 fprintf('Some values in pitch array exceed "len"; truncating.\n'); | |
67 points=points(1:kmax); | |
68 end; | |
69 else | |
70 points=1:sampleRate/pitch:len; | |
71 end; | |
72 indices=floor(points); | |
73 | |
74 % Use a triangular approximation to an impulse function. The important | |
75 % part is to keep the total amplitude the same. | |
76 y(indices) = (indices+1)-points; | |
77 y(indices+1) = points-indices; | |
78 | |
79 % GlottalFilter(x,fs) - Filter an impulse train and simulate the glottal | |
80 % transfer function. The sampling interval (sampleRate) is given in Hz. | |
81 % The filtering performed by this function is two first-order filters | |
82 % at 250Hz. | |
83 a = exp(-250*2*pi/sampleRate); | |
84 %y=filter([1,0,-1],[1,-2*a,a*a],y); % Not as good as one below.... | |
85 y=filter([1],[1,0,-a*a],y); | |
86 | |
87 % FormantFilter(input, f, fs) - Filter an input sequence to model one | |
88 % formant in a speech signal. The formant frequency (in Hz) is given | |
89 % by f and the bandwidth of the formant is a constant 50Hz. The | |
90 % sampling frequency in Hz is given by fs. | |
91 if f1 > 0 | |
92 cft = f1/sampleRate; | |
93 bw = 50; | |
94 q = f1/bw; | |
95 rho = exp(-pi * cft / q); | |
96 theta = 2 * pi * cft * sqrt(1-1/(4 * q*q)); | |
97 a2 = -2*rho*cos(theta); | |
98 a3 = rho*rho; | |
99 y=filter([1+a2+a3],[1,a2,a3],y); | |
100 end; | |
101 | |
102 % FormantFilter(input, f, fs) - Filter an input sequence to model one | |
103 % formant in a speech signal. The formant frequency (in Hz) is given | |
104 % by f and the bandwidth of the formant is a constant 50Hz. The | |
105 % sampling frequency in Hz is given by fs. | |
106 if f2 > 0 | |
107 cft = f2/sampleRate; | |
108 bw = 50; | |
109 q = f2/bw; | |
110 rho = exp(-pi * cft / q); | |
111 theta = 2 * pi * cft * sqrt(1-1/(4 * q*q)); | |
112 a2 = -2*rho*cos(theta); | |
113 a3 = rho*rho; | |
114 y=filter([1+a2+a3],[1,a2,a3],y); | |
115 end; | |
116 | |
117 % FormantFilter(input, f, fs) - Filter an input sequence to model one | |
118 % formant in a speech signal. The formant frequency (in Hz) is given | |
119 % by f and the bandwidth of the formant is a constant 50Hz. The | |
120 % sampling frequency in Hz is given by fs. | |
121 if f3 > 0 | |
122 cft = f3/sampleRate; | |
123 bw = 50; | |
124 q = f3/bw; | |
125 rho = exp(-pi * cft / q); | |
126 theta = 2 * pi * cft * sqrt(1-1/(4 * q*q)); | |
127 a2 = -2*rho*cos(theta); | |
128 a3 = rho*rho; | |
129 y=filter([1+a2+a3],[1,a2,a3],y); | |
130 end; |