scieee AI-readable full text Open interactive document viewer

Pattern modelling and pattern processing in image and speech signals

Sayols Baixeras, Narcís

Abstract

[ANGLÈS] In the context of signal processing, the aim of this memoir is to explore the pattern theory (PT) of Grenander and Mumford by focussing on two proof-of-concept applications, one dealing with images and the other with voice. The image application not only classifies the symmetry type of mosaics given a digital picture, but also can generate mosaic images with virtually any pattern decoration. The voice application classifies the phonemes in a digital voice recording and also can generate virtually unlimited variations on its pronunciation. These applications illustrate, in ways that are described in detail in the memoir, some of the key advantages of PT over and beyond the more familiar approaches known as pattern recognition and pattern classification. One important advantage is a sort of "division of labor": the construction of pattern models, which takes into account the data and is eminently theoretical, is separate from the pattern processing work (implementation, algorithms, programs). A second advantage is that pattern analysis (recognition, classification) and pattern synthesis (generating random instances that "look and feel" just as the world signals being modeled) become two sides of the same coin, in the sense that the same approach provides both. Actually, analysis is done via synthesis, because the inspiration for the proposed models comes from the data and recognition is resolved by using suitable plausibility rules in order to find the best pattern parameters fitting the data. Another advantage of the approach is its resilience in front of noisy and ambiguous samples. Finally, it is important to remark that pattern models can often be reused on data that are totally unrelated to the data that led to those models.

Full text

PROJECTE FINAL DE CARRERA Pattern modelling and pattern processing in image and speech signals Estudis: Enginyeria de Telecomunicació Autor: Narcís Sayols Baixeras Directors: Francesc Vallverdú Bayes Sebastià Xambó Descamps Any: 2011-2012 Universitat Polit` ecnica de Catalunya Escola T` ecnica Superior d’Enginyeria de Telecomunicacions de Barcelona Final Project at ETSETB Pattern modelling and pattern processing in image and speech signals Narc´ ıs Sayols Baixeras Advisor: Francesc Vallverd´ u Bay´ es Coadvisor: Sebasti` a Xamb´ o Descamps Departament de Teoria del Senyal i Comunicacions Abstract Key words: Information And Communication, Circuits Communication, information, Pattern theory, Wavelet analysis In the context of signal processing [31, 43, 34, 35], the aim of this memoir is to explore the pattern theory (PT) of Grenander and Mumford ([21, 38]) by focussing on two proof-of-concept applications, one dealing with images and the other with voice. The image application not only classifies the symmetry type of mosaics given a digital picture, but also can generate mosaic images with virtually any pattern decoration. The voice application classifies the phonemes in a digital voice recording and also can generate virtually unlimited variations on its pronunciation. These applications illustrate, in ways that are described in detail in the memoir, some of the key advantages of PT over and beyond the more familiar approaches known as pattern recognition and pattern classification ([11, 58, 2]). One important advantage is a sort of ‘division of labor’: the construction of pattern models, which takes into account the data and is eminently theoretical, is separate from the pattern processing work (implementation, algorithms, programs). A second advantage is that pattern analysis (recognition, classification) and pattern synthesis (generating random instances that ‘look and feel’ just as the world signals being modeled) become two sides of the same coin, in the sense that the same approach provides both. Actually, analysis is done via synthesis, because the inspiration for the proposed models comes from the data and recognition is resolved by using suitable plausibility rules in order to find the best pattern parameters fitting the data. Another advantage of the approach is its resilience in front of noisy and ambiguous samples. Finally, it is important to remark that pattern models can often be reused on data that are totally unrelated to the data that led to those models. The material in this memoir has been grouped into three parts. The first part, consisting of the first four chapters, is best described as a presentation of the theoretical background: Wavelet analysis (Ch. 1), Mosaic groups (Ch. 2), Phonetic techniques (Ch. 3) and Pattern Theory (Ch. 4). These chapters can be read independently, except that Ch. 4 occasionally refers to the preceding materials. The second part, consisting of two chapters, is focussed on the two applications referred to above: Wallpaper grup generation and classification (Ch. 5) and Phonetical recognition and pronunciation (Ch. 6). Chapter 5 depends on chapters 1 and 4, while Chapter 6 depends on chapters 3 and 4. For reference convenience, we include an appendix that summarizes the signal processing ideas and results that we use throughout. Contents Introduction 1 Chapter 1. Wavelet Theory 3 1.1. Introduction 3 1.2. Wavelet matrices 4 1.3. Wavelet systems 6 1.4. Biorthogonal wavelet systems 8 1.5. Multiresolutions and the Mallat algorithm 9 1.6. The Mallat algorithm for periodic data 12 1.7. Wavelet image compression 13 1.8. Wavelet channel coding 14 Chapter 2. Wallpaper groups 19 2.1. Euclidean plane isometries 19 2.2. Wallpaper groups 21 2.3. Wallpaper group notations 22 2.4. The 17 wallpaper groups 23 Chapter 3. Phonetic techniques 27 3.1. Introduction 27 3.2. Phonetic sounds 28 3.3. Markov models 29 3.4. Speech recognition 30 3.5. N-gram approximation 32 3.6. Feature extraction 33 3.7. Text Normalisation 34 3.8. Phonetic analysis 34 3.9. Prosodic analysis 35 3.10. Waveform synthesis 36 Chapter 4. Pattern Theory 37 4.1. Introduction 37 4.2. Pattern formalism 38 4.3. Bayesian probability 39 4.4. Pattern analysis and Pattern synthesis 41 vii viii CONTENTS 4.5. Machine translation model 41 Chapter 5. Wallpaper group algorithm 43 5.1. Mosaic generator 43 5.2. Decoration generator 43 5.3. Main cell creation 44 5.4. Tiling 45 5.5. Classification algorithm 45 5.6. Translational lattice detection 46 5.7. Classifying the wallpaper groups 47 5.8. Examples of the algorithm 48 5.9. Classification of generated mosaics 52 5.10. Matlab functions 60 Chapter 6. Speech classification 63 6.1. Classification algorithm 63 6.2. Speech segmentation 64 6.3. Phoneme recognition 67 6.4. Examples of the classification algorithm 68 6.5. Synthesis algorithm 69 6.6. Phoneme generator 70 6.7. Matlab functions 73 Conclusions and future work 77 Appendix A. Neural Networks 79 Appendix B. Mosaic’s Code 81 Appendix C. Speech Code 91 References 99 Introduction Signal processing [40, 43, 44, 23] is an area in engineering and applied mathematics that deals with operations on or analysis of signals to extract or modify information. Signals is a loosely defined term that includes a variety of forms, such as images, sounds, sensor data, control system signals, or telecommunication transmission systems (radio or television signals, for example). The importance of signal processing stems from the fact that it provides theoretical and practical tools to restore signals distorted by noise and, more generally, to cull information that is normally hidden in the raw data. In this context, the main focus of the present project is to probe the potential of pattern theory, an insightful framework which is capable, we believe, of shedding new light on old problems and of steering novel developments, theoretical and practical, in the years to come. Pattern theory [17, 18, 19, 21, 38] tries to analyze all types of signals (images, sounds, text, protein chains, etc.), using statistical models, mostly Bayesian, that describe them. Pattern theory in this sense is not to be confused with mere ‘pattern recognition’ or ‘pattern classification’, two important classic areas of signal processing which, in the approach we adopt, are dovetailed as pattern processing analysis and synthesis. In other words, while in those areas the analysis and synthesis of signals are two different problems, in pattern theory they are two aspects of the same model. A bonus aspect to be stressed here is that pattern theory models used in certain types of signals can often be reused in other areas. The root of this is that pattern theory facilitates the recognition of similar structures in different problems, so that useful models for a specific set of features in a signal may also be suitable for modeling features in other apparently unrelated signals. As a prerequisite basis for pattern theory, this project includes also a presentation of wavelet analysis [35, 45]. Wavelet theory amounts to a sweeping generalization of Fourier analysis that allows to ’solve’ local signals in both time and frequency. In recent years, this technique has become an indispensable tool for treating signals whose relevant characteristics are localized. In our study we consider the mathematical fundamentals together with examples of their use, for instance in compressing and filtering of signals. We view wavelet theory as a crucial ingredient for our future investigations in pattern theory and, more specifically, in image grammars, which are supposed to provide a suitable support for the description of images as a hierarchical structure of parts and relations among them. We also envision the use pattern and wavelet theory in medical imaging. In this vast area there is an increasing need for fast and reliable processing that can help clinical and radiology researchers and practitioners. So, we will try to model the 1 8 1. WAVELET THEORY Fig. 2. Daubechies scaling function (red) and Daubechies wavelet function (green). 1.4. Biorthogonal wavelet systems Definition. Let L=(aj i) and R=(bj i) be m×mg matrices with complex entries. We will say that (L,R) is a wavelet matrix pair of rang mand genus gif L(z)˜ R(z)=mIm and mg−1 X k=0 ar k= mg−1 X k=0 br k=mδr,0 Let (L,R) be a wavelet matrix pair and {ϕ, Φ, ψr,Ψr,r=1, ..., m−1}functions satisfying the scaling and wavelet equations ϕ(x)= mg−1 X k=0 a0 kϕ(mx −k) ψr= mg−1 X k=0 ar kϕ(mx −k) Φ(x)= mg−1 X k=0 b0 kΦ(mx −k) Ψr= mg−1 X k=0 br kΦ(mx −k) for r=1, ..., m−1. The functions {ϕ, Φ}and {ψr,Ψr,r=1, ..., m−1}are called biorthogonal scaling functions and biorthogonal wavelet functions, respectively. Definition. Abiorthogonal wavelet system,W[L,R], associated with a wavelet matrix pair (L,R) are the rescaling and translates of its biorthogonal scaling and wavelet functions W[L,R]={ϕk(x),Φk(x),k∈Z}∪{ψr jk,Ψr jk,j,k∈Z,j≥0,r=1, ..., m−1} 1.5. MULTIRESOLUTIONS AND THE MALLAT ALGORITHM 9 Observation. A biorthogonal wavelet system satisfies the following biorthogonality proprieties: ZϕkΦk0=δk,k0 ZϕkΨr jk0=0,r=1, ..., m−1 Zψr jkΦk0=0,r=1, ..., m−1 Zψr jkΨr0 j0k0=δr,r0δj,j0δk,k0 Theorem 3. If (L,R) is a wavelet matrix pair, then there exists an associated biorthogonal wavelet system {ϕk, ψr jk,Φk,Ψr jk}and, moreover, for any f∈L2(R), f(x)= +∞ X k=−∞hf, ϕkiΦk(x)+ m−1 X r=1 +∞ X j=0 +∞ X k=−∞hf, ψr jkiΨr jk(x) where the convergence is in the weak L2sense. Example. (1) Wavelet matrices: Every wavelet matrix Adefines a wavelet matrix pair (A,A). An example could be the Haar matrix of rank 2 HL=HR= 1 1 −1 1 ! (2) Rank 2and genus 2:Here is an example of a wavelet matrix pair of rank m=2 and genus g=2: L= 1/3 2/3 2/3 1/3 −1−2 2 1 ! R= −1 2 2 −1 1/3−2/3 2/3−1/3! (3) Daubechies type, genus 3: A complex wavelet matrix pair for m=2, g=3. L= −0.13 +0.07i0.11 +0.21i1.02 +0.14i1.02 −0.14i0.11 −0.21i−0.13 −0.07i −0.13 −0.07i−0.11 +0.21i1.02 −0.14i−1.02 −0.14i0.11 +0.21i0.13 −0.07i! R= −0.13 −0.07i0.11 −0.21i1.02 −0.14i1.02 +0.14i0.11 +0.21i−0.13 +0.07i −0.13 +0.07i−0.11 −0.21i1.02 +0.14i−1.02 +0.14i0.11 −0.21i0.13 +0.07i! 1.5. Multiresolutions and the Mallat algorithm Let A= a0a1... a2g−1 b0b1... b2g−1! be a wavelet matrix of rank 2 and genus g, and let W={ϕk, ψjk}be the corresponding orthonormal wavelet system. Introduce ϕjk =2j/2ϕ(2jx−k) 10 1. WAVELET THEORY the rescaling and translations of the scaling function ϕ(x). We assume orthonormality for convenience of exposition, although the analysis we present here is valid in general case of tight frames. For j∈Z, define the vector space Vj=Span{ϕjk |k∈Z}1 It can be proved that L2(R)=∪jVj, so we have the orthogonal projections Pj:L2(R)→Vj. Hence, given a function f∈L2(R), Pjfconverges to f, as j→ ∞, in the L2norm and its coefficients are given by the formula Pjf(x)= +∞ X k=−∞ cjkϕjk(x) where cjk =ZR f(x)ϕjk(x)dx since the ϕjk’s are a tight frame for Vj. If we let Wjdenote the orthogonal complement of Vjin Vj+1, then for a fixed J∈Z+ V0⊕W0⊕···⊕WJ−1=VJ Moreover, if f(x)= +∞ X k=−∞ c0kϕ0k(x)+ +∞ X j=0 +∞ X k=−∞ djkψjk(x) for f∈L2(R), then we obtain +∞ X k=−∞ cJkϕJk(x)= +∞ X k=−∞ c0kϕ0k(x)+ J−1 X j=0 +∞ X k=−∞ djkψjk(x) So, one can determine the coefficients on the right-hand side of the previous equation in terms of the coefficients on the left-hand side, and conversely. This is the Mallat algorithm. Here is how the Mallat algorithm works: Suppose we are given an expansion of the form fJ= +∞ X k=−∞ cJkϕJk(x), and we want to determine the coefficients of the corresponding lower-order expansion of the type fJ= +∞ X k=−∞ c0kϕ0k(x)+ J−1 X j=0 +∞ X k=−∞ djkψjk(x) We will do this successively in stages. First, we consider the decomposition VJ−1⊕WJ−1=VJ, and determine the expansion coefficients in VJ−1and WJ−1for the coefficients in VJ. Thus, we can write XcJ−1,kϕJ−1,k+XdJ−1,kψJ−1,k=XcJ,kϕJ,k 1The span of Sis defined as the set of all linear combinations, not necessarily finite, of elements of S. 1.5. MULTIRESOLUTIONS AND THE MALLAT ALGORITHM 11 and try to determine the pair {cJ−1,k,dJ−1,k}in terms of the {cJ,k}, and conversely. First, multiply the last equation by ϕJ−1,land integrate. We obtain: cJ−1,l=XcJ,kZϕJ,k(x)ϕJ−1,l(x)dx Now use the basic scaling equation and wavelet defining equation to write ϕJ−1,l(x)=1 √2 2g−1 X r=0 arϕJ,r+2l(x) (*) ψJ−1,l(x)=1 √2 2g−1 X r=0 brϕJ,r+2l(x) (**) Substituting (*) into (**) and using the orthogonality, we obtain cJ−1,l=1 √2X r cJ,rar−2l. Similarly, we find that dJ−1,l=1 √2X r cJ,rbr−2l More generally, by expressing VJ−2⊕WJ−2=VJ−1 . . . Vj−1⊕Wj−1=Vj . . . V0⊕W0=V1 we obtain recursive formulae for the coefficients {c0k,djk,i≤j≤J−1}, in terms of the coefficients {cjk}, given by cj−1,l=1 √2X r cj,rar−2l dj−1,l=1 √2X r cj,rbr−2l for 0 ≤j≤J. The inverses of these formulae can be derived in a similar way. We simply consider Vj−1⊕Wj−1=Vj and suppose that we know the coefficients of the expression in Vj−1and Wj−1, and we want to determinate the coefficients in the expression in Vj. Using a similar argument, we obtain the inductive formula cj,k=1 √2X k cj−1,kal−2k+dj−1,kbl−2k for j=1, ..., J. 12 1. WAVELET THEORY 1.6. The Mallat algorithm for periodic data The Mallat algorithm gives a linear mapping VJ M →V0⊕W0⊕... ⊕WJ−1 and its inverse. These spaces are all infinite dimensional. We want to consider a special case where we replace each space Vjand Wjby its periodic analogue, thereby providing a finite-dimensional version of the Mallat algorithm, which is what is needed in practise. We define the periodic scaling and wavelet spaces with period Las VL j=nXcj,kϕjk |cj,k=cj,k+L,k∈Zo WL j=nXdj,kψjk |dj,k=dj,k+L,k∈Zo if we assume that Lis even, then the Mallat algorithm maps naturally: VL j≃RL ↓M↓H⊕G VL j−1⊕WL j−1≃RL/2⊕RL/2 and we see that the linear mapping Mcan be represented by a pair of matrices Hand G, which are illustrated for the case that g=2 and L=8: H= h0h1h2h30000 0 0 h0h1h2h30 0 0000h0h1h2h3 h2h30000h0h1  and Gwill be similar with entries {gk}replacing {hk}. Here we assume that the wavelet matrix Ahas the form A= a0a1a2a3 b0b1b2b3!=√2 h0h1h2h3 g0g1g2g3! since the vectors (hk) and (gk) are what appear explicitly in the Mallat algorithm. The inverse Mallat algorithm will have a similar matrix representation. Observation. The implementation of the Mallat algorithm is not carried out by matrix multiplication, but by a convolution with the vectors h=(h0,h1,h2,h3) and g=(g1,g2,g3,g4) followed by a downsampling operator. In this case, we only take the even terms. This is schematically described in Figure 3. G H ↓2 ↓2Level 1 coefficients Level 2 coefficients Level 3 coefficients G H G H ↓2 ↓2 ↓2 ↓2 Fig. 3. Discrete wavelet transform scheme 1.7. WAVELET IMAGE COMPRESSION 13 Let L=2Kand let s0, ..., s2K−1a sequence of numbers, then H(s0, ..., s2K−1)=(sl0, ..., slK−1)∈Rk≃VL j−1and G(s0, ..., s2K−1)=(sh0, ..., shK−1)∈Rk≃WL j−1, the low-pass and high-pass outputs at the Mallat mapping M, respectively, are calculated as follows. Assume g=2, then sl0= 3 X l=0 slhlsh0= 3 X l=0 slgl sl1= 5 X l=2 slhl−2sh1= 5 X l=2 slgl−2 . . .. . . slK−1= 2K+1 X l=2K−2 slhl−2K−2shK−1= 2K+1 X l=2K−2 slgl−2K−2 Observation. For the last sum, we extend the sequence periodically by setting s0=s2Kand s1=s2K+1. Definition. Let Abe a wavelet matrix of rank 2 (x0, ..., x2N−1)∈R2N. Let Jbe an integer such that 1 ≤J≤N. The discrete wavelet transform (DWT) of order J defined by Ais a linear mapping R2NN →R2N−1⊕R2N−2⊕···⊕ R2N−J+1⊕R2N−J⊕R2N−J ≃ ≃ ≃ ≃ ≃ ≃ VL N N →WL N−1⊕WL 2N−2⊕···⊕ WL 2N−J+1⊕WL 2N−J⊕VL 2N−J where we identify the vector spaces R2jwith the periodic scaling and wavelet spaces of periods 2jas indicated above. The mapping Mis given by the Mallat algorithm. The scheme is sketched in Figure 3. Observation. It is not hard to see that the computational complexity of the discrete wavelet transform is O(N). Indeed, at every level the convolution involves Lproducts and Lsummands, so the total number of operations at any level is bounded by 2LN. Since at every level we operate on half the number of points as at the previous level, and (1 +1 2+... +1 2J)<2, we see that we at most double the constant by going to a finite number Jof levels. 1.7. Wavelet image compression Today, the most successful general image compression method is based on the two dimensional product basis constructed from the Daubechies wavelet matrix D3and their biorthogonal variations. Recall that D3 provides a low-pass representation of polynomials of degree less than 3. From this it follows that the product basis provides a low-pass expansion of polynomial functions of two variables, say xand y, of degree less than 3. These quadric surfaces are good models for light reflected from smooth surfaces such as walls, or the cheeks and forehead of a face. The ability to represent reflected light energy that produces quadric surfaces in a digital image means that this transform is effective in concentrating a large fraction of the image energy in a small number of low-pass (“near dc”) transform coefficients. The Figure 4 displays the scaling and wavelet functions ϕ(x) and ψ(x). 14 1. WAVELET THEORY Fig. 4. Daubechies scaling function ϕfor D3(m=2,g=3) (blue). Daubechies wavelet function ψfor D3(m=2,g=3) (red). The filters that correspond to these basis functions transform the original image into four components: the low-low, low-high, high-low and high-high parts of the transform. Each of these outputs contains one quarter as many coefficients as the input image, so the total number of output coefficients is the same as the number of input coefficients. This fact makes it possible to display the transformed output as an image also by scaling all outputs to fall in the range of the input pixel values –say the range 0 to 255 for an 8 bit gray-scale image. The four images in the four subsquares of Figure 5 were constructed in this way. They illustrate the first stage in applying the wavelet transform for compression, and correspond to the low-low, low-high,high-low, and high-high pass components of the original image (which looks like the low-low quadrant in the upper left). 1.8. Wavelet channel coding The user of a digital communication system will primarily be concerned with the bit rate and the error rate of the communication channel. The communication channel is controlled by allocating power and bandwidth, both of which are precious resources. Every communication channel experiences noise. Additive white Gaussian noise (AWGN) is often a good first approximation because it results from specific applications. The communication system designer would like to achieve the objectives of high bit rate and low error rate with a minimum of power consumption and bandwidth requirements. These objectives are inconsistent; trade-offs must be made that prefer high bit rate to low error rate or low error rate to high bit rate; low power requirements to low bandwidth or low bandwidth to low power requirements. These trade-offs determine the type of modulation and error correction that will be selected. Wavelet channel coding (WCC) provides a systematic conceptual and design method for making these tradeoffs through software selection within a common chipset-based hardware framework. 1.8. WAVELET CHANNEL CODING 15 Fig. 5. Four quadrants of a level-1 wavelet decomposition of a Liechestein castle image. The advantages of wavelet channel coding stem from the combination of the exact orthogonality of wavelet codewords, the spreading of message symbol information throughout the codeword symbols, and the ability to utilise soft decisions to decode wavelet channel coded symbols. The main properties of WCC are summarised in the following list: (1) Wavelet Channel Coding is a new class of coding algorithms. (2) WCC offers a systematic and simple approach to the full range of coding problems, from low rate, power efficient codes to high rate, bandwidth efficient codes. (3) Wavelet Channel Coding can be applied in a block coding mode or in a trellis coding mode. (4) WCC codewords are strictly orthogonal. (5) WCC codewords have small correlations for non-codeword offsets. (6) WCC coding employs robust soft decision decoding. (7) WCC codes can be arbitrarily long. 16 1. WAVELET THEORY (8) WCC codewords have desirable Hamming distance properties and provide good error correction capability. (9) WCC codes can be efficiently coded and decoded with simple VLSI circuits. (10) Synchronisation can be performed by correlation matching. (11) Analysis and computer simulations show that WCC with arbitrary length wavelets achieves the AWGN performance of coherent BPSK2. When compared under a constant channel rate criterion, WCC provides coding gains of approximately 10 log2(mg +1) dB. On pulsed interference and flat fading channels, WCC outperforms BPSK with gains that are dependent on the wavelet sequence length. Example. Wavelet Channel Coding for m=2 For the purpose of illustration, let a message x1,x2, ..., xn, ... consist of a sequence of bits represented by the signed units {+1,−1}. Let A= a0a1... a2g−1 b0b1... b2g−1! be a wavelet matrix of rank 2 and genus gand let aand bdenote the scaling and wavelet vectors of this wavelet matrix, respectively (first and second rows of A, or, in engineering language, the low and high pass filters of the 2-band filter bank A). Because the rows of A are mutually orthogonal when translated by steps of two, we can take advantage of the orthogonality of the filters (vectors) aand bto code at a rate of two message bits per 2kclock pulses, where 1 <k<log22g. Message bits with odd sequence number will be coded using the waveform (a0, ..., a2g−1) and message bits with even sequence number will be coded using the waveform (b0, ..., b2g−1). 1234... 2g2g+1 2g+2... x1a0x1a1x1a2x1a3... x1a2g−1... ... ... x2b0x2b1x2b2x2b3... x2b2g−1... ... ... x3a0x3a1... x3a2g−3x3a2g−2x3a2g−1... x4b0x4b1... x4b2g−3x4b2g−2x4b2g−1... ... . . .. . .. . .. . . y1y2y3y4... y2gy2g+1y2g+2... Table 1. Wavelet channel coding example. The coding procedure is illustrated in Table 1 for a system with maximally overlapped wavelet sequences. This corresponds to the case where the code rate is one information bit per WCC symbol (i.e. k=1 above). The sequence of clock pulses is arranged above the upper rule of the table, and the sequence of transmitted symbols ynis shown below the lower rule of the table. The encoding of each message bit xnis shown in the nth row below the upper rule. Note that for odd nthe encoding begins on the nth clock pulse and that for even nthe encoding begins on the (n−1)th clock pulse. The symbol ynis equal to the sum of the nth column of encoded message bit values and is therefore not restricted to the values ±1. The formula for computing the symbol ynto be transmitted at the nth clock pulse is yn=X k{x2k+1an−2k−1+x2k+2bn−2k−1} 2BPSK refers to Binary Phase Shift Keying and it is a modulation technique 1.8. WAVELET CHANNEL CODING 17 Some observations are in order: (1) It is evident that code rates as small as 1/gcan be achieved by varying the overlap of the wavelet sequences; in the limit where the code rate is 1/g, the wavelet sequences are non overlapped but adjacent. (2) When flat wavelet matrices are used, the WC encoded symbols that are generated by the WCC algorithm are binomially distributed. 24 2. WALLPAPER GROUPS 2.4.1. p1. This is the simplest symmetry group. It consists only of translations. There are neither reflections, glide-reflections, nor rotations. The two translation axes may be inclined at any angle to each other. 2.4.2. pm. This group contains reflections. The axes of reflection are parallel to one axis of translation and perpendicular to the other axis of translation. The lattice is rectangular. There are neither rotations nor glide reflections. 2.4.3. pg. This group contains glide reflections. The direction of the glide reflection is parallel to one axis of translation and perpendicular to the other axis of translation. There are neither rotations nor reflections. 2.4.4. cm. This group contains reflections and glide reflections with parallel axes. There are no rotations in this group. The translations may be inclined at any angle to each other, but the axes of the reflections bisect the angle formed by the translations, so the lattice is rhombic. 2.4.5. p2. This group differs only from p1 in that it contains πrotations, that is, rotations of order 2. As in all symmetry groups there are translations, but there are no reflections nor glide reflections. The two translations axes may be inclined at any angle to each other. 2.4.6. pgg. This group contains no reflections, but it has glide-reflections and πrotations. There are perpendicular axes for the glide reflections, and the rotation centers do not lie on the axes. 2.4.7. pmg. This group contains reflections, and glide reflections which are perpendicular to the reflection axes. It has rotations of order 2 on the glide axes, halfway between the reflection axes. 2.4.8. pmm. This symmetry group contains perpendicular axes of reflection, with πrotations where the axes intersect. 2.4.9. cmm. This group has perpendicular reflection axes, as does the group pmm, but it also has rotations of order 2. The centers of the rotations do not lie on the reflection axes. 2.4.10. p3. This is the simplest group that contains a 2π 3-rotation, that is, a rotation of order 3. It has no reflections or glide reflections. 2.4.11. p31m. This group contains reflections (whose axes are inclined at π 3to one another) and rotations of order 3. Some of the centers of rotation lie on the reflection axes, and some do not. There are some glide-reflections. 2.4.12. p3m1. This group is similar to the last in that it contains reflections and order-3 rotations. The axes of the reflections are again inclined at π 3to one another, but for this group all of the centers of rotation do lie on the reflection axes. There are some glide-reflections. 2.4.13. p4. This group has a pi 2rotation, that is, a rotation of order 4. It also has rotations of order 2. The centers of the order-2 rotations are midway between the centers of the order-4rotations. There are no reflections. 2.4. THE 17 WALLPAPER GROUPS 25 2.4.14. p4g. Like p4, this group contains reflections and rotations of orders 2 and 4. There are two perpendicular reflections axis passing through each order 2 rotation. However, the order 4 rotation centers do not lie on any reflection axis. There are four directions of glide reflection. 2.4.15. p4m. This group also has both order 2 and order 4 rotations. This group has four axes of reflection. The axes of reflection are inclined to each other by π 4so that four axes of reflection pass through each order 4 rotation center. Every rotation center lies on some reflection axes. There are also two glide reflections passing through each order 2 rotation, with axes at π 4to the reflection axes. 2.4.16. p6. This group contains π 3rotations, that is, rotations of order 6. It also contains rotations of orders 2 and 3, but no reflections or glide-reflections. 2.4.17. p6m. This complex group has rotations of order 2, 3, and 6 as well as reflections. The axes of reflection meet at all the centers of rotation. At the centers of the order 6 rotations, six reflection axes meet and are inclined at π 6to one another. There are some glide reflections. Crist. notation Orbiforl notation Lattice Rotation Order Reflection Order p1◦parallelogram 1 none pm ∗∗ rectangle 1 parallel pg ×× rectangle 1 none cm ∗× rhombus 1 parallel p2 2222 parallelogram 2 none pgg 22×rectangle 2 none pmg 22∗rectangle 2 parallel pmm ∗2222 rectangle 2 90° cmm 2∗22 rhombus 2 90° p3 333 hexagonal 3 none p31m3∗3 hexagonal 300 60° p3m1∗333 hexagonal 3060° p4 442 square 4 none p4g4∗2 square 400 90° p4m∗442 square 4045° p6 632 hexagonal 6 none p6m∗632 hexagonal 6 30° Table 1. Properties of all 17 wallpaper groups. 0=all rotation centers lie on reflection axes. 00 =not all rotation centers on reflection axes. 26 2. WALLPAPER GROUPS p1p2pm pg cm pmm pmg pgg cmm p4p4mp4g p3p3m1p31mp6p6m (p1) ◦ (p211) 2222 (p1m1) ∗∗ (p1g1) ×× (c1m1) ∗× (p2mm) ∗2222 (p2mg) 22∗ (p2gg) 22× (c2mm) 2∗22 (p4) 442 (p4mm) ∗442 (p4gm) 4∗2 (p3) 333 (p3m1) ∗333 (p31m) 3∗3 (p6) 632 (p6mm) ∗632 Centers of Rotations 2-fold 3-fold 4-fold 6-fold axis of rflection axis of glide reflection outline of lattice outline of centered cell Fig. 2. The 17 wallpaper groups main cell with all their rotational centers, reflections and glide reflections. Chapter 3 Phonetic techniques 3.1. Introduction In this chapter we assemble key materials about phonetics that are needed for the application in Chapter 6. These materials are basically all the terms used in speech processing explained in section 3.2. We also present a simple version of some modern techniques used in speech signals. First, in sections 3.3 to 3.6, we explain a typical speech recogniser. After that, in the last sections, we consider speech synthesis and explain how a concatenative synthesiser works. The principal references used in this chapter are [26, 15, 28]. Nowadays the speech recognition systems are best understood by analysing three aspects separately (see [28, 26]): feature extraction,acoustic model and language model. Most techniques to extract features from the signals are aimed at improving the audio quality before recognition, as a way of strengthening the recognition process. These methods are basically Mel Frequency Cepstral Coefficients (MFCC) (See section 3.6) and Perceptual Linear Prediction (PLP) [10, 24, 26, 22, 15, 36, 28]. Other techniques that have been used recently for feature extraction implement wavelet techniques. These systems use the local properties of wavelet transform to extract the energies of each subband of frequencies and use these energies as feature signatures [32, 13]. The second aspect is the acoustic model, whose role is to create statistical representations of the phonemes and stitch them together to form words. Most common recognisers use HMM models (See section 3.4). There are several good references that use this method, such as [27, 16, 26, 36, 15, 28]. Other techniques use artificial neural networks (see Appendix A) to classify phonemes and create words from them [30, 56]. Finally, the third aspect tries to identify the most probable sequence of words in the speech signal. The most common approach is the N-gram model (See section 3.5). Some works that use this model are [57, 26, 15, 28]. There are mainly three types of speech synthesisers depending on how the waveform is created. These types are concatenative synthesisers,formant synthesisers and articulatory synthesisers. Concatenative synthesis generates a speech waveform by concatenating a sequence of diphones (See section 3.10) from a database. After that, it is necessary to adjust the waveform in order to obtain speech with an acceptable prosody. We refer to [53, 52, 26] for description of some modern synthesisers. 27 28 3. PHONETIC TECHNIQUES Formant synthesis tries to mimic the speech spectrogram by generating the formants (See section 3.2) of the different phonemes. The most famous synthesisers of this type are Klatt’s formant synthesiser and its successors, including [1]. To know more about them see [26]. Finally, articulatory synthesis attempts to generate speech by modeling the vocal tract as an open tube (cf. [12, 26]). 3.2. Phonetic sounds Humans produce sounds called phonemes by expelling air from the lungs that resonates among the vocal tract (laryngeal cavity, the pharynx, the oral cavity, and the nasal cavity). Phonemes are usually divided into consonants and vowels. Consonants are usually created by blocking or restricting the airflow from the lungs. Consonants can be voiced or unvoiced1. Vowels have less obstructions and for our purposes they are voiced. In this section we will describe some properties of the speech signals mostly related to the frequency domain. First, we start by describing the bandwidth of sound signals. For practical purposes, the sounds which can be detected by human ears are below 10000 Hz. So, sampling rates used in speech processing are of the order of 16000 Hz2 In terms of frequency, the most important term is fundamental frequency (often written as F0), which is the natural frequency of the vocal folds. This frequency, as we will see in section 3.9, depends on the utterance intonation. Fig. 1. Graph of the mel scale funtion. Another term related with the fundamental frequency is the pitch. The pitch of a sound is the acoustic perception of (the fundamental) frequency and hence it depends on the properties of human hearing. There several several variants of empirical functions to represent pitch in terms of frequency. One that is widely 1If the vocal folds vibrate when the sound is created, the sound is said to be voiced and otherwise unvoiced 2Telephone signals use a bandwidth of 8000 Hz. 3.3. MARKOV MODELS 29 used, and which is sufficient for our needs, is the mel scale m(f) (see Figure 1), which is defined by the formula m(f)=1127 ln(1 +f 700). This empirical function reflects the fact that equal increments of pitch correspond to equal ratios of frequency and is normalized so that m(0) =0 and m(1000) =1000. Most speech signals are described using spectrograms. An spectrogram is a representation that how the frequency of a sound changes among the time. Zones with darken colours are zones with more power and zones with soft colors are frequencies with less power. An example can be seen in figure 2. Fig. 2. Spectrogram of a catalan word NEN. The x-axis is time in ms and the y-axis is frequency in Hz. Each dark band in the figure is called formant. A formant is a frequency band that is amplified by the vocal tract. Since different phonemes has formants in different position they can be used as features in recognition such as in LPC models. 3.3. Markov models Before explaining a recognition system we must explain Markov models which are use in it. Definition. Let Ωbe a finite set of states. A sequence {X0,X1, ...}of random variables taking values in Ωis said to be a Markov chain if it satisfies the Markov condition: P(Xn=in|X0=i0, ..., Xn−1=in−1)=P(Xn=in|Xn−1=in−1) for all n≥1 and all i0,i1, ..., in∈Ω. Definition. The Markov chain is said homogeneous if, for all n≥1 and all i,j∈Ω, P(Xn=j|Xn−1=i)=P(X1=j|X0=i) 30 3. PHONETIC TECHNIQUES Markov chains will always be assumed homogeneous unless otherwise specified. Definition. In this case, the transition matrix Q of the chain is defined as the |Ω|×|Ω|matrix of all transition probabilities Q(i,j)=ai j =P(X1=j|X0=i). The probabilities ai j are called transition probabilities. Proposition. The matrix Qngives the law of Xnfor the chain starting at X0=i P(Xn=j|X0=i)=Qn(i,j) Definition. AHidden Markov Model is a Markov chain where each state has associated a probability density function bj(θt) which determines the probability that this state generates θtat time t(the model is hidden because any state could have emitted the observed value). bjare called observation probability. Observation. The probability density function can be continuous or discrete. In our case (speech case) bj is usually a Gaussian distribution with a diagonal covariance matrix. This model generates a sequence of observed states θ=θ0, θ1, ..., θT−1because at every time tonly one state emits an observation. The set of all the sequences can be represented as routes via an scheme similar as in figure 3. In this scheme the ( j,t)−th node corresponds to the hypothesis that the observation θtwas generated by the state j. Two nodes (i,t−1) and ( j,t) are connected if and only if ai j >0. State j Time t θ0θ1θ2θ3θ4 0 1 2 3 Fig. 3. Hidden Markov Model, showing the finite state machine for the HMM (left), the observation sequence (top), and all the possible routes through the trellis (arrowed lines) 3.4. Speech recognition As we have said before we will explain a simpled version of a speech recogniser based in a Hidden Markov model (HMM). To describe this recogniser we will follow [15]. 3.4. SPEECH RECOGNITION 31 First, this type of speech recogniser converts an input audio waveform into a sequence of fixed size acoustic vectors Y1:N=(y1, ..., yN). This process is called feature extraction (See section 3.6). After that, the decoder tries to find the most probably sequence of words W1:M=(w1, ..., wM) which have generated the input sequence Y. In other words, the decoder attempts to find ˆ W=arg max{P(W|Y)} Now, as it is difficult to calculate this probability, we use the Bayesian rule to transform this equation into ˆ W=arg max{P(Y|W)P(W)}(*) As each spoken word wis decomposed into a sequence of Kwbasic sounds called basic phonemes, the possibility of different pronunciations has to be taken into account. So, let q(w)=q1, ..., qKwbe a pronunciation of the word w. Thus, the likelihood P(Y|W) can be expressed as P(Y|W)=X Q P(Y|Q)P(Q|W) where the summation is over all valid pronunciation sequences for Wand Q=q(w1), ..., q(wM)is a particular sequence of pronunciations. So if we suppose independence, P(Q|W)= M Y l=1 P(q(wl)|wl) where each q(wl)is a valid pronunciation for word wl. At this point, each base phoneme qis represented by a continuous density HMM. Once taken the composite HMM Qformed by all the base phonemes q(w1), ..., q(wM), the acoustic likelihood is given by the equation P(Y|Q)=X θ P(θ, Y|Q) where θ=θ0, ..., θT+1is a state sequence through the composite model and P(θ, Y|Q)=aθ0,θ1 T Y t=1 bθt(yt)aθtθt+1 The acoustic model parameters λ=[{ai j},{bj}] can be efficiently estimated using the forward-backward algorithm which is an example of expectation-maximisation algorithm described in [38]. Observation. The problem with decomposing the spoken words into a sequence of non-related phonemes is that it fails to capture the variations of this phoneme produced by the previous and following phonemes. So to eliminate this problem, more complex speech recognisers use triphonemes which is a unique model for every trio of phonemes. 32 3. PHONETIC TECHNIQUES 3.5. N-gram approximation In the equation (*) we have computed the first probability. In this section we will focus in the second term. The probability of word sequence W=w1, ..., wKis given by P(W)= K Y k=1 P(wk|w1, ..., wk−1) For recognition the previous product is truncated to N−1 words to form an N-gram language model P(W)= K Y k=1 P(wk|wk−N+1, ..., wk−1) where Nis typically in the range 2 −4. Definition. Given a finite alphabet S(in our case the set of all words), a language on S is a set of probability distributions Pnon the set of strings Ωnof length nfor all n≥1. To characterise a N-gram model we give three equivalent conditions Proposition. Let ΩNbe the space of strings a1, ..., aNof length N,ai’s being taken from a finite alphabet S. Consider a probability distribution P:ΩN→R+. Fix an integer n≥1. The following conditions are equivalent: (1) Conditional factorisation.Phas the form P(a1, ..., aN)=P0(a1, ..., an−1) N−n Y k=0 P1(ak+n|ak+1, ..., ak+n−1) for suitable P0and P1. (2) Exponential form. P(a1, ..., aN)=1 Zexp −X σ∈Ωn λσ#occ(σ, a1, ..., aN) for suitable λσ’s, where Ωnis the set of strings of length nand #occ(σ, a1, ..., aN) denotes the number of occurrences of the string σin a1, ...aN. Here we allow λσ=∞in case no strings of positive probability contain σ. (3) Markov property. For all I=(k+1, ..., k+n−1) of length n−1, let a(I)=ak+1, ...., ak+n−1; then P(a1, ..., aN|a(I)) =P1(a1, ..., ak|a(I))P2(ak+n, ..., aN|a(I)) which means that a (before I) and a (after I) are conditionally independent given a(I). Using the third equivalence, we can treat every Ias an independent sequence and using Markov chains properties we can calculate the probabilities. The N-gram probabilities are estimated from training text by counting N-gram occurrences. For example, let C(wk,wk−1,wk−2) represent the number of occurrences of the words wk−2,wk−1,wk, then P(wk|wk−2,wk−1)≃C(wk,wk−1,wk−2) C(wk−1,wk−2) 3.6. FEATURE EXTRACTION 33 3.6. Feature extraction In this section we will explain the features of the speech recognition. There are a lot of possible feature representations but the most common is the mel frequency cepstral coefficents (MFCC). In this sections we will describe a method to extract these coefficients. To do it, we will follow [28]. First, the audio signal is convert into a digital signal. After that, the whole process is shown in figure 4. 1 energy feature 12 MFCC 12 ∆ MFCC 12 ∆∆ MFCC 1 energy 1 ∆ energy 1 ∆∆ energy 12 MFCC coefficients preemphasis window DFT Mel filter bank log IDFT deltas energy Speech signal Fig. 4. MFCC extraction process from a digital speech signal. The first step is a high frequency filter to augment the high frequencies of the signal to make information of this part of the spectrum easier to detect. The preemphasis filter is a first order filter with an equation y(n)=x(n)−αx(n−1) with 0.9<α<1. As speech signals are generally non-stationary, it is common to extract the spectral features from a small part of the signal. If this part of the signal is sufficiently small, it can be supposed that the signal is stationary. To do it, the next step of the process is to run a window across the speech signal. This process can be characterized by three parameters. The width in time of the window, the offset between successive windowed samples (frames), and the shape of the window. In MFCC process it is often used the Hamming window, which decrease the value of the boundaries to zero to avoid discontinuities. The goal of the upper branch of the figure 4 it is to calculate spectral features which are some values of the cepstral function. It is common to take as a features the first 12 cepstral values of the signal. Definition. The Cepstral function c(n) is formally defined as the inverse DFT of the log magnitude of the DFT of a signal x(n). In other words, c(n)= N−1 X k=0 log  N−1 X n=0 x(n)e−i2πkn/Nei2πkn/N So, the upper branch of the scheme calculates is a sequence of process that their goal is to calculate the cepstral function and take its first 12 values. Observation. As human hearing is less sensitive to higher frequencies (¿1000Hz) than low frequencies, we pass the signal to a a bank of filters which model a mapping between hertz and mel scale to performance this human property3. Now, we have 12 cepstral coefficients for each frame. We also calculate in the lower branch the energy of the frame which can be defined as E=PN n=1x(n)2. 3See section 3.2. 40 4. PATTERN THEORY M 12346 1mgd1mgd1mg1mg mg 1m p1pm pg cm pmm p2 pmg pgg cmm p3p3m1p31mp4p4m p4g p6p6m Fig. 2. Symmetry patterns of plane mosaics. The variables are denoted r=order of the rotation symmetry (for r=1,2,3,4,6), m=mirror, g=glide mirror and d=diagonal mirror. Mosaic symmetry patterns corresponds to the paths joining Mand one of the seventeen leaves. A mosaic pattern is a mosaic symmetry pattern together with an arbitrary decoration of the fundamental cell. Most decorations can themselves be described as patterns, as it will illustrates later in examples. If Mrepresents a mosaic image (observable) to be classified (pattern analysis), all other vertices are hidden variables whose values have to be determined. In synthesis (sampling), a case is selected at random, and a tile decoration, and the resulting mosaic is produced as a picture. that can be applied to practical problems. This fact is an important characteristic of pattern theory: It allows to treat modeling separately from pattern processing. The problem we wish to solve is to infer the value of hidden random variables Sgiven some observed variables I. In other words, we want to calculate P(S|I). For this Bayesian theory is is most handy. From the definition of conditional probabilities we have P(S|I)P(I)=P(S,I)=P(I|S)P(S) So, dividing by P(I), we obtain the Bayes’ rule, P(S|I)=P(I|S)P(S) P(I)=P(I|S)P(S) PS0P(I|S0)P(S0)∝P(I|S)P(S) that gives the posterior probability P(S|I) in terms of the prior probability P(S) and the likelihood P(I|S). In other words, Bayes’ rule expresses the probability P(S|I) of the state Sgiven the measurements Iin terms of the probability P(S) of the state and the probability P(I|S) of those measurements given S. In Pattern theory, Bayesian models are used because of two main facts. First, we can use it to perform probabilistic inference, such as finding the most probable state of the world given some measurements of a signal. This process is called the maximum a posteriori (MAP) estimate of the world. This type of processes are very common in signal processing. Secondly, we can generate new samples from the model: assign values to the hidden variables S, according to their distribution laws, and output the corresponding I. The fitness of the model is judged according to the similarity of the Iso generated to the real signals. 4.5. MACHINE TRANSLATION MODEL 41 4.4. Pattern analysis and Pattern synthesis An important fact in pattern theory is that from its perspective the analysis of the patterns in a signal and the synthesis of new signals are two sides of the same coin, as they share the probabilistic model. Pattern theory suggests two convenient views to be taken into account in pattern processing: bottom-up and top-down. They are represented in Figure 3 for a generic pattern. The specializations to mosaic patterns in Chapter 5 and to speech patterns in Chapter 6 are summarized in the caption. Data Model Algorithm New data Sampling Comparison Implementation Fig. 3. Generic stages of pattern theory. For the mosaic patterns in Chapter 5, the model is based on the symmetries of the mosaic and the sampling consists in choosing the type of mosaic and a decoration. For the speech patterns in Chapter 6, the model is based on frequency and the sampling consists in choosing features for a phoneme and also its duration and fundamental frequency. Most of the algorithms in pattern recognition only have the bottom-up stage. This stage starts with the signal and calculates a vector of features to characterise the behaviour of the signal. After that, it compares these features with those expected from the different categories. The problem with this type of algorithm is that there is no way to reverse the process, i.e., it is not possible manner to create new samples from the features. Another problem with feature-extracting algorithms is that they are not flexible to cope with anything unexpected, such as a shadow in a text. In contrast, pattern theory can reconstruct the signal, or an approximation of it, and can create endless new samples from the model. 4.5. Machine translation model To end this chapter we present an example of an approach to machine translation using Bayes’ theorem. We want to translate some sentence from one language to another with a model whose parameters are derived from the analysis of (aligned) bilingual text corpora. This model is based on two facts. First, a two-language dictionary with frequencies and second, a simple model of short word sequences in the target language and the usage of Bayesian theory to combine them. To 42 4. PATTERN THEORY be more specific, we suppose that he have the word string fin language Fand let ebe a word string in language E. A F-to-Edictionary gives a probability distribution of P(e|f), whose higher values yield reasonable translations. If we use the Bayes’ rule, we can use the E-to-Fdictionary to calculate this probability. So, we fix fand we seek e=arg max e{P(f|e)P(e)} The probability P(f|e) is given by the E-to-Fdictionary and P(e) can be calculated from an n-gram model (See 3.5). This equation is called the maximum a posteriori (MAP) estimate of e. Although a word to word translator sometimes produces non coherent translations, the model proposed here performs a natural translation if we have a reasonable amount of phrases. The key of this type of machine translation is that one needs a new random variable to describe the relation between eand f: the alignment of the two sentences. In other words, many pairs of words ei,fjwill be simple translation one of another, but they may appear in different order. However, there are cases where some words in the language Fget expanded to phrases in language E(for example: ”headache“ (English)↔ ”mal de cap“ (Catalan)). Some other cases are that idiomatic phrases can be different or some words have to be interleaved in the other language. Thus, an alignment is a correspondence associating one word ejto disjoint strings of f. So, the dictionary gives a list of strings f(1), ..., f(l) with their probabilities P(f(k)|e) as possible translations of the sentence e. The strings can contain empty strings, singletons and longer strings. To sum up, the advantages of statistical machine translation are: •Statistical machine translation systems are not tailored to any specific pair of languages. •Other translation systems are likely to result in Literal translation. While it appears that statistical systems should avoid this problem and result in natural translations. •New statistical methods incorporate syntax or quasi-syntax structures that improve the translation process. Chapter 5 Wallpaper group algorithm This chapter is devoted to present an algorithm for the synthesis and classification of plane mosaics based on their symmetry groups. The algorithm is based on the mathematical classification of these symmetry groups (see Chapter 2) and it is meant to be a showcase of the Grenander-Mumford approach to patterns (see Chapter 4). The algorithm is implemented in Matlab and its functionality in regard to the generation of mosaics and their classification is illustrated with examples, including mosaics generated by the program. 5.1. Mosaic generator In this section we present a Matlab program which implements an algorithm that yields random mosaics with a random decoration. The algorithm can be divided into four steps: (1) To create an image that will be used for the decoration of the mosaic. (2) To chose at random a mosaic type and to build its standard cell with that decoration. (3) To tile the plane with that cell. (4) To transform the mosaic by randomizing its parameters according to the degrees of freedom of its type. 5.2. Decoration generator In this part of the algorithm we explain our method for creating an image to decorate a mosaic tile. As the decoration of a mosaic can be an arbitrary image, the first decision was to avoid this dull generality and to device instead an interesting procedure inspired in pattern theory. To that end, the possibility that seemed more appealing was to mimic the style traits of a painter and use them, following the tenets of pattern theory, as rules to generate random decorations. Since that would be rather laborious, and to a large extend peripheral to our concerns here, we have followed instead a simpler approach that is sufficient to illustrate the idea. Our decorations are formed by picking a colour for the background and then inserting circles at random (their number, centers, radii and colours are picked at random). The only restriction that we impose is that 43 44 5. WALLPAPER GROUP ALGORITHM the circles are not meet the border or the diagonals of the tile. This restrictions are only meant to avoid discontinuities (usually they are not very pleasing) when crossing tile boundaries. See Figure 1 for output samples of this procedure. Fig. 1. Four sample tile decorations. 5.3. Main cell creation This part of the algorithm takes a decoration image and a type of wallpaper group and returns the main cell of the mosaic. The algorithm first decides which part of the image is taken according to the mosaic type. If the mosaic has a quadrilateral fundamental domain, the program applies an affine transform to the image to make it the fundamental domain. If the mosaic has a triangular fundamental domain, the program only uses a half of the image. Once the fundamental domain is obtained, the algorithm creates the main cell by applying the symmetries of the wallpaper group to the fundamental domain. Finally, the main cell is transformed into a square cell to ease the task of next step, which actually produces the tiling. Figure 2 displays some examples. Fig. 2. Sample square cells created with our decorations. 5.5. CLASSIFICATION ALGORITHM 45 5.4. Tiling This application creates the tiling of the input image. First, the algorithm creates a bigger image formed by a tiling of the original. After that, the program applies a affine transform to the new image depending of the degrees of freedom of the lattice. These degrees of freedom can be the length of the main cell sides and the angle between them. The degrees of the lattice are listed in the table 1. Lattice type Degrees of freedom Parallelogrammatic 3 degrees: The length of the two sides and the angle. Rectangular 2 degrees: The length of the two sides. Rhombic 2 degrees: The length of the sides and the angle. Square 1 degree: The length of the sides. Hexagonal 1 degree: The length of the sides. Table 1. The degrees of freedom of the different type of lattices. Mosaics of every type created by the program are listed in 5.9. 5.5. Classification algorithm In this section we present the classification algorithm. In some sense it makes the opposite of the previous program. The application assumes that a mosaic image is given as a parallel projection in the direction of its perpendicular lines, i.e, from a frontal perspective (see Figure 3), and returns the type of wallpaper group of the mosaic. Our computational algorithm for periodic pattern perception based on wallpaper groups includes two main components: (1) recovering the underlying translation lattice of the pattern. (2) classifying the wallpaper group of the image. The key tool to detect periodic patterns is the correlation function. We use it as a probability function, since we find in every type of isometry the maximum value of the correlation function between the image and the transformation of the image due to the isometry. To make it a probability function we divide it by the maximum value of the autocorrelation of the original image. Let I(x,y) be an image and let ϕbe an isometry. To calculate the probability that the image Ihas this isometry we use the following steps. (1) compute the transformed image J(x,y)=ϕ(I(x,y)). (2) calculate the median of each image. 46 5. WALLPAPER GROUP ALGORITHM Frontal perspection Arbitrary perspective Fig. 3. Image perspective. (3) subtract the median from both images and obtain ˆ I(x,y) and ˆ J(x,y). (4) compute the correlation function using the FFT by rˆ Iˆ J(x,y)=F−1{F∗{ˆ I(x,y)}F{ ˆ J(x,y)}} (5) calculate the maximum of the autocorrelation function of ˆ I(x,y) as Mˆ Iˆ I=rˆ Iˆ I(x,y)=rˆ Iˆ I(0,0) (6) divide the correlation function by the previous number, i.e, Cˆ Iˆ J(x,y)=rˆ Iˆ J(x,y) Mˆ Iˆ I (7) search the maximum of the previous function. In the next two sections we explain the two parts of our algorithm in more details. 5.6. Translational lattice detection This part of the algorithm is centered in the processing of the image and the detection of the lattice (this is the most important part). The image processing starts by transforming the image into a grey scale image, as it is easier to manipulate than a colour image. It is, in a sense, a compression technique. After that, the gray image is compressed by a 1-level wavelet transform using Haar wavelets. The advantage of this compression is to make uniform the different regions of the mosaic and emphasize the boundaries. Once the image has been processed, the algorithm tries to find the lattice of the wallpaper group. We divide this search in three parts: (1) Finding the peaks of the autocorrelation function of the image (2) Finding the region of dominance of every peak (3) Calculating the main vectors of the lattice. 5.6.1. Peak finding. The first step to determinate the lattice of the wallpaper group is to find the peak of the autocorrelation function. To do this in our case we first decompose the autocorrelation image in squares of n(typically 5) pixels length per side. After that, we calculate the maximum value of every square and keep the position of the peak inside the square. Once the maximum for each square has been found, we we find the maximum of them and save the value and the positions where it occurs. With this method we avoid some noise in the autocorrelation function produced by noise in the original image. 5.7. CLASSIFYING THE WALLPAPER GROUPS 47 5.6.2. Region of dominance. It is a nontrivial task to find a proper set of peaks in an autocorrelation surface of a periodic pattern. After some experimental trials, our observation is that the absolute height of a peak is not as important as the size of its region of dominance, defined as the largest circle centered on the candidate peak such that no higher peaks are contained in the circle. A peak with a low height, but located far from any larger neighbours, perceptually is much more important than a high peak that is close to an even higher one. So, given the peak candidate for the previous part of the algorithm, we order them according to their region of dominance and keep only a percentage of them. 5.6.3. Determinate the lattice vectors. Having extracted a set of candidate lattice points as dominant peaks in the autocorrelation image, the next task is to find the shortest linearly independent translation vectors that generate the lattice. To determinate the lattice vectors, we first find the peak nearer to the center of the autocorrelation function. Since this is always a peak we use it to find the vectors. After that, we calculate the 2 nearer peak such that the vectors are linearly independent. To avoid bad peaks, we check that at double size there is another peak. Once the lattice has been found, we determinate the lattice type by calculating the angle between the vectors and the ratio between their lengths. 5.7. Classifying the wallpaper groups This part of the algorithm calculates the probabilities of the main cell to have the different types of symmetries. After that, the wallpaper group inside the image is determined using these probabilities. Once the lattice of the wallpaper group has been found, the first step to calculate the wallpaper group of the image is to apply an affine transform to the image to obtain an square main cell. An square main cell makes easier to calculate the value of correlations inside the image. Although it would seem that in this form it would be more difficult to calculate symmetries due to the composition of the symmetries with the affine transform, almost every symmetry, except the rotations of order 3 and 6, has diagonal matrix and commutes with the affine matrix transform. So, in these two cases one has to be very careful to compute in the right order the matrix transformations. The algorithm used to determine the wallpaper group is described in the following lines. The input of the algorithm is the lattice type computed (given by translation vectors T1and T2) by measuring the angles between them, their lengths and an image of the main cell. In the following text we will use the notation T1-reflection (T2-reflection) referred to a reflection about an axis of the unit lattice parallel with T1(respectively, T2). Euclidean Algorithm: (1) If the lattice is a parallelogram lattice (two possible groups: p1, p2), test if there is a 2-fold rotation. If the answer is yes, Wis a p2, otherwise it is p1. (2) If the lattice is a rectangle lattice, there are five plus two (seven) possible groups: pm,pg,pmm,pmg, pgg and p1, p2. First test if there is a 2-fold rotation. If it exists (four possible groups: pmm,pmg,pgg, 48 5. WALLPAPER GROUP ALGORITHM p2), test if there is a T1-reflection and T2-reflection. If they both exist and neither is a glide reflection, Wis pmm, else if one of them is a glide reflection, it is a pmg, otherwise is is a pgg. If no reflection exists, then Wis p2. If a 2-fold rotation does not exist (three possible groups: pm,pg,p1), then check if there is T1-reflection (or a T2-reflection). If there is a glide-reflection, Wis pg, otherwise it is pm. If no reflection symmetry exists, then Wis p1. (3) If the lattice is a rhombic, test if there is a diagonal reflection symmetry. If it does not exist, go to step 1. Otherwise there are two possible groups: cm,cmm. Test if there is a 2-fold rotation. If yes, Wis a cmm, otherwise it is a cm. (4) If the lattice is a square lattice, test test if there is 4-fold rotation. If no, go to step 3. Otherwise there are three possibilities: p4, p4m,p4g. Now test if there is a T1-reflection symmetry. If yes, Wis a p4m group. Otherwise, test if there is a diagonal-reflection. If yes, Wis a p4g, and else it is a p4. (5) If the lattice is hexagonal, first test if there is a 3-fold rotation symmetry. If no, go to step 3. Otherwise, there are five possible groups: p3, p3m1, p31m,p6, p6m. Now test if there is a 2-fold rotation. If yes (two possible groups: p6, p6m), then test if there is T1-reflection. If yes, Wis p6m, else it is a p6. In the case that there is no 2-fold rotation (three possible groups: p3, p3m1, p31m), test if there is a T1-reflection. If no, Wis a p3. Otherwise check if there is a diagonal-reflection. yes, Wis a p3m1, else it is a p31mgroup. In short, given a lattice, we first test the possible existence of special symmetries (3-fold, 4-fold rotations, diagonal reflection). If the answer is yes, the search is limited to a small set of possible groups, else the classification process leads to a more general type of lattice. To compute the different probabilities of the symmetries, we use the method explained in 5.5. 5.8. Examples of the algorithm The examples in this section illustrate the symmetry classification algorithm. We present 3 different examples. The first two examples are computer generated mosaics and hence they have few imperfections and their symmetries are very clear. The last example is an Indian metalwork presented at the Great Exhibition in 1851. Since it is human made, it has some imperfections and those affect significantly the correlation values. Figure 4 displays the mosaic chosen for the first example. The wallpaper group is a pmg and we will use our program to identify it. First of all, the program transforms the image into a grey scale one and compresses it with a 1-level wavelet transform. After that, it computes the autocorrelation function of the image and finds the peaks of the autocorrelation with the algorithm described in Figure 5.6. Figure 5 shows the peaks found by the program. After that, we determine the main cell of the lattice. This can be seen in Figure 6. In Figure 7, the main cell with the 2-fold rotation point in the center is shown. Once the lattice of the wallpaper group is found, and since the lattice type is a rectangular lattice, we test for a 2-fold rotation center. The program returns a value of P(2-fold)) =0.9276. Table 2 contains the probability values of all the symmetries. So, following the algorithm described in 5.7, the only possible groups are p2, pmg,pmm and pgg. Now we test for T1and T2reflections. The result can be seen in Table 2. So, as there is one reflection and one glide reflection, the wallpaper group is a pmg. 5.8. EXAMPLES OF THE ALGORITHM 49 Fig. 4. A computer generated pmg wallpaper group. Fig. 5. A computer generated pmg wallpaper group. Fig. 6. The autocorrelation function of Figure 4 and the peaks found by the algorithm. Fig. 7. The main cell of the mosaic in Figure 4 with a 2-fold rotation point in the center. Symmetry Probability 2 rotation 0.9276 3 rotation 0.1972 4 rotation 0.2205 6 rotation 0.2011 T1reflection 0.9720 with a glide of 25 T2reflection 0.8841 with a glide of 0 D1reflection 0.2221 with a glide of 32 D2reflection 0.2129 with a glide of 25 Table 2. Probabilities of the different symmetries for Figure 4. The size of the images after the affine transform is 50 ×50. Figure 8 shows the mosaic chosen for the second example. The wallpaper group is a p6m, which is the wallpaper group with more symmetries, and we will use our program to identify it. We notice that the image has some imperfections and due to that the probabilities are lower than the previous example. However, the good values are still higher than 0.5. 56 5. WALLPAPER GROUP ALGORITHM Fig. 24. Image of a generated cmm Symmetry Probability 2 rotation 0.9204 3 rotation 0.1159 4 rotation 0.0868 6 rotation 0.2149 T1reflection 0.3639 with a glide of 0 T2reflection 0.0968 with a glide of 0 D1reflection 0.9026 with a glide of 25 D2reflection 0.8339 with a glide of 0 Table 13. Symmetry probabilities of cmm Fig. 25. Image of a generated p4 Symmetry Probability 2 rotation 0.8798 3 rotation 0.1750 4 rotation 0.9202 6 rotation 0.1991 T1reflection 0.1142 with a glide of 42 T2reflection 0.1113 with a glide of 0 D1reflection 0.3010 with a glide of 0 D2reflection 0.0857 with a glide of 45 Table 14. Symmetry probabilities of p4 Fig. 26. Image of a generated p4m Symmetry Probability 2 rotation 0.9337 3 rotation 0.2060 4 rotation 0.9446 6 rotation 0.2219 T1reflection 0.9516 with a glide of 0 T2reflection 0.9463 with a glide of 0 D1reflection 0.8963 with a glide of 0 D2reflection 0.9067 with a glide of 0 Table 15. Symmetry probabilities of p4m 5.9. CLASSIFICATION OF GENERATED MOSAICS 57 Fig. 27. Image of a generated p4g Symmetry Probability 2 rotation 0.9366 3 rotation 0.0723 4 rotation 0.8430 6 rotation 0.2744 T1reflection 0.8867 with a glide of 25 T2reflection 0.8402 with a glide of 25 D1reflection 0.7884 with a glide of 0 D2reflection 0.7669 with a glide of 0 Table 16. Symmetry probabilities of p4g Fig. 28. Image of a generated p3 Symmetry Probability 2 rotation 0.3480 3 rotation 0.8444 4 rotation 0.1033 6 rotation 0.3187 T1reflection 0.3831 with a glide of 0 T2reflection 0.1559 with a glide of 0 D1reflection 0.2099 with a glide of 0 D2reflection 0.2181 with a glide of 24 Table 17. Symmetry probabilities of p3 58 5. WALLPAPER GROUP ALGORITHM Fig. 29. Image of a generated p3m1 Symmetry Probability 2 rotation 0.2283 3 rotation 0.8744 4 rotation 0.2693 6 rotation 0.2208 T1reflection 0.2765 with a glide of 0 T2reflection 0.2757 with a glide of 0 D1reflection 0.9554 with a glide of 0 D2reflection 0.3035 with a glide of 27 Table 18. Symmetry probabilities of p3m1 Fig. 30. Image of a generated p31m Symmetry Probability 2 rotation 0.2623 3 rotation 0.8238 4 rotation 0.3869 6 rotation 0.0315 T1reflection 0.7992 with a glide of 0 T2reflection 0.8139 with a glide of 0 D1reflection 0.3903 with a glide of 27 D2reflection 0.8067 with a glide of 0 Table 19. Symmetry probabilities of p31m 5.9. CLASSIFICATION OF GENERATED MOSAICS 59 Fig. 31. Image of a generated p6 Symmetry Probability 2 rotation 0.8655 3 rotation 0.8671 4 rotation 0.1633 6 rotation 0.8505 T1reflection 0.1517 with a glide of 23 T2reflection 0.1331 with a glide of 38 D1reflection 0.3075 with a glide of 0 D2reflection 0.3320 with a glide of 24 Table 20. Symmetry probabilities of p6 Fig. 32. Image of a generated p6m Symmetry Probability 2 rotation 0.8160 3 rotation 0.9141 4 rotation 0.1446 6 rotation 0.9177 T1reflection 0.9024 with a glide of 25 T2reflection 0.8431 with a glide of 25 D1reflection 0.9694 with a glide of 25 D2reflection 0.8643 with a glide of 25 Table 21. Symmetry probabilities of p6m 60 5. WALLPAPER GROUP ALGORITHM 5.10. Matlab functions In this section we present the principal functions coded in Matlab to implement the algorithms described before. 5.10.1. Generator algorithm. First, we present the functions defined to generate a mosaic. These functions are listed below. •function [I]=imagegenerator –I=A square image used as decoration of the mosaic. –This function creates a random decoration for the new mosaic. To do it, it applies the algorithm described in 5.2 and it uses the Matlab function random to decide the colours, the number of circles, and their attributes. •function [C,T]=cellcreation(i) –i=Image of the decoration. –C=A square main cell of the mosaic. –T=Type of mosaic. –This function creates a square version of the main cell of the mosaic as described in 5.3. In the case of mosaics with rotations of order 3, it uses the function imtransform. To decide the mosaic type, it uses the function random. •function [M]=tiling(c,t) –c=image of a square main cell of the mosaic. –t=type of mosaic. –M=image of the whole mosaic. –This function creates a tiling with the square main cell and then applies an affine transform to the tiling to create the mosaic with the Matlab function imtransform. To define the affine matrix it applies a random to every degree of freedom of the mosaic lattice. 5.10.2. Classification algorithm. In this section we present the main functions, again coded in Matlab, to classify the different mosaics. For every function we present the inputs (in lower-case letters), outputs (in capital letters) and a little explanation of what the function does. •function [X,A]=mosaics(i) –i=the image of the mosaic. –X=the image in grey scale. –A=the autocorrelation of the image. –This function transform the original image in a gray scale and calculates its autocorrelation function. It uses the fftfunction of Matlab. •function [P,V,R]=maxima(a,x) –a=autocorrelation function. –x=the image in gray scale. –P=peaks of the autocorrelation function. –V=vectors of the lattice. –R=type of lattice. –The purpose of this function is to calculate the peaks of the autocorrelation and the lattice of the mosaic from the image and its autocorrelation. It is uses the algorithm described in 5.6.1 5.10. MATLAB FUNCTIONS 61 •function [A,J]=squarecell(i,v) –i=image of the mosaic. –v=vectors of the lattice. –A=matrix of the affine transformation. –J=square main cell of the mosaic. –This function takes the image of the mosaic and the lattice and returns an square main cell of the mosaic. It applies an affine transform with the Matlab function imtransform. •function [J,V]=rotation(i,t) –i=image of the mosaic. –t=type of rotation. –J=image after the rotation. –V=maximum value of the correlation between the image and the rotation of it. –This part of the algorithm calculates the probability that there is a rotation of type t. It applies a transformation to the image with the Matlab function imtransform and calculates the maximum of the correlation of the original image and the transformed one. •function [V,G]=reflection(i,t) –i=image of the mosaic. –t=type of reflection. –V=maximum value of the correlation between the image and the reflection of it. –G=value of the sliding offset of the symmetry. –This function also applies a transform with the Matlab function imtransform and calculates the maximum in the direction of the reflection in the correlation image. Chapter 6 Speech classification As we have indicated in Chapter 4, in this chapter we show a Matlab application that parses the phonemes of a given recorded voice and another one that generates new recorded voices. The first sections of this chapter deal with the parsing of words into phonemes. We use the DWT to parse a word into its phonemes because it has the property to extract the power of the signal in different subbands of frequencies. The analysis of the power in different frequency bands has the capability to distinguishing the beginning and ending of the phonemes because the power in the different subbands is roughly constant over the lifetime of the phoneme [13, 63, 64]. The second part deals with the classification of the phonemes. We use an artificial neural network (see Appendix A) trained from the first formants of the different phonemes (Chapter 3). The formants are features that can discriminate phonemes (especially voiced phonemes). Finally, the last sections of the chapter are devoted to explains a method to synthesise voices from formants. Using the formants from the database we have obtained an algorithm that creates samples that are different from those in the initial database (artificial voices). 6.1. Classification algorithm The application is a program which returns, given a recording of a person saying a word, its sequence of phonemes. In our case, we use a data base of some Catalan words spoken by children. The algorithm consist in two main components: (1) Segmentation: it divides the spoken word into phonemes. (2) Identification: classifies each phoneme using a neural network. The first component uses the properties of the local spectrum of the wavelet transform to find the points where the energy in one subband changes, and this determines the phoneme boundaries. The second component calculates the formants of each phoneme and uses them as features for classification. In the next two sections we explain the two parts of our algorithm in more detail. 63 64 6. SPEECH CLASSIFICATION 6.2. Speech segmentation 6.2.1. Segmentation algorithm. This part of the algorithm divides the spoken word into phonemes by detecting their boundaries using the DWT. The DWT is used because of its decomposition in frequency subbands. The analysis of the power in different frequency subbands is an excellent way to distinguish the beginning and the end of phonemes, as many phonemes exhibit rapid changes in particular subbands, and these provide evidence for their initial and end points. The start of a phoneme should be marked by an initially small but rapidly rising power level in one or more of the DWT levels. In other words, we should expect the power to be small and the derivative to be large. Some experiments as in [63] showed that the speech signal should be decomposed into six levels, which cover the frequency band of a human voice. In our case we use a 6-level Symlets DWT. Let sbe the speech signal. First of all we calculate its M-DWT as DWT(s)={dM,dM−1, ..., d1,a1}. As the human voice has negligible power at very low frequencies, we only will use the djcoefficients. After that as the wavelet spectrum samples in n-level depends on the length Nof speech signal in time domain according to 2−M+n−1N, where n=1, ..., M, the power at each band is calculated in a different way to obtain the same number of samples following the equation pn(i)= 2n−1 X j=1 dn(j+2n−1i),where i=0, ..., 2−MN−1 (∗) The DWT subband power shows rapid variations. So, the first order differences in the power are inevitably noisy. Due to that we calculate the envelopes epnof each subband power function by choosing the highest values of pnin a window of given size Wto obtain a power envelope. See table 1. DWT Level Number of samples in comparison with level 1Window size 1 1 3 2 2 3 3 4 3 4 8 5 5 16 5 6 32 5 Table 1. Windows size of each DWT level. To calculate the derivative of pnwe use a smoothed differencing operator. The subband power pnis convolved with the mask [1,2,−2,−1] to obtain smoothed rate-of-change information rn. After that, we can detect phoneme boundaries searching for i-points for which the inequality p≥β||rn(i)||−epn(i) holds, where the constant pis threshold value which accounts for the time scale and sensitivity of the crossing points. In practice we take p=0.02. In the inequality, rnis multiplied by a scaling factor βwhich is approximately equal to 1. 6.2. SPEECH SEGMENTATION 65 The algorithm is summarized in the following steps: (1) Normalise a speech signal by dividing by its maximum value. (2) Decompose a signal into 6-levels of the DWT. (3) Calculate the sum of power samples in all frequency subbands to obtain the n-th subband power representation pn(i) according to (∗). (4) Obtain the envelopes epn(i) for functions in each subband by choosing the highest value of pnin a given window W(see table 1). (5) Calculate the rate-of-change function rn(i) by filtering pn(i) with the mask [1,2,−2,−1]. (6) Given a threshold pof the distance between rn(i) and epn(i) and a threshold pmin of minimal epn, find indexes for which ||rn(i)||−epn(i)<p∧||rn(i+1)||−epn(i+1)>p∨||rn(i−1)||−epn(i−1)>p∧epn(i)>pmin. Write such indices in one vector. (7) Find and group indices where there is no space between neighbouring ones longer than attribute ∆. This attribute is the minimum length of a phoneme which approximately is 0.028 seconds. (8) Calculate an average index value for each group found in the previous step as points of phoneme change. 6.2.2. Examples. The examples in this section serve to illustrate the segmentation algorithm. We present two examples. In the first example, the algorithm divides exactly the speech signal while in the second the program divides the speech signal in more segments than it should and some points are a bit different than the real ones. Figure 1 shows the recorded waveform of a child saying the word ONA. In figures 3 we can see the power function, its envelope and the rate-of-change function. We can also see the points of phoneme transition at each subband before the average step. Finally, Figure 2 shows the recorded waveform with some red lines that indicate the segmentation points found by the algorithm. Fig. 1. The speech waveform of a child saying the word ONA. Fig. 2. As in Figure 1, but with the segmentation found by the program (red lines). The second example of this section is shown in Figure 4. In this example the word is ENA. In Figure 5, the red lines represent the segmentation found by the algorithm and the green lines belong to the true segmentation. 72 6. SPEECH CLASSIFICATION (a) Spectrum of the generated phoneme. (b) Spectrum of a database sample (c) Time domain plot of the generated phoneme. (d) Time domain plot of a database sample Fig. 11. Figures of the phoneme /o/. (a) Spectrum of the generated phoneme. (b) Spectrum of a database sample (c) Time domain plot of the generated phoneme. (d) Time domain plot of a database sample Fig. 12. Figures of the phoneme /m/. 6.7. MATLAB FUNCTIONS 73 (a) Spectrum of the generated phoneme. (b) Spectrum of a database sample (c) Time domain plot of the generated phoneme. (d) Time domain plot of a database sample Fig. 13. Figures of the phoneme /n/. 6.7. Matlab functions In this section we present the main Matlab functions that we have coded to parse speech into phonemes, classify them and generate new speech renderings. For every function we present the inputs (in lower-case letters), outputs (in capital letters) and a short explanation of what the function does (Except for the Peter Assmann function). To see the whole code, see Appendix C. 6.7.1. Segmentation and classification functions. In this subsection we list the principal Matlab functions for the segmentation and classification. •function S=initialize(y) –y=the initial signal. –S=the signal after changing the sample rate. –This function changes the sample rate of the signal and erases the noisy parts of the signal. •function [E,R,I] =segmentation(s,w) –s=signal. –w=type of wavelets used. –I=points of segmentation. –E=envelope of each subband after the wavelet transform. –R=derivative of the power of each subband. –Returns the points of possible segmentation and the function of power and its derivative for each subband. We apply the method explained in 6.2.1. 74 6. SPEECH CLASSIFICATION •function [L,T]=readdatabase(p) –p=path of the database. –L=list of database phoneme signals. –T=array with the number of samples of each phoneme. –Read all the database phonemes of a given path. •function [N,T]=neuralnetwork(i,o,t) –i=training inputs. –o=training outputs. –t=training test. –N=neural network after training. –T=training test outputs. –This function trains a neural network to classify the different phonemes. It also returns the training test output. To create the neural network we use the Matlab function newff. •function [P]=phonemeparameters(s,i) –s=signal. –i=points of segmentation. –P=parameters of each phoneme. –It calculates the first 5 formants of each phoneme as explained in 6.3.1. The most important Matlab functions are lpc and roots. •function [P]=simulate nn(n,p) –n=neural network used. –p=parameters of the phoneme. –P=phoneme after the classification. –It takes the trained neural network and the parameters from a phoneme and outputs its classification. The principal function is sim. 6.7.2. Generation and synthesis functions. In this subsection we present the principal functions for the generation of sounds. •function [A,P]=get vspect(f0,ft,bt,nft,r) –f0 =fundamental frequency. –ft =formants of the phoneme. –bt =bandwidth of each phoneme. –ntf =number of formants. –r=sample rate of the spectrum signal. –A=amplitude of the generated phoneme spectrum. –P=phase of the generated phoneme spectrum. –Returns the spectrum of the generated phoneme from its formants. This function is due to Peter Assmann. •function Y=synthesise(d,r,ft,f0); –d=duration of the phoneme synthesis. –r=frequency rate of the synthesis. –ft =formants of the phoneme. –f0 =fundamental frequency of the signal. –Y=generated sound. 6.7. MATLAB FUNCTIONS 75 –Returns the generated phoneme from its formants. To do it, first applies the get vspect function presented above and then passes its spectrum to the time domain. •function [M,S]=phonemetype(p,t) –p=parameters of the database phonemes. –t=list of phonemes of each class. –M=mean of each formant pattern phoneme. –S=standard deviation of each formant pattern phoneme. –It calculates the mean and standard deviation of an hypothetical ideal phoneme. It follows the algorithm described in 6.6. Conclusions and future work In this project we have presented an introduction to some signal processing tools, with emphasis in wavelets and pattern theory. We have also illustrated their potential by experimenting with two proof-of-concept applications in image and voice processing, respectively. The underlying idea of pattern theory is to produce classes of stochastic models that can describe the patterns we see in nature, in the sense that random samples from these models have the same look and feel as the samples from the world itself. The detection of patterns in a real signal can be achieved by finding the pattern sample that is closest to it. This can be done by means of Bayes’ theory. There are two key features of this approach that are worth mentioning. On one hand, recognition can be successful even for quite noisy and ambiguous samples. On the other, the pattern model allows the production of endless variations by playing with its stochastic parameters or with its structural elements. As we have described in the text, wavelet analysis is a relatively new tool that generalizes Fourier analysis. The Fourier transform decomposes a signal into a sinusoidal basis of different frequencies. As a sine wave has an infinite time duration and specific frequency, it is perfectly localized in frequency domain but not in time domain. To counter this problem, the wavelet transform decomposes a signal in a base formed by shifted and scaled versions of functions limited in both time and frequency. We have used this local analysis of time signals to extract information from speech signals and parse a recorded voice into phonemes. The idea behind this method is that the power variations of phonemes take place in a narrow band only, so that it is much easier to detect them by analyzing the components of the DWT than by taking into account the power of the whole signal. With this approach we have been able to search for characteristic phoneme patterns, in the sense that they should suffice to distinguish one phoneme from the others. The recognition performance we have reached has more than 70% match to each phoneme used. As for possible variations, we have shown how to create new voices by tinkering with the parameters of the database. In the case of images, our goal was to produce a system that on one hand can generate plane mosaics of any of the 17 possible symmetry patterns that these structures can have and, on the other, that can recognize these patterns and hence be able to classify any mosaic by processing an image of it. For the classification part, the core idea was to look at the correlation of the mosaic image with some suitably chosen transformations of it. 77 78 CONCLUSIONS AND FUTURE WORK The implementations of the algorithms described in the last two chapters have been coded in Matlab. The listings can be found in the Appendices B and C. Future Work There are a number of different possibilities to continue the work undertaken in this project, including some that are inspired by the applications of wavelet analysis and pattern theory that have arisen during its development. We would like to improve our speech syntethiser/recogniser explained in the Chapter 6. In particular, it would be interesting to try it with the whole Catalan phoneme alphabet, and with more voice samples, in order to improve our neural network matches. We would also like to improve our phoneme model in order to make possible not only to experiment with variations of a voice due to factors such as age or current conditions in the vocal tract, but also to create other voices that are recognizably different and yet native. And instead of voice, a similar research can be undertaken for the case of musical instruments. In the case of plane mosaics, we can improve our program by implementing a more complex image generator. For example, we could describe the parameters that characterize a decoration style and hence create new samples of that style. In the pattern theory field, a promising and ambitious topic is its application in the so-called image grammars. These are data structures (parse graphs) to be implemented in systems aimed at ascertaining the most probable interpretation of any given image. A parse graph hierarchically structures the parts of an image (like objects, people or background) and their relations. In some way, it is an ideal arena for the synthesis/analysis interplay at work in pattern theory. Among the promising applications of pattern theory to image processing, we want to mention the case of biomedical images. In this vast area there is an increasing need for fast and reliable processing that can help clinical and radiology researchers and practitioners. One goal here is to model the patterns of disease lesions as they appear in the images, as for example lesions of multiple sclerosis in nuclear magnetic resonance. Another goal is to combine different images of the same source in order to obtain the best possible join information. Appendix A Neural Networks In this appendix we outline an introduction to artificial neural networks (ANN). Neural networks try to mimic how our own brains work, admittedly in a rather limited way, and they have had a big recent resurgence because of advances in computer hardware. See [46]. An ANN is a processing system that consists of elements with local computing capacity (neurons), organized into layered structures that are interconnected and work cooperatively. Neural networks are used because they are capable of learning. Given a specific task to solve, and a class of functions F, learning means using a set of observations to find f∗∈Fwhich solves the task in some optimal sense. The steps to solve a problem with a neural network are: •Learning phase •Testing phase •Simulation The learning phase has the following parts: •A training set formed by examples of inputs and their expected outputs. •A cost function that estimates the separation between the model and the concept that we try to model with the training set. •A optimization algorithm, which normally is the backpropagation algorithm. •A stopping criterion that allows to control the training time. The testing phase uses some examples, the test set (normally different from the training set), to check the quality of the learning phase and whether it is necessary to redo it. Finally, once the system has been trained and tested properly, we can use the system to calculate the output of the desired inputs. An example of an ANN is a Multi Layer Perceptron (MLP). The MLP is an ANN consisting of multiple layers. This allows to solve problems that are not linearly separable. This type of ANN is used in Chapter 6 and implemented in Matlab. The layers of a MLP can be classified into three types: 79 80 A. NEURAL NETWORKS •Input layer: Consisting of neurons that accept input features and pass them to the network. In these neurons there is no processing. •Hidden layers: Consisting of those neurons whose inputs come from previous layers and whose outputs are passed to the following layers. •Output layer: Neurons whose output values are the outputs of the entire network. The main advantage of a MLP is its ease of use, and that it can approximate any input-output examples. The main drawback is its slow training and the high number of training samples required. The tasks ANNs are applied to belong principally to the following areas: •Function approximation, or regression analysis, including time series prediction, fitness approximation and modeling. •Classification, including pattern and sequence recognition, novelty detection and sequential decision making. •Data processing, including filtering, clustering, blind source separation and compression. •Robotics, including the managing of manipulators, and computer numerical control. Appendix B Mosaic’s Code In this appendix we list the code of the mosaic’s algorithm. In the larger functions we only include the most important part of the code. •function [I]=imgenerador sI=1000; I=zeros(sI,sI,3,’uint8’); a=random(’unid’,256); if a==256 a=0; end b=random(’unid’,256); if b==256 b=0; end c=random(’unid’,256); if c==256 c=0; end I(:,:,1)=a; I(:,:,2)=b; I(:,:,3)=c; d=random(’unid’,9); if d==9 d=0; end k=1; while k<=d bool=0; di=random(’unid’,sI-40)+20; dj=random(’unid’,sI-40)+20; mval=min([sI-di sI-dj di dj]); for i=20:sI-20 if ((di-i)*(di-i)+(dj-i)*(dj-i)<400)||((di-i)*(di-i)+(dj-(sI+1-i))*(dj-(sI+1-i))<400) bool=1; else mval=min([sqrt((di-i)*(di-i)+(dj-i)*(dj-i)) mval]); end 81 88 B. MOSAIC’S CODE if(n==floor(n/dim)*dim) pos=[dim floor(n/dim)]; else pos=[n-floor(n/dim)*dim floor(n/dim)+1]; end function dis=distmat(a,b) dis=(a(1)-b(1))*(a(1)-b(1))+(a(2)-b(2))*(a(2)-b(2)); function ang=vectangle(a,b) ang=acosd(dot(a,b)/sqrt(dot(a,a)*dot(b,b))); •function [A,J,M]=squarecell(i,v) v1=v(1,:); v2=v(2,:); num=49; A=[v2(2) v1(2);v2(1) v1(1)]; A=Aˆ(-1)*(num+1); A=[A [0;0];0 0 1]; A=transpose(A); trans=maketform(’affine’,A); [J,xdata,ydata]=imtransform(i, trans); dim=size(i,1); if mod(dim,2)==0 dim=dim+1; end mig=posicioplot(punt,dim); M=floor(tformfwd(trans,mig(1),mig(2))-[xdata(1) ydata(1)]); function pos=posicioplot(n,dim) if(n==floor(n/dim)*dim) pos=[floor(n/dim) dim]; else pos=[floor(n/dim)+1 n-floor(n/dim)*dim]; end In the next function we only present the case of a 6-fold rotation. The other cases are similar. •function [J,V]=rotation(i,t,v) num=49; [A1,Ji,migt]=squarecell(i,v); I=Ji(migt(2)+(0:1:num),migt(1)+(0:1:num)); (...) elseif t==6 [A2,Jj,migt2]=squarecell(i,v(2,:),v(2,:)-v(1,:)); J=Jj(migt2(2)+(0:1:num),migt2(1)+(0:1:num)); gr=60; end if mod(size(a31,1),2)==0 dim=size(a31,1)+1; else dim=size(a31,1); end B. MOSAIC’S CODE 89 mid=[floor(size(i,1)/2) floor(size(i,2)/2)]; t=[1-cosd(gr) sind(gr); -sind(gr) 1-cosd(gr)]*[mid(2);mid(1)]; I1=I-mean(mean(I)); I2=J-mean(mean(J)); Icorr=ifft2(fft2(I2).*conj(fft2(I1))); a=max(max(ifft2(fft2(I1).*conj(fft2(I1))))); Icorr=Icorr/a; V=max(max(Icorr)); mm=find(V==Icorr); xx=posicio(mm,size(Icorr,1)); R=[cosd(gr) sind(gr) 0;-sind(gr) cosd(gr) 0;t(1) t(2) 1]; T=[1 0 0;0 1 0; xx(2) xx(1) 1]; A=A1*T*A1ˆ(-1)*R; B=[1 0 0; 0 1 0; 0 0 1]; v=[-A(3,1)+B(3,1);-A(3,2)+B(3,2)]; M=[A(1,1)-B(1,1) A(2,1)-B(2,1);A(1,2)-B(1,2) A(2,2)-B(2,2)]; x=Mˆ(-1)*v; trans2=maketform(’affine’,A1); a=floor(tformfwd(trans2,transpose(x))); xx=floor(a-[xdata(1) ydata(1)]); x=floor(transpose(x)); figure(1) image(Ji(xx(2)+(0:1:num),xx(1)+(0:1:num))); function a=invposicio(b,s1) a=(b(2)-1)*s1+b(1); •function [V,G]=reflection(i,t) num=49; V=0; G=0; for j=0:1:num if t==0 I=i; I2=I(size(I,1):-1:1,:); I=I-mean(mean(I)); I2=I2-mean(mean(I2)); a=max(max(ifft2(fft2(I).*conj(fft2(I))))); b=ifft2(fft2(I2).*conj(fft2(I))); bmax=max(b(1,:)); mm=find(bmax==b(1,:)); aux=bmax/a; if aux>V V=aux; G=mm-1; end elseif t==1 I=i; I2=I(:,size(I,2):-1:1); I=I-mean(mean(I)); I2=I2-mean(mean(I2)); a=max(max(ifft2(fft2(I).*conj(fft2(I))))); b=ifft2(fft2(I2).*conj(fft2(I))); bmax=max(b(:,1)); 90 B. MOSAIC’S CODE mm=find(bmax==b(:,1)); aux=bmax/a; if aux>V V=aux; G=mm-1; end elseif t==2 I=i; I2=transpose(I); I=I-mean(mean(I)); I2=I2-mean(mean(I2)); a=max(max(ifft2(fft2(I).*conj(fft2(I))))); b=ifft2(fft2(I2).*conj(fft2(I))); bmax=0; for i=1:1:num+1; if bmax<b(i,i) bmax=b(i,i); mm=i; end end aux=bmax/a; if aux>V V=aux; G=mm-1; end else I=i; I2=I(size(I,1):-1:1,:); I2=transpose(I2); I2=I2(size(I,1):-1:1,:); I=I-mean(mean(I)); I2=I2-mean(mean(I2)); a=max(max(ifft2(fft2(I).*conj(fft2(I))))); b=ifft2(fft2(I2).*conj(fft2(I))); bmax=0; for i=1:1:num+1; if bmax<b(i,i) bmax=b(i,num+2-i); mm=i; end end aux=bmax/a; if aux>V V=aux; G=mm-1; end end end Appendix C Speech Code In this appendix we displey the code of the speech methods explained in Chapter 6. •function S =initialize(y) [c1,l1]=wavedec(y,8,’db8’); c1=c1(1:sum(l1(1:6))); l1=[l1(1:6);size(c1,1)]; S = waverec(c1,l1,’db8’); •function [E,R,I] =segmentation(s,w) s=s/max(s); numlev=6; [c,l]=wavedec(s,numlev,w); n=0; slev=zeros(numlev,1); for i=1:numlev n=max(n,ceil(l(i+1)/2ˆ(i-1))); slev(i)=ceil(l(i+1)/2ˆ(i-1)); end p=zeros(n,numlev); r=zeros(n+3,numlev); env=p; h=[1 2 -2 -1]; for i=1:numlev cp=zeros(n*2ˆ(i-1),1); cp(1:l(i+1))=c(1+sum(l(1:i)):sum(l(1:i+1))); res=zeros(n,1); for j=1:2ˆ(i-1) res=res+cp(j:2ˆ(i-1):n*2ˆ(i-1)).*cp(j:2ˆ(i-1):n*2ˆ(i-1)); end p(:,i)=res; r(:,i)=abs(conv(p(:,i),h))/6; end for j=1:numlev t=floor(w(j)/2); for i=t+1:n if i+t<n+1 91 92 C. SPEECH CODE env(i,j)=max(p(i-t:i+t,j)); else env(i,j)=env(i-1,j); end end for i=t:-1:1 env(i,j)=max(p(1:i+t)); end end index=zeros(n,numlev); nindex=zeros(1,6); for j=1:numlev pp=0.02; pmin=0.003; ind=[]; for i=2:n-1 if (abs(r(i,j)-env(i,j))<pp)&&((abs(r(i+1,j)-env(i+1,j))>pp)|| (abs(r(i-1,j)-env(i-1,j))>pp))&&(env(i,j)>pmin) ind=[ind i]; end end nindex(j)=size(ind,2); index(1:size(ind,2),j)=ind’; end in=max(nindex); aa=[]; for i=1:numlev aa=[aa index(1:in,i)’/slev(i)]; end aa=sort(aa); aa=aa(find(and(aa>0,aa<1))); t=0.030; fs=11025; delta=t*fs/size(s,1); aam=[]; summ=aa(1); aux=1; j=1; for i=2:size(aa,2) if i==size(aa,2) if aa(i)-aa(aux)>3*delta mea=(aa(i)+aa(aux))/2; tind=find(aa>mea); tind=tind(1); if (tind==i)&&(aa(i)-aa(i-1)>delta) aam=[aam sum(aa(aux:tind-1))/(tind-aux) aa(i)]; elseif aa(i)-aa(i-1)>delta aam=[aam sum(aa(aux:tind-1))/(tind-aux) sum(aa(tind:i-1))/(i-tind) aa(i)]; else aam=[aam sum(aa(aux:tind-1))/(tind-aux) sum(aa(tind:i))/(i+1-tind)]; end j=1; summ=aa(i); aux=i; elseif aa(i)-aa(i-1)>delta C. SPEECH CODE 93 summ=summ/j; aam=[aam summ aa(i)]; else summ=(summ+aa(i))/(j+1); aam=[aam summ]; end else if aa(i)-aa(aux)>3*delta if (aa(i)-aa(i-1)>delta)&&(aa(i-1)-aa(aux)>2.4*delta) i=i-1; mea=(aa(i)+aa(aux))/2; tind=find(aa>mea); tind=tind(1); aam=[aam sum(aa(aux:tind-1))/(tind-aux) sum(aa(tind:i))/(i+1-tind)]; i=i+1; j=1; summ=aa(i); aux=i; elseif(aa(i)-aa(i-1)>delta) summ=summ/j; aam=[aam summ]; j=1; summ=aa(i); aux=i; else mea=(aa(i)+aa(aux))/2; tind=find(aa>mea); tind=tind(1); aam=[aam sum(aa(aux:tind-1))/(tind-aux)]; j=i+1-tind; summ=sum(aa(tind:i)); aux=tind; end elseif aa(i)-aa(i-1)>delta summ=summ/j; aam=[aam summ]; j=1; summ=aa(i); aux=i; else summ=summ+aa(i); j=j+1; end end end I=aam; E=env; R=r; •[L,T]=readdatabase(p) phon=[’o’ ’ea’ ’e’ ’i’ ’n’ ’m’]; sphon=[1 2 1 1 1 1]; L=[]; T=[]; 94 C. SPEECH CODE temp=0.02; r=11025*temp; for i=1:size(sphon,2) pwd=[p phon(1+sum(sphon(1:i-1)):sum(sphon(1:i)))]; pp=ls(pwd); T=[T size(pp,1)-2]; for j=3:size(pp,1) [listaux,f1,n1]=wavread([pwd ’/’ pp(j,:)]); L=[L listaux]; end end •[N,T]=neuronalnetwork(i,o,t) ival=10; jval=6; N=newff(t,o,[ival jval], {’tansig’,’tansig’}); N=train(N,i,o); taux=sim(N,t); tout=zeros(1,size(taux,2)); for i=1:size(taux,2) tout(i)=find(max(taux(:,i))<=taux(:,i)); end T=tout; •[P]=phonemeparameters(s,i) fs=11025; P=[]; for indexi=1:max(size(i))-1 signal=s(i(indexi):i(indexi+1))’; SegLength=floor(.025*fs); SP=.4; PreEmphFact=-0.98; NumberOfFormants=5; MaxFormantFreq=5000; MaxBWFreq=600; FreqRes=512; sigLength=length(signal); NumSeg=fix((sigLength-SegLength+SegLength*SP)/(SegLength*SP)); signal=real(filter([1 PreEmphFact],1,signal)); BegPtr=1; FCFreq=[]; FCBW=[]; hamwin=hamming(SegLength); AddP=1; for n=1:NumSeg segment=signal(BegPtr:(BegPtr+SegLength-1)); segment=segment.*hamwin; segment=[segment;zeros((FreqRes-SegLength),1)]; Candidates=FormantCand(segment); FCseg=angle(Candidates)*fs/(2*pi); FCBW=abs(log(abs(Candidates))*fs/pi); FCseg=FCseg(find(FCBW<MaxBWFreq)); FCseg=FCseg(find(FCseg<MaxFormantFreq)); C. SPEECH CODE 95 while (NumberOfFormants>length(FCseg)) Candidates=FormantCand(segment,AddP); FCseg=angle(Candidates)*fs/(2*pi); FCBW=abs(log(abs(Candidates))*fs/pi); FCseg=FCseg(find(FCBW<MaxBWFreq)); FCseg=FCseg(find(FCseg<MaxFormantFreq)); AddP=AddP+1; end if (n>1) Formants=distFormant(FCseg,NumberOfFormants,LastFormant); else Formants=distFormant(FCseg,NumberOfFormants); end ForMat=Formants.FM; chance=1./Formants.dst; [a b]=max(chance); LastFormant=ForMat(:,b); FormantTrack(:,n)=LastFormant; AddP=1; BegPtr=BegPtr+fix(SegLength*SP); end FFF=[]; FFO=[]; for i=1:size(FormantTrack,2) FFF=[FFF FormantTrack(:,i)’]; end FFF=sort(FFF); aux=1; for i=2:size(FFF,2) if i==size(FFF,2) FFO=[FFO;mean(FFF(aux:i))]; elseif (FFF(i)-FFF(aux)<300)&&(FFF(i+1)-FFF(i)<FFF(i)-FFF(i-1))&&(FFF(i+1)-FFF(aux)>300) FFO=[FFO;mean(FFF(aux:i-1))]; aux=i; elseif FFF(i)-FFF(aux)>300 FFO=[FFO;mean(FFF(aux:i-1))]; aux=i; end end if size(FFO,1)<5 a=5-size(FFO,1); a=0*(1:a); FFO=[FFO;a’]; end P=[P FFO(1:5)]; end function Candidates=FormantCand(segment,AddP) P=15+AddP; lpccof=lpc(segment,P); rts=roots(lpccof); Phase=angle(rts); Amp=abs(rts); posPhaseIndex=find((Phase>0.000001) & (Phase<(pi-0.000001))); Phase=Phase(posPhaseIndex); 96 C. SPEECH CODE Amp=Amp(posPhaseIndex); [Phase sIndex]=sort(Phase); Amp=Amp(sIndex); Candidates=Amp.*exp(i*Phase); function dist=distFormant(Poles,numberOfFormants,LastChosenFormant) FormantMat=(nchoosek(Poles,numberOfFormants))’; numberOfCands=size(FormantMat,2); dist.FM=FormantMat; dist.dst=dst; •function [P]=simulate nn(n,p) phon=[’o’ ’ea’ ’e’ ’i’ ’n’ ’m’]; sphon=[1 2 1 1 1 1]; Vaux=sim(n,p); Vout=zeros(1,size(Vaux,2)); P=[]; for i=1:size(Vaux,2) Vout(i)=find(max(Vaux(:,i))<=Vaux(:,i)); P=[P ’/’ phon(1+sum(sphon(1:Vout(i)-1)):sum(sphon(1:Vout(i)))) ’/’]; end •[A,P]=get vspect(f0,ft,bt,nft,r) f=0:f0:r/2; tf=ones(size(f)); T=1/r; z=exp(i*2*pi*f*T); fgp=0; bgp=100; cp=-exp(-2*pi*bgp*T); bp=2*exp(-pi*bgp*T).*cos(2*pi*fgp*T); ap=1-bp-cp; tf=tf.*(ap./(1-bp.*z.ˆ(-1)-cp.*z.ˆ(-2))).*(1-z.ˆ(-1)); fgz=1500; bgz=6000; cz=-exp(-2*pi*bgz*T); bz=2*exp(-pi*bgz*T).*cos(2*pi*fgz*T); az=1-bz-cz; cz=-cz/az; bz=-bz/az; az=1/az; tf=tf.*(az./(1-bz.*z.ˆ(-1)-cz.*z.ˆ(-2))); c=-exp(-2*pi*bt*T); b=2*exp(-pi*bt*T).*cos(2*pi*ft*T); a=1-b-c; for ift=1:nft tf=tf.*(a(ift)./(1-b(ift).*z.ˆ(-1)-c(ift).*z.ˆ(-2))); end amp=abs(tf)’; phase=angle(tf)’; •function Y=synthesise(d,r,ft,f0); npts=floor(d*(r/1000)); nmspf=d; C. SPEECH CODE 97 nsampf=npts; T=1/r; o=ones(nsampf,1); bt=[90 110 140 180 220]; y=zeros(npts,1); ps=zeros(nsampf,floor((r/2)/min(f0))+1); psi=zeros(1,floor((r/2)/min(f0))+1); if ft(4)>4000 nft=3; ft=ft(1:3); bt=bt(1:3); elseif ft(5)>4800 nft=4; ft=ft(1:4); bt=bt(1:4); end i=find(ft(1:nft)<30); nft=nft-length(i); bt(i)=[]; ft(i)=[]; [amp,ph]=get_vspect(f0,ft,bt,nft,r); nh=length(amp); k=(o*(0:nh-1))*2*pi*f0*T; ps=cumsum(k); y(1:nsampf)=sum((o*amp’.*cos(ps-k+o*ph’+o*psi(1:nh)))’)’; psi(1,1:nh)=psi(1,1:nh)+(ps(nsampf,1:nh)); •function [M,S]=phonemetype(p,t) M=[]; S=[]; for ipar=1:max(size(t)) m=[]; s=[]; par=p(:,1+sum(t(1:ipar-1)):1:sum(t(1:ipar))); for i=1:size(par,1) aux=par(i,:); aux=sort(aux); temp=1; tm=[]; for j=2:max(size(aux)) if (aux(j)-aux(j-1)>150) tm=[tm j-temp]; temp=j; elseif aux(j)-aux(temp)>400 tm=[tm j-temp]; temp=j; end end tm=[tm j-temp]; ij=find(tm==max(tm)); ij=ij(1); m=[m mean(aux((1+sum(tm(1:ij-1))):1:sum(tm(1:ij))))]; s=[s std(aux((1+sum(tm(1:ij-1))):1:sum(tm(1:ij))))]; end M=[M;m] S=[S;s]; end