close all; clear all;
[x, Fs] = audioread('male_speaker.wav');
plot(x)
title('Speech Signal')
ts=1/Fs; window_sec=0.020; num_samples=round(window_sec/ts);
t = 0 : 1/Fs : num_samples/Fs;
voice_start=31000; %from inspection of the signal
x_voiced=x(voice_start:voice_start+num_samples);
figure
plot(t,x_voiced)
axis([0 num_samples/Fs -(max(x_voiced)+.1) max(x_voiced)+.1])
title('Voiced Part of Speech')
%determine lpc coefficients
p_order=10;
a_voiced=lpc(x_voiced,p_order);
%-----
%look at xcoor
xcorr_lenght=num_samples/2;
[auto_corr_voiced,lags] = xcorr(x_voiced,xcorr_lenght,'coeff');
figure
stem(lags,auto_corr_voiced)
title('Correlation Coeffiecent of Voiced Part of Speech')
%-----
%FFT method of modeling signal source, using num_sample as length of fft
fft_len=num_samples;
fft_voiced=fft(x_voiced, fft_len);
y = linspace(0,Fs/2,fft_len/2);
figure
stem(y, abs(fft_voiced(1:length(fft_voiced)/2)))
axis([0 1500 0 max(abs(fft_voiced))])
title('Fourier Transform of Voiced')
%inverse fft to create signal source with smaller number of coefficents
%picking 50 coef below.
num_fft_coef=50;
trun_fft_coef=[fft_voiced(1:num_fft_coef); zeros(length(fft_voiced)-num_fft_coef,1)];
voiced_signal_source=real(ifft(trun_fft_coef)); %this creates the time sequence
%create estimate of speech signal using lpc filter and ifft sequence as the source
estimated_voice=filter([0 -a_voiced(2:end)],1, voiced_signal_source);
%pad with a zero so same length as original sequence
estimated_voice=[0; estimated_voice];
figure
plot(t,x_voiced)
hold on
plot(t,(estimated_voice), '-r')
title('Comparison of Original Speech and FFT Recreated Speech with LPC order 10')
%---------
%using dct method of modeling signal source
voiced_dct_coef = dct(x_voiced,num_samples);
%truncate the number of dct
num_dct_coef=60;
trun_dct_coef=[voiced_dct_coef(1:num_dct_coef); zeros(length(voiced_dct_coef)-num_dct_coef,1)];
%inverse dct (recreate voiced signal with smaller number of dct coefficents
idct_voiced=idct(trun_dct_coef);%this creates the time sequence from dct
%create estimate of speech signal using lpc filter and idct sequence as the
%source
estimated_voice_idct=filter([0 -a_voiced(2:end)],1, idct_voiced);
%pad with a zero so same length
estimated_voice_idct=[0; estimated_voice_idct];
figure
plot(t,x_voiced)
hold on
plot(t,estimated_voice_idct, '-r')
title('Comparison of Original Speech and DCT Recreated Speech with LPC order 10')
%---
%write the files to disc
%wavwrite(x_voiced,Fs,'original_speech')
%wavwrite(estimated_voice_idct,Fs,'reconstructed_speech_idct')
%wavplay(estimated_voice_idct,Fs)