% EE 438 Digital Signal Processing with Applications - Spring 1997 % A speech signal is downsampled and upsampled, the spectra % are plotted, and the signals are run through the sound card. % No low-pass filtering is performed in either case. %--------------------------------------------------------------- % Initialize clear all; close all; %--------------------------------------------------------------- % Parameters D = 4 % downsampling/upsampling factor %--------------------------------------------------------------- %Read and play back data sampled at 8192Hz Fs = 8192; data=load('erf1s1t0'); %plot(data) %end1=input('end1?'); %end2=input('end2?'); %end1 = 1 %end2 = end1+8191; %x=data(end1:end2); x=data; x(8192)=0; % zero-pad if lenth(data) < 8192 x=x(1:8192); N = length(x) %--------------------------------------------------------------- % Downsampling by D n = 1:1:N; t = (n-1)./Fs; z = zeros(1,N); z(1:ceil(N/D)) = x(1:D:N); z(ceil(N/D)+1:N) = zeros(1,N-ceil(N/D)); figure(1); subplot(2,1,1), plot(t,x); xlabel('t sec'); title('Original utterance'); subplot(2,1,2), plot(t,z); xlabel('t sec'); title('Utterance downsampled by D'); X = fft(x); X = fftshift(X); Xmag = abs(X); Z = fft(z); Z = fftshift(Z); Zmag = abs(Z); delta_f = Fs./(N.*1000); nf = -N./2:1:N/2-1; f = nf .* delta_f; figure(2); subplot(2,1,1), plot(f,Xmag); xlabel('f kHz'); title('Original utterance'); subplot(2,1,2), plot(f,Zmag); xlabel('f kHz'); title('Utterance downsampled by D'); input('Original utterance') soundsc(x,Fs); input('Utterance downsampled by D') soundsc(z,Fs); input('Utterance downsampled by D, played at Fs/D') soundsc(z,Fs./D); %--------------------------------------------------------------- % Upsampling by D z = zeros(1,D.*N); z(1:D:D.*N) = x(1:N); x_extend = x; x_extend(N+1:D.*N) = zeros(1,(D-1).*N); n_extend = 1:1:D.*N; t_extend = n_extend./Fs; figure(1); subplot(2,1,1), plot(t_extend,x_extend); xlabel('t sec'); title('Original utterance'); subplot(2,1,2), plot(t_extend,z); xlabel('t sec'); title('Utterance upsampled by D'); X_extend = fft(x_extend); X_extend = fftshift(X_extend); Xmag_extend = abs(X_extend); Z = fft(z); Z = fftshift(Z); Zmag = abs(Z); delta_f = Fs./(D.*N.*1000); nf = -D.*N./2:1:D.*N/2-1; f = nf .* delta_f; figure(2); subplot(2,1,1), plot(f,Xmag_extend); xlabel('f kHz'); title('Original utterance'); subplot(2,1,2), plot(f,Zmag); xlabel('f kHz'); title('Utterance upsampled by D'); input('Original utterance') soundsc(x,Fs); input('Utterance upsampled by D') soundsc(z,Fs); input('Utterance upsampled by D, played at Fs*D') soundsc(z,Fs*D);