%%% Real-Time Speech Pitch Shifting on an FPGA %%% Estephan, Sawyer, Wanninger %%% M-File by Habib Estephan (2006) %%% Villanova University %%% Department of Electrical and Computer Engineering clear; clc Nin=wavread('freddie_mono.wav'); %input wave Nin=Nin'; %Input's transpose to make it a 1xM array SampleFreq=44100; %Sampling Frequency of the input windowsize=1800; %Specifies the Size of the block estimperiod=(5e-3)*SampleFreq; %Calculates the number of samples in 5 ms of signal %which is the typical period of human's %speech fundemental frequency maxnumperiod=floor(windowsize/estimperiod) %Calculates the total periods in one block numperiod=2 %Specifies the number of periods taken out of each block if numperiod>maxnumperiod %this if statement gurantees that the number of truncated periods is less %than the total number of periods in that %specific block nunmperiod=maxnumperiod-1; end x=round(length(Nin)/windowsize); Nout=floor(windowsize*x-numperiod*estimperiod); Output=zeros(1,100); %Defines the output vector that will contain the truncated blocks %from the input vector for n=1:round((length(Nin)/windowsize)) start=windowsize*n+(1-windowsize) %points to the beginning of the next block from the input last=floor(windowsize*n-numperiod*estimperiod) %points to the end of the next block from the input section=Nin(start:last); %Section will contain the current block through each iteration l=length(section); %Length of Section st=n*l+1-l; %points to the location of insertion of the truncated block into the output vector lst=n*l; %points to the final location of the truncated block into the output vector Output(st:lst)=section; %Output vector end ratio=length(Output)/length(Nin); [t,d]=rat(ratio); %returns the the ratio as a fraction, where the Numerator is stored in t %and the denominator is stored in d. Out1=resample(Output,d,t); %in order to play the outputed signal at the same rate we %have resample it at %a rate that d/t the current sampling rate %in order to rescale the output vector and %make it the same length as the %input Sound(Out1,SampleFreq)