Upload
pramod-surana
View
221
Download
1
Embed Size (px)
Citation preview
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
1/39
Computing Assignment 1 (EE 679)
Name- Pramod Kumar Surana
Roll No.-123070005
1. Given the following specification for a single-formant resonator, obtain the transfer
function of the filter H(z). Plot its magnitude response (dB magnitude versus frequency)
and impulse response.
F1 (formant) = 1 kHz
B1(bandwidth) = 200 Hz
Fs (sampling freq) = 16 kHz
Ans.- The general transfer function of a single formant resonator is given by
()
( )( )
Where
r is related to bandwidth B by B 2(1-r) when r 1. is resonance frequency. B and
should be in radians.
Here Fs= 16 kHz so =1000*2*pi/16000 =pi/8;
B=200*2*pi/16000 =pi/40;
r=1-pi/80 = (80-pi)/80;
A can be chosen depending on gain requirements, I have chosen A as 1/13;
Program for calculating frequency and impulse response of the above system is:
r=(80-pi)/80; %%Assign r
w0=pi/8; %%Assign w0
%%Assign two conjugate poles
p1=r*exp(1i*w0);
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
2/39
p2=r*exp(-1i*w0);
ww=0:5:8000;
H=filt(1/13,[1 -(p1+p2) p1*p2],1/16000); %%realize filter trans. func.
t=0:1/16000:2/100;
h=impulse(H,t); %%calculate impulse response over 0 to 20 ms
plot(t.*1000,h); %%plot impulse response
xlabel('time in ms');
ylabel('amplitude');
Hw=freqresp(H,exp(1i*ww.*(pi/8000))); %%calculate frequency response
n=size(Hw,3);
HH=reshape(Hw,n,1); %%convert freq. response to 2D matrix
figure;
semilogx(ww,mag2db(abs(HH))); %%plot frequency response
xlabel('frequency in Hz');
ylabel('gain in dB');
grid on;
Fig 1- Impulse response of the single formant resonator for Ques. 1
0 2 4 6 8 10 12 14 16 18 20-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
time in ms
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
3/39
Fig 2- Frequency response of the single formant resonator for Ques. 1
2. Excite the above resonator (filter) with a source given by an impulse train of F0 = 100
Hz. Compute the output of the source-filter system over the duration of 0.5 second. Plot the
time domain waveform. Also play it out and comment on the sound quality.
Ans. - The program for generating the impulse train of 100 Hz for .5 second duration and passing
it through the filter designed in question 1 is as follows- (h is the impulse response of the filter
designed in question 1, it is necessary to execute the code in program 1 before this code in orderto pass the pulse train through filter)
fs=16000; %%set sampling frequency
rep=1:1:50; %%no. of periods
D=rep.*1e-2; %%set time period of .1 s (F0=100Hz)
te=0:1/fs:.5; %%create sample points
100
101
102
103
104
-35
-30
-25
-20
-15
-10
-5
0
5
10
frequency in Hz
gainindB
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
4/39
w=1e-3; %%width of pulse
yp=1/4*(pulstran(te,D,@rectpuls,w)); %%generate pulse train
plot(te,yp); %%plot pulse train
axis([0 .5 -.5 .5]);
xlabel('time in seconds');
ylabel('amplitude');
ww=conv(h,yp); %%pass the pulse train through filter
te1=0:1/fs:.52;
figure;
plot(te1,ww); %%plot the filter output
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pk.wav'); %%covert the output to sound file
Fig 3- Pulse train of frequency 100 Hz and duration .5 seconds
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
time in seconds
amplitu
de
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
5/39
Fig 4- Output of filter designed in question 1 when excited by pulse train shown in figure 3.
Fig 5- Enlarged version of filter output waveform
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.05
0
0.05
0.1
0.15
0.2
0.25
0.3
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
6/39
Comment-
Output waveform is periodic due to periodicity of the pulse train and like the repetition of
the impulse response. Sound obtained after passing the pulse train through the filter is a bit harsh
and not like natural sounds.
3. Vary the parameters as indicated below and comment on the differences in waveform
and sound quality for the different parameter combinations.
(a) F1 = 300 Hz, B1 = 100 Hz; F1=1200 Hz, B1 = 200 Hz
(b) F0 = 80 Hz; F0 = 150 Hz
Ans- (a) first case F1=300 Hz, B1=100 Hz, Fs=16 kHz, F0=100 Hz
So here we get B1= 100*2*pi/16000= pi/80 radians;
So r=1- pi/(80*2)= (160-pi)/160;
W0=300*2*pi/16000= 3*pi/80 radians;
Code for generating above filter is-
r=(160-pi)/160; %%set value of r
w0=3*pi/80; %%set value of w0
p1=r*exp(1i*w0); %%set poles
p2=r*exp(-1i*w0);
ww=0:5:8000;
H=filt(1/13,[1 -(p1+p2) p1*p2],1/16000); %%realize filter
t=0:1/16000:2/100;
h=impulse(H,t); %%compute impulse response
plot(t.*1000,h); %%plot impulse response
xlabel('time in ms');
ylabel('amplitude');
Hw=freqresp(H,exp(1i*ww.*(pi/8000))); %%compute freq. response
n=size(Hw,3);
HH=reshape(Hw,1,n);
figure;
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
7/39
semilogx(ww,mag2db(abs(HH))); %%plot freq. response
xlabel('frequency in Hz');
ylabel('gain in dB');
grid on;
Fig 6- Impulse response of filter with F1=300 Hz and B1=100 Hz
0 2 4 6 8 10 12 14 16 18 20-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
time in ms
am
plitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
8/39
Fig 7- Frequency response of filter with F1=300 Hz and B1=100 Hz
100
101
102
103
104
-40
-30
-20
-10
0
10
20
30
frequency in Hz
gainindB
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-1.5
-1
-0.5
0
0.5
1
1.5
2
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
9/39
Fig 8-Output of filter with F1=300 Hz and B1=100 Hz when excited with 100 Hz pulse train
Comment-
Waveform of output has damping sinusoids with less frequency than the question 1 filter
as the resonance frequency of this filter is only 300 Hz. Sound appears to be somewhat softer
than the sound output of F1= 1 kHz filter.
Second case F1=1200 Hz, B1=200 Hz, Fs=16 kHz, F0=100 Hz
So here we get B1= 200*2*pi/16000= pi/40 radians;
So r=1- pi/(40*2)= (80-pi)/80;
W0=1200*2*pi/16000= 12*pi/80 radians;
Code for generating above filter is-
r=(80-pi)/80; %%set value of r
w0=12*pi/80; %%set value of w0
p1=r*exp(1i*w0); %%set poles
p2=r*exp(-1i*w0);
ww=0:5:8000;
H=filt(1/13,[1 -(p1+p2) p1*p2],1/16000); %%realize filter
t=0:1/16000:2/100;h=impulse(H,t); %%compute impulse response
plot(t.*1000,h); %%plot impulse response
xlabel('time in ms');
ylabel('amplitude');
Hw=freqresp(H,exp(1i*ww.*(pi/8000))); %%compute freq. response
n=size(Hw,3);
HH=reshape(Hw,1,n);
figure;
semilogx(ww,mag2db(abs(HH))); %%plot freq. responsexlabel('frequency in Hz');
ylabel('gain in dB');
grid on;
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
10/39
Fig 9- Impulse response of filter with F1=1200 Hz and B1=200 Hz
Fig 10- Impulse response of filter with F1=1200 Hz and B1=200 Hz
0 2 4 6 8 10 12 14 16 18 20-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
time in ms
amplitude
100
101
102
103
104
-40
-35
-30
-25
-20
-15
-10
-5
0
5
10
frequency in Hz
gainindB
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
11/39
Fig 11- Output of filter with F1=1200 Hz and B1=200 Hz when excited by 100 Hz pulse train
Code for exciting the above filter with 100 Hz pulse train is-fs=16000; %%set sampling frequency
rep=1:1:50; %%no. of periods
D=rep.*1e-2; %%set time period of .1 s (F0=100Hz)
te=0:1/fs:.5; %%create sample points
w=1e-3; %%width of pulse
yp=1/4*(pulstran(te,D,@rectpuls,w)); %%generate pulse train
plot(te,yp); %%plot pulse train
axis([0 .5 -.5 .5]);
xlabel('time in seconds');ylabel('amplitude');
ww=conv(h,yp); %%pass the pulse train of .5 second
duration through filter
te1=0:1/fs:.05;
figure;
plot(te1,ww(1:801)); %%plot the filter output
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
12/39
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pk.wav'); %%covert the output to sound file
Comment-
Output has more variations due to high resonance frequency. Slightly more sharper sound
than 1 kHz filter, difficult to distinguish perceptually from the 1 kHz filters sound.
(b) F0 = 80 Hz; F0 = 150 Hz
First case F0 = 80 Hz
The code for generating 80 Hz impulse train and passing through the filter in question 1 is as
follows (code for questions 1 filter should be executed first)-
fs=16000; %%set sampling frequency
rep=1:1:46; %%no. of periods
D=rep.*1.25e-2; %%set time period of .1 s (F0=100Hz)
te=0:1/fs:.5; %%create sample points
w=1e-3; %%width of pulse
yp=1/4*(pulstran(te,D,@rectpuls,w)); %%generate pulse train
plot(te,yp); %%plot pulse train
axis([0 .5 -.5 .5]);
xlabel('time in seconds');
ylabel('amplitude');
ww=conv(h,yp); %%pass the pulse train through filter
te1=0:1/fs:.05;
figure;
plot(te1,ww(1:801)); %%plot the filter output
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pk.wav'); %%covert the output to sound file
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
13/39
Fig 12- Pulse train with frequency of 80 Hz
Fig 13- Output of filter realized in question 1 when excited with 80 Hz pulse train
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
time in seconds
amplitude
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
14/39
Fig 14- Enlarged view of output
Comment-
Output is periodic but period is more as compared to the output due to 100 Hz pulse train.
Sound has less continuity when heard (something like trrrrrrr).
Second case F0 = 150 Hz
The code for generating 150 Hz impulse train and passing through the filter in question 1 is as
follows (code for questions 1 filter should be executed first)-
fs=16000; %%set sampling frequency
rep=1:1:75; %%no. of periodsD=rep.*1e-2/1.5; %%set time period of .1 s
(F0=100Hz)
te=0:1/fs:.5; %%create sample points
w=1e-3; %%width of pulse
yp=1/4*(pulstran(te,D,@rectpuls,w)); %%generate pulse train
plot(te,yp); %%plot pulse train
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.05
0
0.05
0.1
0.15
0.2
0.25
0.3
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
15/39
axis([0 .5 -.5 .5]);
xlabel('time in seconds');
ylabel('amplitude');
ww=conv(h,yp); %%pass the pulse train through filter
te1=0:1/fs:.52;
figure;
plot(te1,ww); %%plot the filter output
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pk.wav'); %%covert the output to sound file
Fig 15- Pulse train with frequency of 150 Hz
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5-0.5
-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
16/39
Fig 16- Output of filter realized in question 1 when excited with 150 Hz pulse train
Fig 17- Enlarged view of output waveform in figure 16.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.05
0
0.05
0.1
0.15
0.2
0.25
0.3
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
17/39
Comment-
Sound appears to have less trrrr like effect. Sound is sharper.
4. In place of the simple single-resonance signal, synthesize the following more realistic
vowel sounds at two distinct pitches (F0 = 80 Hz, F0 = 220 Hz). Keep the bandwidths
constant at 100 Hz for all formants. Duration of sound: 0.5 sec
Vowel F1, F2, F3
/a/ 730, 1090, 2440
/i/ 270, 2290, 3010
/u/ 300, 870, 2240
Ans- Vowel /a/
Filter for /a/-
The filter can be realized as some of three filters with single resonances equal to formant
frequencies.
Here r = 1- pi/160 = (160-pi)/pi;
And w01 = 73*pi/80; w02 = 109*pi/80; w03= 244*pi/80;
()
( )()
( )()
( )()
Where pi = r*exp(j*w0i) for i= 1,2,3
Code for realizing this filter is
r=(160-pi)/160;
w01=73*pi/800; %%first formant
w02=109*pi/800; %%second formant
w03=244*pi/800; %%third formant
%%poles for first formant
p11=r*exp(1i*w01);
p12=r*exp(-1i*w01);
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
18/39
%%poles for second formant
p21=r*exp(1i*w02);
p22=r*exp(-1i*w02);
%%poles for third formant
p31=r*exp(1i*w03);
p32=r*exp(-1i*w03);
ww=0:10:8000;
H1=filt(1/52,[1 -(p11+p12) p11*p12],1/16000); %%tf of first filter
H2=filt(1/33,[1 -(p21+p22) p21*p22],1/16000); %%tf of second filter
H3=filt(1/16,[1 -(p31+p32) p31*p32],1/16000); %%tf of third filter
Ha=H1+H2+H3; %%tf of composite filter with
three formants
t=0:1/16000:3/100;
ha=impulse(Ha,t); %%compute impulse response of
filter
plot(t.*1000,ha); %%plot impulse response
xlabel('time in ms');
ylabel('amplitude');
Haw=freqresp(Ha,exp(1i*ww.*(pi/8000))); %%compute frequency response
n=size(Haw,3);
HaH=reshape(Haw,n,1);
figure;
semilogx(ww,mag2db(abs(HaH))); %%plot frequency response
xlabel('frequency in Hz');
ylabel('gain in dB');
grid on;
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
19/39
Fig 18- Impulse response of the filter for generating vowel /a/
Fig 19- Frequency response of the filter for generating vowel /a/
0 5 10 15 20 25 30-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
time in ms
amplitude
101
102
103
104
-40
-35
-30
-25
-20
-15
-10
-5
0
5
10
frequency in Hz
gainindB
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
20/39
Code for generating /a/ with pitches 80 and 220 Hz is as follows-
fs=16000;
rep=1:1:66;
D=rep.*1.25e-2;
te=0:1/fs:.5;
w=1e-3;
yp=1/4*(pulstran(te,D,@rectpuls,w));
ww=conv(ha,yp);
te1=0:1/fs:.05;
plot(te1,ww(1:801));
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pka80.wav');
fs=16000;
rep=1:1:110;
D=rep.*1e-2/2.2;
w=1e-3;
yp1=1/4*(pulstran(te,D,@rectpuls,w));
ww1=conv(ha,yp1);
figure;
plot(te1,ww1(1:801));
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp1,fs,'pk220.wav');
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
21/39
Fig 20- Waveform of vowel /a/ generated by pulse train of 80 Hz
Fig 21- Enlarged view of fig 20
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
22/39
Fig 22- Waveform of vowel /a/ generated by pulse train of 220 Hz
Fig 23- Enlarged view of fig 22
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
23/39
Comments-
Sound generated with 80 Hz pitch is not so good in quality (have more trrrrr like
effect), sound generated with 220 Hz is like some musical instrument sound.
Vowel /i/
Filter for /i/-
The filter can be realized as some of three filters with single resonances equal to formant
frequencies.
Here r = 1- pi/160 = (160-pi)/pi;
And w01 = 27*pi/80; w02 = 229*pi/80; w03= 301*pi/80;
()
( )()
( )()
( )()
Where pi = r*exp(j*w0i) for i= 1,2,3
Code for realizing this filter is
r=(160-pi)/160;
w01=27*pi/800; %%first formantw02=229*pi/800; %%second formant
w03=301*pi/800; %%third formant
%%poles for first formant
p11=r*exp(1i*w01);
p12=r*exp(-1i*w01);
%%poles for second formant
p21=r*exp(1i*w02);
p22=r*exp(-1i*w02);
%%poles for third formantp31=r*exp(1i*w03);
p32=r*exp(-1i*w03);
ww=0:10:8000;
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
24/39
H1=filt(1/52,[1 -(p11+p12) p11*p12],1/16000); %%tf of first filter
H2=filt(1/33,[1 -(p21+p22) p21*p22],1/16000); %%tf of second filter
H3=filt(1/16,[1 -(p31+p32) p31*p32],1/16000); %%tf of third filter
Hi=H1+H2+H3; %%tf of composite filter with
three formants
t=0:1/16000:3/100;
ha=impulse(Ha,t); %%compute impulse response of
filter
plot(t.*1000,ha); %%plot impulse response
xlabel('time in ms');
ylabel('amplitude');
Hiw=freqresp(Ha,exp(1i*ww.*(pi/8000))); %%compute frequency response
n=size(Hiw,3);HiH=reshape(Hiw,n,1);
figure;
semilogx(ww,mag2db(abs(HiH))); %%plot frequency response
xlabel('frequency in Hz');
ylabel('gain in dB');
grid on;
Fig 24Impulse response of the filter for generating vowel /i/
0 5 10 15 20 25 30-0.1
-0.05
0
0.05
0.1
0.15
time in ms
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
25/39
Fig 25Frequency response of the filter for generating vowel /i/
Code for generating vowel /i/ with 80 and 220 Hz pitch-
fs=16000;
rep=1:1:66;
D=rep.*1.25e-2;
te=0:1/fs:.5;
w=1e-3;
yp=1/4*(pulstran(te,D,@rectpuls,w));
ww=conv(hi,yp);
te1=0:1/fs:.53;
te2=0:1/fs:.05;
plot(te1,ww);
xlabel('time in seconds');
ylabel('amplitude');
figure;
plot(te2,ww(1:801));
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pki80.wav');
101 102 103 104-40
-35
-30
-25
-20
-15
-10
-5
0
5
10
frequency in Hz
gainindB
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
26/39
fs=16000;
rep=1:1:110;
D=rep.*1e-2/2.2;
w=1e-3;yp1=1/4*(pulstran(te,D,@rectpuls,w));
ww1=conv(hi,yp1);
figure;
plot(te1,ww1);
xlabel('time in seconds');
ylabel('amplitude');
figure;
plot(te2,ww1(1:801));
xlabel('time in seconds');ylabel('amplitude');
wavwrite(yp1,fs,'pki220.wav');
Fig 26- Vowel /i/ generated with 80 Hz pulse train
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
27/39
Fig 27- Enlarged view of fig 26
Fig 28- Vowel /i/ generated with 220 Hz pulse train
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
28/39
Fig 29- Enlarged view of fig 28
Comments-
Sound generated with 80 Hz pitch is not so good in quality ( have more trrrrr effect),
sound generated with 220 Hz is like some musical instrument sound. Identifying the vowel is
more difficult at 80 Hz pitch.
Vowel /u/
Filter for /u/-
The filter can be realized as some of three filters with single resonances equal to formant
frequencies.
Here r = 1- pi/160 = (160-pi)/pi;
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
29/39
And w01 = 30*pi/80; w02 = 87*pi/80; w03= 224*pi/80;
()
( )()
( )()
( )()
Where pi = r*exp(j*w0i) for i= 1,2,3
Code for realizing this filter is
r=(160-pi)/160;
w01=30*pi/800; %%first formant
w02=87*pi/800; %%second formant
w03=224*pi/800; %%third formant
%%poles for first formant
p11=r*exp(1i*w01);p12=r*exp(-1i*w01);
%%poles for second formant
p21=r*exp(1i*w02);
p22=r*exp(-1i*w02);
%%poles for third formant
p31=r*exp(1i*w03);
p32=r*exp(-1i*w03);
ww=0:10:8000;
H1=filt(1/52,[1 -(p11+p12) p11*p12],1/16000); %%tf of first filter
H2=filt(1/33,[1 -(p21+p22) p21*p22],1/16000); %%tf of second filter
H3=filt(1/16,[1 -(p31+p32) p31*p32],1/16000); %%tf of third filter
Hu=H1+H2+H3; %%tf of composite filter with
three formants
t=0:1/16000:3/100;
hu=impulse(Ha,t); %%compute impulse response of
filter
plot(t.*1000,hu); %%plot impulse response
xlabel('time in ms');
ylabel('amplitude');
Hiw=freqresp(Hu,exp(1i*ww.*(pi/8000))); %%compute frequency response
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
30/39
n=size(Hiw,3);
HuH=reshape(Huw,n,1);
figure;
semilogx(ww,mag2db(abs(HuH))); %%plot frequency response
xlabel('frequency in Hz');
ylabel('gain in dB');
grid on;
Fig 30Impulse response of the filter for generating vowel /u/
0 5 10 15 20 25 30-0.1
-0.05
0
0.05
0.1
0.15
time in ms
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
31/39
Fig 31Impulse response of the filter for generating vowel /u/
Code for generating vowel /u/ with 80 and 220 Hz pitches is-
fs=16000;
rep=1:1:66;
D=rep.*1.25e-2;
te=0:1/fs:.5;
w=1e-3;
yp=1/4*(pulstran(te,D,@rectpuls,w));
ww=conv(hu,yp);
te1=0:1/fs:.53;
te2=0:1/fs:.05;
plot(te1,ww);
xlabel('time in seconds');
ylabel('amplitude');
figure;
plot(te2,ww(1:801));
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp,fs,'pku80.wav');
101
102
103
104-40
-35
-30
-25
-20
-15
-10
-5
0
5
10
frequency in Hz
gainindB
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
32/39
fs=16000;
rep=1:1:110;
D=rep.*1e-2/2.2;
w=1e-3;
yp1=1/4*(pulstran(te,D,@rectpuls,w));
ww1=conv(hu,yp1);
figure;
plot(te1,ww1);
xlabel('time in seconds');
ylabel('amplitude');
figure;
plot(te2,ww1(1:801));
xlabel('time in seconds');
ylabel('amplitude');
wavwrite(yp1,fs,'pku220.wav');
Fig 32- Vowel /u/ generated with 80 Hz pulse train
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
33/39
Fig 33- Enlarged view of figure 32
Fig 34- Vowel /u/ generated with 220 Hz pulse train
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
34/39
Fig 35- Enlarged view of figure 34
Comments-
Sound generated with 80 Hz pitch is not so good in quality (have trrrrr like effect),
sound generated with 220 Hz is like some musical instrument sound.
5. Signal Analysis:
Compute the DTFT magnitude spectrum of any 2 of the vowel sounds you have
synthesized. Use rectangular and Hamming windows of lengths: 40 ms, 100 ms. (i)
Comment on the similarities and differences between the different spectra. (ii) Estimate the
signal parameters from each of the spectra and compare with the ground-truth.
Ans. -The sound signals of vowel /u/ with 80 Hz pitch and /i/ with 220 Hz pitch are analyzed.
The code for computing spectrum of both signals with rectangular window of 40 ms and
hamming window of 100 ms is as follows (1024 point fft is used for rectangular windowed
signal and 2048 point fft is used for hamming windowed signal)
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
time in seconds
amplitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
35/39
fs=16000; %%select sampling frequency
u80=wavread('pku80.wav'); %%read sound files
i220=wavread('pki220.wav');
u80=5.*(u80.');i220=5.*(i220.');
wr=rectwin(.04*fs); %%create rectangular window of 40 ms
wh=hamming(.1*fs); %%create hamming window of 100ms
wr=wr.';
wh=wh.';
%%apply both windows on u80 one by one
urw80=u80(16:(15+.04*fs)).*wr;
uhw80=u80(16:(15+.1*fs)).*wh;
%%apply both windos of i220 one by one
urw220=u80(16:(15+(.04*fs))).*wr;
uhw220=u80(16:(15+(.1*fs))).*wh;
fr = fs/2*linspace(0,1,513);
fh = fs/2*linspace(0,1,1025);
%%compute fourier transform
Uur=fft(urw80,1024);
Uuh=fft(uhw80,2048);
Uir=fft(urw220,1024);
Uih=fft(uhw220,2048);
plot(fr,mag2db(abs(Uur(1:513))));
xlabel('frequency in Hz');
ylabel('magnitude');figure;
plot(fh,mag2db(abs(Uuh(1:1025))));
xlabel('frequency in Hz');
ylabel('magnitude');
figure;
plot(fr,mag2db(abs(Uir(1:513))));
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
36/39
xlabel('frequency in Hz');
ylabel('magnitude');
figure;
plot(fh,mag2db(abs(Uih(1:1025))));
xlabel('frequency in Hz');
ylabel('magnitude');
Fig 36 -Magnitude spectrum of /u/ with 80 Hz pitch using rectangular window of size 40ms and
using 1024 point FFT.
0 1000 2000 3000 4000 5000 6000 7000 8000-40
-30
-20
-10
0
10
20
30
40
frequency in Hz
magnitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
37/39
Fig 37 -Magnitude spectrum of /u/ with 80 Hz pitch using hamming window of size 100ms and
using 2048 point FFT.
0 1000 2000 3000 4000 5000 6000 7000 8000-100
-80
-60
-40
-20
0
20
40
frequency in Hz
magnitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
38/39
Fig 38 -Magnitude spectrum of /i/ with 220 Hz pitch using rectangular window of size 40ms and
using 1024 point FFT.
0 1000 2000 3000 4000 5000 6000 7000 8000-40
-30
-20
-10
0
10
20
30
40
frequency in Hz
magnitude
7/30/2019 Computing Assignment 1(Pramod Kumar Surana)
39/39
Fig 39 -Magnitude spectrum of /i/ with 220 Hz pitch using hamming window of size 100ms and
using 2048 point FFT.
(i) The spectrum in figure 37 and 39 has more spreading than in figure 36 and 38. Hence
hamming windowed spectrum has more spreading than rectangular windowed spectrum.
(ii)
The distance between two impulses in figure 36 and 37 is coming out to be 80 Hz that is equal to
the actual pitch period.
The distance between two impulses in figure 38 and 39 is coming out to be 220 Hz that is equal
to the actual pitch period.
The formants are not so apparent and are not measurable from the spectrums.
0 1000 2000 3000 4000 5000 6000 7000 8000-100
-80
-60
-40
-20
0
20
40
frequency in Hz
magnitude