Does anyone explain me how pitch modification working?
7 views (last 30 days)
Show older comments
Hi!
Please somebody explain me how pitch modification working. I don't understand exactly what does it do. I got an error message about the function line. Anyone know why? I would like to pitch modify some wave files, but firstly want to know what exactly do.
Thx in advance
Here is the code:
%%Pitch modification
[x Fs nBits] = wavread(filename);
x = x(:);
sent_L = length(x);
semitone = round(semitone);
if semitone>12|semitone<-12
semitone = 0;
fprintf('semitone has to be in [-12 12], where\n ')
end
scale = 2^(semitone/12);
Le = 160;
S = Le/4;
overlap = Le - S;
Nframe = floor((sent_L-overlap)/S); %lefelé kerekít
Lq = round(Le*scale);
a = 0.50;
b = -0.50;
n = 1:Le;
win = sqrt(S)/sqrt((4*a^2+2*b^2)*Le)*(a+b*cos(2*pi*n/Le));
win = win(:);
n = 1:Lq;
winq = sqrt(S)/sqrt((4*a^2+2*b^2)*Lq)*(a+b*cos(2*pi*n/Lq));
winq = winq(:);
Nit = 4;
xfinal = zeros(sent_L,1);
U = sum(win)/(S);
k = 1;
kk = 1;
h = waitbar(0,'Please wait...');
for n = 1:Nframe
if k:k+Lq-1<=sent_L
frm = winq.*x(k:k+Lq-1)/U;
else
frm = winq.*[x(k:sent_L);zeros(Lq - (sent_L-k+1),1)]/U;
end
frm_resamp = resample(frm, Le, Lq);
xSTFTM = abs(fft(frm_resamp));
if k+Le-1<=sent_L
res = xfinal(k:k+e-1);
else
res = [xfinal(k:sent_L);zeros(Le - (sent_L-k+1),1)];
end
x_recon = iterated_recon(xSTFTM, res, Nit, win);
if (k+Le-1<=sent_L)
xfinal(k:k+Le-1) = xfinal(k:k+Le-1) + x_recon;
else
xfinal(k:sent_L) = xfinal(k:sent_L) + x_recon(1:sent_L-k+1);
end
k = k + S;
waitbar(n/Nframe, h)
end
close(h)
outfile = [filename(1:end-4),'_pitch_recon.wav'];
wavwrite(xfinal, Fs, outfile);
function x_recon = iterated_recon(xSTFTM, x_res, Nit, win)
j = sqrt(-1);
for i = 1:Nit
phi = phase(fft(win.*x_res)) + randn(size(x_res))*0.01*pi;
% random phase purturbation will reduce some resonance.
x = xSTFTM.*exp(j*phi); %M-constraint
x_recon = ifft(x);
x_res = real(x_recon);
end
x_recon = x_res;
0 Comments
Accepted Answer
Walter Roberson
on 3 Sep 2013
The part of your file before the "function" line is known in MATLAB terms as a "script". It is not allowed in MATLAB to store a "script" and a "function" in the same file. You will need to move the function into the file iterated_recon.m
0 Comments
More Answers (0)
See Also
Categories
Find more on Propagation and Channel Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!