MATLAB Code Section 1, a. - c.
MATLAB Code Section 1, a. - c.
%%
% Project 3, Engineering Acoustics
% Question 1
% a) - c)
fs= 44100;
rec= audiorecorder(fs, 16, 1);
%%
record(rec);
%%
stop(rec);
%%
y= getaudiodata(rec);
%%
wavwrite(real(y), fs, 'voiced name 44100.wav')
%%
sound(real(y), fs)
%%
t= linspace(0, length(y) ./ fs, length(y));
subplot 311
plot(t, real(y))
axis tight
xlabel('Time (sec)')
ylabel('Amplitude')
title('"Mark Freeman"')
total_time= length(y) / fs; % sec
az= 0;
el= 90;
toffset= 0;
offset= toffset * fs;
win_time= 0.02;
wtime= win_time/4;
win= round(wtime * fs);
h= hamming(win);
percent_overlap= 0.9;
hop= round(win * (1- percent_overlap));
for i= 0: floor((total_time * fs) / hop) - 10
s= y((i * hop)+1 + offset : floor((i * hop)+win+offset), 1);
s= s .* h;
S= 20.*log10(abs(fft(s)));
if i == 0
Z1= S(1:round(length(S)/2));
else
Z1= cat(2, Z1, S(1:round(length(S)/2)));
end
end
subplot 312
t1= linspace(0+toffset, total_time+toffset, floor((total_time * fs) / hop +1) - 10);
f= linspace(0, fs/2, (win + 1)/2);
[X,Y]= meshgrid(t1, f);
surf(X,Y,Z1)
axis tight
ylabel('Freq (Hz)')
xlabel('Time (sec)')
zlabel('Power')
lighting phong
shading interp
view(az,el)
xlabel('Time (sec)')
ylabel('Freq (Hz)')
title('Wideband')
wtime= win_time;
win= round(wtime * fs);
h= hamming(win);
percent_overlap= 0.97;
hop= round(win * (1- percent_overlap));
for i= 0: floor((total_time * fs) / hop) - 34
s= y((i * hop)+1 + offset : round((i * hop)+win+offset), 1);
s= s .* h;
S= 20.*log10(abs(fft(s)));
if i == 0
Z2= S(1:round(length(S)/2));
else
Z2= cat(2, Z2, S(1:round(length(S)/2)));
end
end
subplot 313
t1= linspace(0+toffset, total_time+toffset, floor((total_time * fs) / hop +1) - 34);
f= linspace(0, fs/2, (win + 1)/2);
[X,Y]= meshgrid(t1, f);
surf(X,Y,Z2)
axis tight
ylabel('Freq (Hz)')
xlabel('Time (sec)')
zlabel('Power')
lighting phong
shading interp
view(az,el)
xlabel('Time (sec)')
ylabel('Freq (Hz)')
title('Narrowband')
%%
print 'Voice Utterance 44100, dB' -djpeg100 -r200