annotate toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/WhiteVowel.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [output,aCoeff] = WhiteVowel(data,sr,L,pos)
Daniel@0 2 % function [output,aCoeff] = WhiteVowel(data,sr,L,pos)
Daniel@0 3 %
Daniel@0 4 % Speech is often described as having spectral peaks or formants which
Daniel@0 5 % identify the phonetic signal. An interesting experiment, first proposed by
Daniel@0 6 % XXX, filters a speech signal to remove all the formant information at one
Daniel@0 7 % time during the speech. If there are no formant peaks, how can the speech
Daniel@0 8 % be understood? It turns out that processing, much like RASTA, means that
Daniel@0 9 % relative changes in spectrum are the most important, thus the speech signal
Daniel@0 10 % is understood because the formant transitions carry the information. This
Daniel@0 11 % gives speech an important transparency due
Daniel@0 12 %
Daniel@0 13 % This function takes a speech signal (data) with a given sampling rate (sr).
Daniel@0 14 % It then finds the L-order LPC filter that describes the speech at the given
Daniel@0 15 % position (pos ms). The entire speech signal is then filtered with the
Daniel@0 16 % inverse of the LPC filter, effectively turning the speech spectrum at the
Daniel@0 17 % given time white (flat).
Daniel@0 18
Daniel@0 19 % Chris Pal, Interval, May 1997
Daniel@0 20 % (c) 1998 Interval Research Corporation
Daniel@0 21
Daniel@0 22 fr = 20; fs = 30; preemp = .9378; % LPC defaults
Daniel@0 23
Daniel@0 24 [row col] = size(data);
Daniel@0 25 if col==1 data=data'; end
Daniel@0 26
Daniel@0 27 nframe = 0;
Daniel@0 28 msfr = round(sr/1000*fr);
Daniel@0 29 msfs = round(sr/1000*fs);
Daniel@0 30 duration = length(data);
Daniel@0 31 msoverlap = msfs - msfr;
Daniel@0 32 frameNumber = floor(pos/1000*sr/msfr);
Daniel@0 33
Daniel@0 34 frameStart = round(pos/1000*sr - msfs/2);
Daniel@0 35 frameData = data(frameStart:(frameStart+msfs-1));
Daniel@0 36 aCoeff = proclpc(frameData, sr, L, fr, fs, preemp);
Daniel@0 37 % Calculate the filter response
Daniel@0 38 % by evaluating the z-transform
Daniel@0 39 spec=lpc_spec(aCoeff);
Daniel@0 40 subplot(2,3,1);
Daniel@0 41 plot(spec);
Daniel@0 42 title('LPC Spectral Slice');
Daniel@0 43 ylabel('Original')
Daniel@0 44
Daniel@0 45 % Now do the actual whitening filter
Daniel@0 46 output = filter(aCoeff,1,data)';
Daniel@0 47
Daniel@0 48 frameData = output(frameStart:(frameStart+msfs-1));
Daniel@0 49 bCoeff = proclpc(frameData, sr, L, fr, fs, preemp);
Daniel@0 50 spec=lpc_spec(bCoeff);
Daniel@0 51 subplot(2,3,4);
Daniel@0 52 plot(spec);
Daniel@0 53 ylabel('Whitened'); xlabel('FFT Bin');
Daniel@0 54
Daniel@0 55 % 256-DFT
Daniel@0 56 origSpec = 20*log10(abs(specgram(data,512,sr,msfs,msoverlap)));
Daniel@0 57 subplot(2,3,2),imagesc(origSpec); axis xy; colormap(1-gray);
Daniel@0 58 title('Spectrogram');
Daniel@0 59
Daniel@0 60 synSpec = 20*log10(abs(specgram(output,512,sr,msfs,msoverlap)));
Daniel@0 61 subplot(2,3,5),imagesc(synSpec); axis xy; colormap(1-gray);
Daniel@0 62 xlabel('Frame #');
Daniel@0 63
Daniel@0 64 origloc = origSpec(:,frameNumber); origloc=origloc-max(origloc);origmin=min(origloc);
Daniel@0 65 subplot(2,3,3),plot(origloc),title('Spectrogram'),
Daniel@0 66 axis([1 length(origloc) origmin 0]);
Daniel@0 67
Daniel@0 68 filloc = synSpec(:,frameNumber); filloc=filloc-max(filloc);
Daniel@0 69 subplot(2,3,6),plot(filloc);ylabel('db');
Daniel@0 70 axis([1 length(origloc) origmin 0]);
Daniel@0 71 xlabel('FFT Bin');
Daniel@0 72
Daniel@0 73 function spec=lpc_spec(aCoeff)
Daniel@0 74 gain=0;
Daniel@0 75 cft=0:(1/255):1;
Daniel@0 76 for index=1:size(aCoeff,1)
Daniel@0 77 gain = gain + aCoeff(index)*exp(-i*2*pi*cft).^index;
Daniel@0 78 end
Daniel@0 79 gain = abs(1./gain);
Daniel@0 80 spec = 20*log10(gain(1:128))';