MATLAB中的音频频谱,音高偏移和通用音频处理

时间:2018-09-12 19:58:36

标签: matlab audio dft spectrum centroid

我正在编写一个使用MATLAB基本程序(例如440Hz处的la4或A4)的MATLAB程序,并且在向用户询问了他/她想要的频率之后,该程序将产生移调的声音。例如,如果用户希望原始文件中的880Hz频率为440Hz,则它将使每个频率加倍(包括谐波)。

我尝试使用MIRPitch,此处未实现,但安装了所有工具箱后,该功能仍然无法正常工作。

我如何理解基础知识?我该如何以其他方式换位?

[y,Fs]=audioread("Test.wav");
[x,Fs]=audioread("LookingForHappiness.mp3");
D=0.8;
%D=(1/Fs)*length(x);
% Digital format ----------------------------------------------------------

Fs=44100;       % Sampling rate (Hz)
Ts=1/Fs;        % Sampling Period (s)



% Start DFT -------------------------------------------------------------


W=D;                % Set the window analysis to pattern duration
N=W/Ts;             % Samples in a window frame
F0=1/W;             % Fourier fundamental frequency
K=Fs*W;             % Total computable frequencies

for k=0:K-1         % k is the frequency index (f=K*F0)
    for(n=0:N-1)
        s(n+1)=sin(2*pi*k*F0*n*Ts);  % n is the time index (t=n*Ts)
        c(n+1)=cos(2*pi*k*F0*n*Ts);  % n is the time index (t=n*Ts)
    end
    Xi(k+1)=0;
    Xr(k+1)=0;
    for (n=0:N-1)
        Xi(k+1)=Xi(k+1)+x(n+1)*s(n+1);
        Xr(k+1)=Xr(k+1)+x(n+1)*c(n+1);
    end
    Xi(k+1)=Xi(k+1)/N;        % Scale by 1/N each frequency bin
    Xr(k+1)=Xr(k+1)/N;        % Scale by 1/N each frequency bin
end
Xi(1)=Xi(1)/2;                % Frequency 0 amplitude is scaled by 1/N
Xr(1)=Xr(1)/2;                % Frequency 0 amplitude is scaled by 1/N

% Show results ------------------------------------------------------------

Xa=2*sqrt(Xi.^2+Xr.^2);       % Computes amplitude spectrum

Fscale=0:F0:(Fs/2);
subplot(2,1,1);
plot(Fscale,Xa(1:K/2+1));    % Plot the amplitude spectrum
xlabel ('frequency (Hz) ')
subplot(2,1,2);
plot(x(1:2));              % Plot the signal  %era 1:100
xlabel ('time (s) ')
sound("L4A.mp3");

0 个答案:

没有答案
相关问题