annotate toolboxes/MIRtoolbox1.3.2/AuditoryToolbox/rasta.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 y=rasta(x,fs,low,high)
Daniel@0 2 % function y=rasta(x,fs) where x is the input data (rows of time data),
Daniel@0 3 % and fs is the frame rate (sampling rate) in Hz. This is a modified
Daniel@0 4 % version of the original filter. Here the RASTA filter is approximated
Daniel@0 5 % by a simple fourth order Butterworth bandpass filter. See pages 50-51
Daniel@0 6 % of my second IRC logbook for the derivation.
Daniel@0 7 %
Daniel@0 8 % Hermansky and Morgan, "RASTA Processing of Speech." IEEE Transactions
Daniel@0 9 % on Speech and Audio Processing. vol. 2, no. 4, October 1994
Daniel@0 10 %
Daniel@0 11
Daniel@0 12 % (c) 1998 Interval Research Corporation
Daniel@0 13 % Malcolm Slaney, January 30, 1996, Interval Research Corporation
Daniel@0 14
Daniel@0 15 if (nargin < 2); fs=100; end
Daniel@0 16 if (nargin < 3); low=.9; end
Daniel@0 17 if (nargin < 4); high=12.8; end
Daniel@0 18
Daniel@0 19 if (low == 0 & high == 0) % Original Filter
Daniel@0 20 num = .1*[2 1 0 -1 -2];
Daniel@0 21 denum = [1 -.94];
Daniel@0 22 else % New fourth order
Daniel@0 23 % Butterworth BP filter
Daniel@0 24 w1=low/fs*2*pi;
Daniel@0 25 w2=high/fs*2*pi;
Daniel@0 26 theta=1;
Daniel@0 27
Daniel@0 28 a=cos((w1+w2)/2)/cos((w2-w1)/2);
Daniel@0 29 k=cot((w2-w1)/2)*tan(theta/2);
Daniel@0 30
Daniel@0 31 num = [1 0 -2 0 1];
Daniel@0 32 denum = [(1 + 2*2^(1/2)*k + 4*k^2) ...
Daniel@0 33 (-4*2^(1/2)*a*k - 16*a*k^2) ...
Daniel@0 34 (-2 + 8*k^2 + 16*a^2*k^2) ...
Daniel@0 35 (4*2^(1/2)*a*k - 16*a*k^2) ...
Daniel@0 36 (1 - 2*2^(1/2)*k + 4*k^2)];
Daniel@0 37 scale = denum(1); % Scale by a(1) component
Daniel@0 38 num = num/scale;
Daniel@0 39 denum = denum/scale;
Daniel@0 40 end
Daniel@0 41
Daniel@0 42 if (0)
Daniel@0 43 len = 1024;
Daniel@0 44 impulse = zeros(1,len);
Daniel@0 45 impulse(1) = 1;
Daniel@0 46
Daniel@0 47 y=filter(num,denum,impulse);
Daniel@0 48 ym = abs(fft(y));
Daniel@0 49 ym=20*log10(ym);
Daniel@0 50 f=(0:(len-1))/len*fs;
Daniel@0 51 semilogx(f(1:len/2),ym(1:len/2));
Daniel@0 52 drawnow;
Daniel@0 53 end
Daniel@0 54
Daniel@0 55 if (length(x) == size(x,1)*size(x,2))
Daniel@0 56 y = filter(num,denum,x,x(1)*[-1 -1 1 1]);
Daniel@0 57 else
Daniel@0 58 y = zeros(size(x));
Daniel@0 59 for i=1:size(x,1)
Daniel@0 60 y(i,:) = filter(num,denum,x(i,:),x(i,1)*[-1 -1 1 1]/scale);
Daniel@0 61 end
Daniel@0 62 end