--- Saving session to: ECE481_25-Apr-2002.txt --- Processed startup.m --- doc ; ; ; ; ; ; ; type lp1 % Linear prediction applications % lp1.m % Find filter model for a single vowel sound % Load the file [x fs bits]=wavread('missedit'); % Extract the /ae/ sound (as in "that") vowel (grab 512 samples) y=x(12071:12582); % Set the filter order n=15; % Find the filter coefficients a=lpc(y,n); a=real(a); % MATLAB 6 returns complex result % Show the spectrum of the original signal Y=fft(y); plot(0:(fs/2)/256:(fs/2)-(1/256), abs(Y(1:256))) xlabel('Frequency (Hz)') title('Spectrum of original signal') disp('press a key...') pause % Show the filter response H=freqz(1,a,0:pi/256:pi-(pi/256)); hold on plot(0:(fs/2)/256:(fs/2)-(1/256), abs(H),'r') title('Spectrum of original signal, and filter response (red)') hold off disp('press a key...') pause % Use bandlimited pulse to drive the filter at approx. the same fundamental freq % (this part is similar to the vowel method we did last time) f0=162; ss=blp(40,f0,f0,1,fs); z=filter(1,a,ss); % Listen to the original vowel sound for k=1:2 soundsc(y,fs) disp('Original sound...') pause % Listen to the synthesized vowel sound soundsc(z,fs) disp('Synthesized sound...') pause end type lp2 % Linear prediction applications % lp2.m % Find time-varying filter model for a sound clip % Load the file fname='missedit' %fname='crcmstnc' %fname='surprise' %fname='spock2' %fname='mkmydy' [x fs bits]=wavread(fname); % Set the block size N=300; % Set the filter order n=25; % Find the number of blocks that will fit, and trim input signal numblocks=floor(length(x)/N); x=x(1:numblocks*N); % Reshape the input vector input a matrix xb=reshape(x,N,numblocks); % Find the filter coefficients for each block [a g]=lpc(xb,n); a=real(a); % MATLAB 6 returns complex result % Show filter response as a mesh plot hh=zeros(128,numblocks); for i=1:numblocks [hh(:,i) ff]=freqz(1,a(i,:),128,fs); end if 0 mesh(1:numblocks,ff/1000,abs(hh)) axis('ij') xlabel('block number') ylabel('frequency (kHz)') title(['Filter model magnitude response: "' fname '"']) rotate3d on disp('press a key...') pause end % Show spectrogram of original image figure calspec(x,[],fs) title('Spectrogram of original sound') disp('press a key...') pause % Show filter response as an image figure imagesc(abs(hh)), axis('xy') title('Spectrogram of filter response') disp('press a key...') pause % Generate an excitation source for the filter f0=100; ss=blp(40,f0,f0,(length(x)-1)/fs,fs); % blp (simulates glottal pulses) % Reshape the input signal ssb=reshape(ss,N,numblocks); % Apply the filter y=zeros(size(ssb)); [y(:,1) z]=filter(g(1),a(1,:),ssb(:,1)); %generate state vector for k=2:numblocks [y(:,k) z]=filter(g(k),a(k,:),ssb(:,k),z); end % Reshape the output signal y=reshape(y,1,N*numblocks); % Listen to the original vowel sound soundsc(x,fs) disp('Original sound...') pause % Listen to the synthesized sound soundsc(y,fs) disp('Synthesized sound...') % Show the spectrogram of the synthesized sound figure calspec(y,[],fs) title('Spectrogram of synthesized sound') type lp2a % Linear prediction applications % lp2a.m % After running lp2 to compute the filter, can run % this script to try different excitation functions % Generate an excitation source for the filter f0=160; ss=blp(40,f0,f0,(length(x)-1)/fs,fs); % blp (simulates glottal pulses) %f0=100; ss=blp(40,f0,f0,(length(x)-1)/fs,fs); % blp (simulates glottal pulses) %f0=50; ss=blp(40,f0,f0,(length(x)-1)/fs,fs); % blp (simulates glottal pulses) %ss=randn(1,N*numblocks); % white noise %ss=square(2*pi*200*(0:1/fs:(length(x)-1)/fs)); % square wave %ss=sawtooth(2*pi*200*(0:1/fs:(length(x)-1)/fs)); % sawtooth wave %ss=sin(2*pi*200*(0:1/fs:(length(x)-1)/fs)); % sine wave %ss=wavread('eguitar'); ss=ss(1:N*numblocks); % electric guitar %ss=wavread('flute'); ss=ss(1:N*numblocks); % flute % Reshape the input signal ssb=reshape(ss,N,numblocks); % Apply the filter y=zeros(size(ssb)); [y(:,1) z]=filter(g(1),a(1,:),ssb(:,1)); %generate state vector for k=2:numblocks [y(:,k) z]=filter(g(k),a(k,:),ssb(:,k),z); end % Reshape the output signal y=reshape(y,1,N*numblocks); % Listen to the original sound if 0 soundsc(x,fs) disp('Original sound...') pause end % Listen to the synthesized sound soundsc(y,fs) disp('Synthesized sound...') % Show the spectrogram of the synthesized sound calspec(y,[],fs) title('Spectrogram of synthesized sound') edit lp1 lp1 press a key... press a key... Original sound... Synthesized sound... Original sound... Synthesized sound... delfigs edit lp2 lp2 fname = missedit press a key... press a key... Original sound... Synthesized sound... fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2.m'); clear lp2 delfigs lp2 fname = missedit fname = surprise press a key... press a key... Original sound... Synthesized sound... edit lp2a fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2a.m'); clear lp2a lp2a Synthesized sound... fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2a.m'); clear lp2a lp2a Synthesized sound... lp2a Synthesized sound... fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2a.m'); clear lp2a lp2a Synthesized sound... fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2a.m'); clear lp2a lp2a Synthesized sound... fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2.m'); clear lp2 lp2 fname = missedit fname = surprise fname = mkmydy press a key... press a key... Original sound... Synthesized sound... fschange('c:\personal\class\2001-02\spring\ece481\matlab\lp2a.m'); clear lp2a lp2a Synthesized sound... exit