谢谢大家了,只要翻译得出来,分不是问题可以再加,谢谢大家帮忙...
这是用法
[d,sr]=wavread('sf1_cln.wav');
% 1024 samples is about 60 ms at 16kHz, a good window
y=pvoc(d,.75,1024);下面是文件
///////////pvoc.m/////////////
function y = pvoc(x, r, n)
% y = pvoc(x, r, n) Time-scale a signal to r times faster with phase vocoder
% x is an input sound. n is the FFT size, defaults to 1024.
% Calculate the 25%-overlapped STFT, squeeze it by a factor of r,
% inverse spegram.
% 2000-12-05, 2002-02-13 [email protected]. Uses pvsample, stft, istft
% $Header: /homes/dpwe/public_html/resources/matlab/RCS/pvoc.m,v 1.2 2002/02/13 16:14:54 dpwe Exp $
if nargin < 3
n = 1024;
end
% With hann windowing on both input and output,
% we need 25% window overlap for smooth reconstruction
hop = n/4;
% Effect of hanns at both ends is a cumulated cos^2 window (for
% r = 1 anyway); need to scale magnitudes by 2/3 for
% identity input/output
scf = 2/3;
% Calculate the basic STFT, magnitude scaled
X = scf * stft(x', n, n, hop);
% Calculate the new timebase samples
[rows, cols] = size(X);
t = 0:r:(cols-2);
% Have to stay two cols off end because (a) counting from zero, and
% (b) need col n AND col n+1 to interpolate
% Generate the new spectrogram
X2 = pvsample(X, t, hop);
% Invert to a waveform
y = istft(X2, n, n, hop)';
///////////stft.m/////////////
function d = stft(x, f, w, h)
% D = stft(X, F, W, H) Short-time Fourier transform.
% Returns some frames of short-term Fourier transform of x. Each
% column of the result is one F-point fft; each successive frame is
% offset by H points until X is exhausted. Data is hamm-windowed
% at W pts..
% See also 'istft.m'.
% dpwe 1994may05. Uses built-in 'fft'
% $Header: /homes/dpwe/public_html/resources/matlab/RCS/stft.m,v 1.1 2002/02/13 16:15:55 dpwe Exp $
s = length(x);
if rem(w, 2) == 0
% force window to be odd-len
w = w + 1;
end
halflen = (w-1)/2;
halff = f/2; % midpoint of win
acthalflen = min(halff, halflen);
halfwin = 0.5 * ( 1 + cos( pi * (0:halflen)/halflen));
win = zeros(1, f);
win((halff+1):(halff+acthalflen)) = halfwin(1:acthalflen);
win((halff+1):-1:(halff-acthalflen+2)) = halfwin(1:acthalflen);
c = 1;
% pre-allocate output array
d = zeros((1+f/2),1+fix((s-f)/h));
for b = 0:h:(s-f)
u = win.*x((b+1):(b+f));
t = fft(u);
d(:,c) = t(1:(1+f/2))';
c = c+1;
end;
///////////pvsample.m/////////////
function c = pvsample(b, t, hop)
% c = pvsample(b, t, hop) Interpolate an STFT array according to the 'phase vocoder'
% b is an STFT array, of the form generated by 'specgram'.
% t is a vector of (real) time-samples, which specifies a path through
% the time-base defined by the columns of b. For each value of t,
% the spectral magnitudes in the columns of b are interpolated, and
% the phase difference between the successive columns of b is
% calculated; a new column is created in the output array c that
% preserves this per-step phase advance in each bin.
% hop is the STFT hop size, defaults to N/2, where N is the FFT size
% and b has N/2+1 rows. hop is needed to calculate the 'null' phase
% advance expected in each bin.
% Note: t is defined relative to a zero origin, so 0.1 is 90% of
% the first column of b, plus 10% of the second.
% 2000-12-05 [email protected]
% $Header: /homes/dpwe/public_html/resources/matlab/dtw/../RCS/pvsample.m,v 1.3 2003/04/09 03:17:10 dpwe Exp $
if nargin < 3
hop = 0;
end
[rows,cols] = size(b);
N = 2*(rows-1);
if hop == 0
% default value
hop = N/2;
end
% Empty output array
c = zeros(rows, length(t));
% Expected phase advance in each bin
dphi = zeros(1,N/2+1);
dphi(2:(1 + N/2)) = (2*pi*hop)./(N./(1:(N/2)));
% Phase accumulator
% Preset to phase of first frame for perfect reconstruction
% in case of 1:1 time scaling
ph = angle(b(:,1));
% Append a 'safety' column on to the end of b to avoid problems
% taking *exactly* the last frame (i.e. 1*b(:,cols)+0*b(:,cols+1))
b = [b,zeros(rows,1)];
ocol = 1;
for tt = t
% Grab the two columns of b
bcols = b(:,floor(tt)+[1 2]);
tf = tt - floor(tt);
bmag = (1-tf)*abs(bcols(:,1)) + tf*(abs(bcols(:,2)));
% calculate phase advance
dp = angle(bcols(:,2)) - angle(bcols(:,1)) - dphi';
% Reduce to -pi:pi range
dp = dp - 2 * pi * round(dp/(2*pi));
% Save the column
c(:,ocol) = bmag .* exp(j*ph);
% Cumulate phase, ready for next frame
ph = ph + dphi' + dp;
ocol = ocol+1;
end
///////////istft.m/////////////
function x = istft(d, ftsize, w, h)
% X = istft(D, F, W, H) Inverse short-time Fourier transform.
% Performs overlap-add resynthesis from the short-time Fourier transform
% data in D. Each column of D is taken as the result of an F-point
% fft; each successive frame was offset by H points. Data is
% hamm-windowed at W pts..
% dpwe 1994may24. Uses built-in 'ifft' etc.
% $Header: /homes/dpwe/public_html/resources/matlab/RCS/istft.m,v 1.1 2002/02/13 16:16:12 dpwe Exp $
s = size(d);
%if s(1) != (ftsize/2)+1
% error('number of rows should be fftsize/2+1')
%end
cols = s(2);
xlen = ftsize + cols * (h);
x = zeros(1,xlen);
if rem(w, 2) == 0
% force window to be odd-len
w = w + 1;
end
win = zeros(1, ftsize);
halff = ftsize/2; % midpoint of win
halflen = (w-1)/2;
acthalflen = min(halff, halflen);
halfwin = 0.5 * ( 1 + cos( pi * (0:halflen)/halflen));
win((halff+1):(halff+acthalflen)) = halfwin(1:acthalflen);
win((halff+1):-1:(halff-acthalflen+2)) = halfwin(1:acthalflen);
for b = 0:h:(h*(cols-1))
ft = d(:,1+b/h)';
ft = [ft, conj(ft([((ftsize/2)):-1:2]))];
px = real(ifft(ft));
x((b+1):(b+ftsize)) = x((b+1):(b+ftsize))+px.*win;
end;
这是用法
[d,sr]=wavread('sf1_cln.wav');
% 1024 samples is about 60 ms at 16kHz, a good window
y=pvoc(d,.75,1024);下面是文件
///////////pvoc.m/////////////
function y = pvoc(x, r, n)
% y = pvoc(x, r, n) Time-scale a signal to r times faster with phase vocoder
% x is an input sound. n is the FFT size, defaults to 1024.
% Calculate the 25%-overlapped STFT, squeeze it by a factor of r,
% inverse spegram.
% 2000-12-05, 2002-02-13 [email protected]. Uses pvsample, stft, istft
% $Header: /homes/dpwe/public_html/resources/matlab/RCS/pvoc.m,v 1.2 2002/02/13 16:14:54 dpwe Exp $
if nargin < 3
n = 1024;
end
% With hann windowing on both input and output,
% we need 25% window overlap for smooth reconstruction
hop = n/4;
% Effect of hanns at both ends is a cumulated cos^2 window (for
% r = 1 anyway); need to scale magnitudes by 2/3 for
% identity input/output
scf = 2/3;
% Calculate the basic STFT, magnitude scaled
X = scf * stft(x', n, n, hop);
% Calculate the new timebase samples
[rows, cols] = size(X);
t = 0:r:(cols-2);
% Have to stay two cols off end because (a) counting from zero, and
% (b) need col n AND col n+1 to interpolate
% Generate the new spectrogram
X2 = pvsample(X, t, hop);
% Invert to a waveform
y = istft(X2, n, n, hop)';
///////////stft.m/////////////
function d = stft(x, f, w, h)
% D = stft(X, F, W, H) Short-time Fourier transform.
% Returns some frames of short-term Fourier transform of x. Each
% column of the result is one F-point fft; each successive frame is
% offset by H points until X is exhausted. Data is hamm-windowed
% at W pts..
% See also 'istft.m'.
% dpwe 1994may05. Uses built-in 'fft'
% $Header: /homes/dpwe/public_html/resources/matlab/RCS/stft.m,v 1.1 2002/02/13 16:15:55 dpwe Exp $
s = length(x);
if rem(w, 2) == 0
% force window to be odd-len
w = w + 1;
end
halflen = (w-1)/2;
halff = f/2; % midpoint of win
acthalflen = min(halff, halflen);
halfwin = 0.5 * ( 1 + cos( pi * (0:halflen)/halflen));
win = zeros(1, f);
win((halff+1):(halff+acthalflen)) = halfwin(1:acthalflen);
win((halff+1):-1:(halff-acthalflen+2)) = halfwin(1:acthalflen);
c = 1;
% pre-allocate output array
d = zeros((1+f/2),1+fix((s-f)/h));
for b = 0:h:(s-f)
u = win.*x((b+1):(b+f));
t = fft(u);
d(:,c) = t(1:(1+f/2))';
c = c+1;
end;
///////////pvsample.m/////////////
function c = pvsample(b, t, hop)
% c = pvsample(b, t, hop) Interpolate an STFT array according to the 'phase vocoder'
% b is an STFT array, of the form generated by 'specgram'.
% t is a vector of (real) time-samples, which specifies a path through
% the time-base defined by the columns of b. For each value of t,
% the spectral magnitudes in the columns of b are interpolated, and
% the phase difference between the successive columns of b is
% calculated; a new column is created in the output array c that
% preserves this per-step phase advance in each bin.
% hop is the STFT hop size, defaults to N/2, where N is the FFT size
% and b has N/2+1 rows. hop is needed to calculate the 'null' phase
% advance expected in each bin.
% Note: t is defined relative to a zero origin, so 0.1 is 90% of
% the first column of b, plus 10% of the second.
% 2000-12-05 [email protected]
% $Header: /homes/dpwe/public_html/resources/matlab/dtw/../RCS/pvsample.m,v 1.3 2003/04/09 03:17:10 dpwe Exp $
if nargin < 3
hop = 0;
end
[rows,cols] = size(b);
N = 2*(rows-1);
if hop == 0
% default value
hop = N/2;
end
% Empty output array
c = zeros(rows, length(t));
% Expected phase advance in each bin
dphi = zeros(1,N/2+1);
dphi(2:(1 + N/2)) = (2*pi*hop)./(N./(1:(N/2)));
% Phase accumulator
% Preset to phase of first frame for perfect reconstruction
% in case of 1:1 time scaling
ph = angle(b(:,1));
% Append a 'safety' column on to the end of b to avoid problems
% taking *exactly* the last frame (i.e. 1*b(:,cols)+0*b(:,cols+1))
b = [b,zeros(rows,1)];
ocol = 1;
for tt = t
% Grab the two columns of b
bcols = b(:,floor(tt)+[1 2]);
tf = tt - floor(tt);
bmag = (1-tf)*abs(bcols(:,1)) + tf*(abs(bcols(:,2)));
% calculate phase advance
dp = angle(bcols(:,2)) - angle(bcols(:,1)) - dphi';
% Reduce to -pi:pi range
dp = dp - 2 * pi * round(dp/(2*pi));
% Save the column
c(:,ocol) = bmag .* exp(j*ph);
% Cumulate phase, ready for next frame
ph = ph + dphi' + dp;
ocol = ocol+1;
end
///////////istft.m/////////////
function x = istft(d, ftsize, w, h)
% X = istft(D, F, W, H) Inverse short-time Fourier transform.
% Performs overlap-add resynthesis from the short-time Fourier transform
% data in D. Each column of D is taken as the result of an F-point
% fft; each successive frame was offset by H points. Data is
% hamm-windowed at W pts..
% dpwe 1994may24. Uses built-in 'ifft' etc.
% $Header: /homes/dpwe/public_html/resources/matlab/RCS/istft.m,v 1.1 2002/02/13 16:16:12 dpwe Exp $
s = size(d);
%if s(1) != (ftsize/2)+1
% error('number of rows should be fftsize/2+1')
%end
cols = s(2);
xlen = ftsize + cols * (h);
x = zeros(1,xlen);
if rem(w, 2) == 0
% force window to be odd-len
w = w + 1;
end
win = zeros(1, ftsize);
halff = ftsize/2; % midpoint of win
halflen = (w-1)/2;
acthalflen = min(halff, halflen);
halfwin = 0.5 * ( 1 + cos( pi * (0:halflen)/halflen));
win((halff+1):(halff+acthalflen)) = halfwin(1:acthalflen);
win((halff+1):-1:(halff-acthalflen+2)) = halfwin(1:acthalflen);
for b = 0:h:(h*(cols-1))
ft = d(:,1+b/h)';
ft = [ft, conj(ft([((ftsize/2)):-1:2]))];
px = real(ifft(ft));
x((b+1):(b+ftsize)) = x((b+1):(b+ftsize))+px.*win;
end;
解决方案 »
- 远程注入代码,进程崩溃
- 如何在带滚动条视图窗口中获得整个窗口DC
- SQL Sever 2000 版本问题
- mfc程序,误操作删除toolbar
- 急!!!请问ISAPI Extension与ISAPI Filter之间有什么关系.
- atl里怎么用SysAllocString这些函数?
- 如何在LAN内玩星际,传奇等网络游戏????????
- 在VC程序中如何设置屏幕分辨率?
- 请问哪里有MSDN Library January 2003 下载?
- 我辛苦下载的pdf文件打不开,y?
- VC里的List Control 内如何将添加的条目的某一个单元的文字,用指定颜色来表示?
- exe和dll调用的readfile有什么不同吗
http://www.vckbase.com/document/viewdoc/?id=1435
不过我主要是想知道这几个文件中的处理过程是怎么样的,所以要想办法把它看懂:)
http://www.buaapress.com.cn/buaa/html/book/view.asp?id=1276&cat_f=&cat_s=23&catf_id=12