%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Multimedia Signal Synthesis at CTU Prague % Copyright © 2014 by Roman Cmejla %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Suggestions for 5th laboratory: % Formant synthesis % November 11, 2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Recommended links: % http://music.columbia.edu/cmc/musicandcomputers/chapter4/04_04.php % http://http://cnx.org/contents/dfbfc86c-866b-4ab8-9d55-eb1ae266962d@3.4:39/Musical_Signal_Processing_with % http://www.asel.udel.edu/speech/tutorials/synthesis/Klatt.html % http://www.fon.hum.uva.nl/david/ma_ssp/doc/Klatt-1980-JAS000971.pdf % http://www.soundonsound.com/sos/mar01/articles/synthsec.asp %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% % Example 1: Filters with two poles - resonators % Design a bank of filters consisting of resonators. % Analysis of harmonics in time using resonators. %% % a) Display zeros and poles in the z-plane % for the proposed bank of filters. clear, close all, clc figure(1) [x,fs]=wavread('banjo'); f0=392; fr=[f0 2*f0 3*f0 4*f0 5*f0 6*f0 7*f0 8*f0 9*f0]; B = 500; % bandwidth of resonators R = 1-B*pi/fs; % radius of poles b0 =(1-R)*sqrt(1-2*R*cos(2*2*pi*fr/fs)+R*R);% the scaling coefficient a = -2*R*cos(2*pi*fr/fs); % computation of coefficients a1 k = .99; for h=1:9 subplot(3,3,h), %H=freqz(b0(h),[1 a(h) R.^2]); zplane(b0(h),[1 a(h) R.^2]) end; %% % b) Display the normalized amplitude frequency characteristics % for designed bank of filters. figure(2) for h=1:9 subplot(3,3,h), [Ha(:,h),w]=freqz(b0(h),[1 a(h) R.^2],[],fs); Ham(h)=max(abs(Ha(:,h))); Han(:,h)=(1/Ham(h))*freqz(b0(h),[1 a(h) R.^2]) plot(abs(Han(:,h))), axis([0 512 0 1]) end; %% % c) Displays all filters in one image. figure(3) plot(w,abs(Han)) %% % d) Analysis of harmonics using resonators % Display the individual harmonics at the output bank of resonators figure(4) % Observe the effect of the pole location on the final amplitude envelope. for h=1:9 y(:,h)=(1/Ham(h))*filter(b0(h),[1 a(h) R.^2],x); % envelopes of single harmonics y(:,h)=filter((1-k),[1 -k],abs(y(:,h))); end; subplot(311), plot(x) subplot(312), specgram(x,[],fs) subplot(313), plot(y); legend('h1','h2','h3','h4','h5','h6','h7','h8','h9') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% % Example 2: Subtractive synthesis %% % a) gunshot x1=randn(1,doba*fs); X=[0 .12 1]; Y=[1 0.07 0]; r=0.6; f0=1200; % zeros and poles = ? % frekvuency characteristics = ? % envelope = ? % synthetic signal = ? %% % b) cymbal fs = 44100; % sampling frekvuency [Hz] doba = .5; % sound duration [s] x=2*rand(1,fs*doba)-1; % white noise O=exp(-nT./.15); B = 300; % bandwidth of resonators fr = 11000; % zeros and poles = ? % frekvuency characteristics = ? % envelope = ? % synthetic signal = ? %% % c) clock fs = 8000; % sampling frequency [Hz] doba = .5; % sound duration [s] x=2*rand(1,fs*doba)-1; % white noise fr=[3500 5500]; B = 550; % bandwidth of the first pair of resonator fr=[3000 7000]; B = 750; % bandwidth second pair of resonator %% % d) rotating machines (train, plane) fs=22050; f1=25; % parni lokomotiva f1=5 Hz % letadlo f1=65 Hz doba=4; nT=0:1/fs:doba-1/fs; % time axis x1=sawtooth(2*pi*f1*[0:1/fs:doba-1/fs]); % need band-limit x2=randn(1,length(x1)); X=[0 .25 .5 .6 1]; Y=[0 .75 1 .45 0]; r=0.3; f0=1950; x=filter(1,[1 -2*r*cos(2*pi*f0/fs) r.^2],x1); O=interp1(X,Y,nT/nT(end)); y=x1.*x2; soundsc(y.*O,fs) subplot(211), plot(y.*O) subplot(212), specgram(y.*O) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% % Example 3: Subtractive synthesis with time-varying filters % a) wind % Wind can be modeled by passing white noise through resonator % with time variable frequency and constant bandwidth. % For strong winds we will use short periods of length from 0.2 to 0.5 % seconds and resonant frequence between 800 and 900 Hz . % Weaker wind is modeled by longer time periods between 2 and 3 % seconds and the resonant frequency 100-200 Hz. clear, fs = 8000; % sampling frequency [Hz] doba = 10; % sound duration [s] x=2*rand(1,fs*doba)-1; % white noise nT=0:1/fs:doba-1/fs; % time axis % souradnice ridicich bodu sily vetru X=[0 .15 .3 .4 .5 .65 .7 .75 .8 .85 .9 .95 1]; Y=[0 .2 .1 .3 .05 .3 1 .8 1 .5 1 .7 .1]; Fmin=100; Fmax=900; y=(Fmax-Fmin)*Y+Fmin; %% % b) waves % Waves can be modeled by passing white noise resonator like the wind. % In this case, besides the resonant frequency the amplitude and bandwidth % are also changed. Changing the bandwidth we allow to control % the "magnitude" of the wave. clear fs = 8000; % sampling frequency [Hz] doba = 5; % sound duration [s] x=2*rand(1,fs*doba)-1; % white noise nT=0:1/fs:doba-1/fs; % time axis % coordinates of the control points X =[0 .2 .25 .35 1]; % time axis Y_A=[0.15 .8 .15 .8 0.15]; % amplitude Y_B=[0 320 400 600 4000]; % bandwidth Y_f=[80 80 1000 1000 1000]; % resonant frequency % interpolated waveform of control amplitude G=interp1(X,Y_A,nT/nT(end)); % interpolated waveform of bandwidth B=interp1(X,Y_B,nT/nT(end)); % interpolated waveform of resonant frequency fr=interp1(X,Y_f,nT/nT(end)); %% % c) water %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% % Example 4: Formant synthesis of vowels % Cascade synthesis of vowels (excitation and impulse noise) % ---------------------------------------------------------- % | V | F1 | F2 | F3 | F4 | BW1 | BW2 | BW3 | BW4 | % ---------------------------------------------------------- % | A | 700 | 1100 | 2700 | 3500 | 90 | 110 | 170 | 250 | % | E | 400 | 1750 | 2500 | 3400 | 90 | 110 | 170 | 250 | % | I | 250 | 2000 | 2900 | 3300 | 90 | 110 | 170 | 250 | % | O | 500 | 700 | 2700 | 3800 | 90 | 110 | 170 | 250 | % | U | 300 | 500 | 2550 | 3350 | 90 | 110 | 170 | 250 | % ---------------------------------------------------------- clear, clc % parameters of the synthetic signal fs=16000; % sampling frequency doba=.6; % vowel duration % glottal pulses f0=90; % fundamental frequency B0=100; R0=1-B0*pi/fs; % vocal tract filter % Fg=1500; Bg=6000; Rg=1-Bg*pi/fs; Fg=1500; Bg=3500; Rg=1-Bg*pi/fs; [b0,a0]=zp2tf([Rg*exp(j*2*pi*Fg/fs);Rg*exp(-j*2*pi*Fg/fs);1],[R0;R0],1); N = fix(fs/(2*f0)); % buzeni pasmove omez.impulsy x=[ones(1,N)*cos(2*pi*[1:N]'*f0*[0:1/fs:doba-1/fs])]; pulsy=filter(b0,a0,x); noise=randn(1,length(x)); % noise excitation % vowel formants A = [700 1100 2700 3500]; % [F1 F2 F3 F4] E = [400 1750 2500 3400]; % [F1 F2 F3 F4] I = [250 2000 2900 3300]; % [F1 F2 F3 F4] O = [500 700 2700 3800]; % [F1 F2 F3 F4] U = [300 550 2550 3350]; % [F1 F2 F3 F4] B = [ 90 110 170 250]; % [B1 B2 B3 B4] % vowel selection F = A; % F = A/E/I/O/U % options for input excitation % y = noise; % y = pules or noise y = pulsy; subplot(311), plot(y) % calculating of the formant filters for k=1:4 R(k)=1-B(k)*pi/fs; pp(k)=R(k)*exp(j*2*pi*F(k)/fs); pn(k)=R(k)*exp(-j*2*pi*F(k)/fs); [b(k,:),a(k,:)]=zp2tf(0,[pp(k);pn(k)],1); end; % cascade connection of filters for k=1:4 y=filter(b(k,:),a(k,:),y); end; soundsc(y,fs) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% % Example 5: Formant synthesis of musical instruments % a) violin %% % b) cello %% % c) clarinet % ------------------------------------------------------------------ % | instrument | F1 | F2 | F3 | F4 | BW1 | BW2 | BW3 | BW4 | % ------------------------------------------------------------------- % | violin | 500 | 1500 | 3000 | 4000 | 300 | 200 | 700 | 1500 | % | cello | 990 | 2000 | | | 450 | 560 | | | % | tube | 350 | 3960 | | | 225 | 1800 | | | % | fagot | 440 | 1180 | 3320 | | 110 | 675 | 1125 | | % | bassoon | 800 | 1750 | 2800 | 3300 | 795 | 795 | 795 | 795 | % | saxophone | 680 | 2050 | 4600 | | 900 | 700 | 700 | | % | oboe | 1350 | 3450 | | | 337 | 450 | | | % | French horn| 550 | 2100 | 790 | | 450 | 790 | 1600 | | % | flute | 750 | 1600 | 4830 | | 560 | 225 | 800 | | % | clarinet | 300 | 830 | 2190 | 3880 | 450 | 450 | 900 | 675 | % ------------------------------------------------------------------ %