使用octave/matlab代码逐渐/逐渐改变信号的音高

Ric*_*k T 7 matlab signal-processing fft octave pitch-shifting

我可以使用resample调整整个信号,我 在这里尝试了相位声码器代码.

我也试过了repmat和插值,我看了fft和interp1

如何随时间递增/逐渐改变信号的音高? 我已经包含了原始信号的示例以及我正在尝试使处理信号听起来像(我使用Audacity创建处理后的信号并使用它们的效果Sliding time scale / pitch shift)但是想在Octave 4.0中创建此信号.如果您收听已处理信号,您可以听到文件的音高逐渐增加,但文件长度与原始信号文件的长度相同(秒).

我正在使用Octave 4.0,就像Matlab一样

这里的代码可以改变整个信号的音高,并在几秒钟内保持原始信号的相同长度,但我不知道如何逐渐改变信号的音高.谢谢rayryeng让我这么远.

clear, clc
[ya, fs, nbitsraw] = wavread('/tmp/original_signal.wav');

num_per_sec=2.4; %// Define total number of times we see the signal

%// Get total number of integer times we see the signal
num_whole = floor(num_per_sec);

%// Replicate signal
yb=repmat(ya,num_whole,1);

%// Determine how many samples the partial signal consists of
portion = floor((num_per_sec - num_whole)*length(ya));

%// Sample from the original signal and stack this on top of replicated signal
yb = [yb; ya(1:portion)];

%interpolation
xxo=linspace(0,1,length(yb))'; 
xxi=linspace(0,1,length(ya))'; 
yi_t=interp1(xxo,yb,xxi,'linear');

wavwrite([yi_t'] ,fs,16,strcat('/tmp/processed_signal.wav'));  % export file
Run Code Online (Sandbox Code Playgroud)

She*_*ohn 6

我的回答并没有给出与你发布的结果完全相同的结果,但我认为它很有趣也很简单,可以为你提供音高拉伸背后的重要概念.我还没有找到我在网上其他地方提出的方法,但我无法想象以前没有人想过这个,所以它可能有一个名字.

首先要意识到的是,如果你想在一段时间内将变换应用于音高,而不是仅仅在整个时间段上对其进行偏移,你需要使用在每个时间点定义的音高"特征" (例如时间 -频率变换),而不是总结整个信号内容(例如傅立叶)的频率变换.

重要的是要意识到这一点,因为很明显我们需要涉及信号的瞬时频率,这被定义为希尔伯特相位的导数(通常(1/2Pi) * dPhi/ dt用于以Hz而不是rad/s工作).

假设我们可以转换信号的瞬时频率,那么我们可以将" 逐渐增加音调 "的概念正式转换为" 向瞬时频率添加线性增加的偏移 ".好消息是,我们可以使用分析变换轻松地转换信号的瞬时频率.方法如下:

function y = add_linear_pitch( x, fs, df )
%
% y = add_linear_pitch( x, fs, df )
%
% x, fs: audio signal (1-dimensional)
% df: the amplitude of frequency offset, in Hz
%
% See also: hilbert
%

    x = x(:);
    n = numel(x); % number of timepoints
    m = mean(x); % average of the signal
    k = transpose(0:n-1); 

    h = hilbert( x - m ); % analytic signal
    e = abs(h); % envelope
    p = angle(h) + df*pi*k.^2/fs/n; % phase + linearly increasing offset
    y = m - imag(hilbert( e .* sin(p) )); % inverse-transform

end
Run Code Online (Sandbox Code Playgroud)

在前面的代码中唯一不明显的事情是我们需要在将它应用到相位之前对"线性增加的音调偏移"(或瞬时频率的任何变换)进行积分,并将其乘以2Pi(以弧度为单位).在我们的例子中,线性函数的积分只是一个二次函数,但你可以玩更复杂的东西:)