簡體   English   中英

使用Matlab實時測量語音信號的基頻

[英]Real-time measuring fundamental frequency of voice signal using matlab

我想在使用Matlab錄音時顯示語音信號的基本頻率。 我在這里發現了在matlab中編程(如何實時處理)如何進行實時部分。

我了解到,用於確定信號基本頻率的一種技術是自相關方法。 還找到了實現它的一段代碼。

現在,我將這段代碼添加到了上面鏈接中找到的代碼中,但是由於我是該領域的新手,所以我不確定我所做的工作是否滿足我的要求-最后的圖是否顯示了每個長度為1秒的信號?

clear all
clc

Fs = 8000;                    %# sampling frequency in Hz
T = 1;                        %# length of one interval signal in sec
t = 0:1/Fs:T-1/Fs;            %# time vector
nfft = 2^nextpow2(Fs);        %# n-point DFT
numUniq = ceil((nfft+1)/2);   %# half point
f = (0:numUniq-1)'*Fs/nfft;   %'# frequency vector (one sided)

%# prepare plots
figure
hAx(1) = subplot(311);
hLine(1) = line('XData',t, 'YData',nan(size(t)), 'Color','b', 'Parent',hAx(1));
xlabel('Time (s)'), ylabel('Amplitude')
hAx(2) = subplot(312);
hLine(2) = line('XData',f, 'YData',nan(size(f)), 'Color','b', 'Parent',hAx(2));
xlabel('Frequency (Hz)'), ylabel('Magnitude (dB)')
set(hAx, 'Box','on', 'XGrid','on', 'YGrid','on')
%#specgram(sig, nfft, Fs);

%# prepare audio recording
recObj = audiorecorder(Fs,8,1);

%# Record for 10 intervals of 1sec each
disp('Start speaking...')
for i=1:10
    recordblocking(recObj, T);

    %# get data and compute FFT
    sig = getaudiodata(recObj);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%
    ms20=Fs/50; % minimum speech Fx at 50Hz 
    r=xcorr(sig,'coeff'); 
    %d=(-ms20:ms20)/Fs; % times of delays 
    subplot(3,1,3); 
    plot(r); 
    legend('Autocorrelation'); 
    xlabel('Delay (s)'); 
    ylabel('Correlation coeff.'); 

    %55555555555555555555555555555555555   
%     R = xcorr (x);
     r = r(160:end);
%     n = 0:159; plot (n, R);

    % some constants
    Lmin = 20; Lmax = 146;
    thr = 0.3; % maximum needs to be at least thr * R[0]
    % detect lag
    [Rmax,ii] = max(r((Lmin+1):(Lmax+1))); % needs to add 1 because of Matlab indexing
    if Rmax >= thr * r(1) % R[0] in Matlab indexing
    L=ii+Lmin-1; % and here needs to remove it again...
    else
    L=0;
    end
    %hold on; plot (L,Rmax,'or'); hold off;

    % show lag in samples
    L
    % in seconds
    T0 = L / 8000
    % and fundamental frequency in Hz
    F0 = 1/T0


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fftMag = 20*log10( abs(fft(sig,nfft)) );

    %# update plots
    set(hLine(1), 'YData',sig)
    set(hLine(2), 'YData',fftMag(1:numUniq))
    title(hAx(1), num2str(i,'Interval = %d'))
    drawnow                   %# force MATLAB to flush any queued displays
end
disp('Done.')

根據http://www.fit.vutbr.cz/~grezl/ZRE/comp_labs/03_pitch_codec_en.pdf ,我在代碼中添加了幾行(介於%5555555之間)。 問題是它輸出相同的基頻。 為什么會發生這種情況,我該如何解決?

謝謝。

它顯示每1秒更新一次的自相關,而不是基本頻率。 代碼執行將等待記錄recordblocking直到記錄完成,然后繪制所有內容,然后再次記錄,因此該循環的總時間將超過10秒。

如果您有一個清晰的音符(僅使用一個頻率),則在自相關中會得到該頻率的一個很好的正弦波。 如果有人在說話,那將是一個非常混亂的情節。 子圖2將為您顯示您的頻率內容,這可能會顯示清晰的基本頻率。

首先輸入干凈的正弦波,嘗試這種方法,以了解如何解釋您的圖。 然后,可以嘗試使用樂器的音符(將包括許多其他頻率),或者嘗試手持音符唱歌(祝您好運),然后考慮這種方法是否適合說話。

坦白地說,某人講話的基本頻率並不容易。 同樣,由於單詞之間的所有停頓,不同單詞中的不同音調等。您可以通過低通濾波器濾除一些高頻信號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM