Matlab simulation of speech signal pitch estimation algorithm based on extended Kalman filter EKF

Table of contents

1. Algorithm simulation effect

2. Algorithms involve an overview of theoretical knowledge

3. MATLAB core program

4. Complete algorithm code file


1. Algorithm simulation effect

The matlab2022a simulation results are as follows:

 

2. Algorithms involve an overview of theoretical knowledge

      The pitch is the basic frequency component of the speech signal, which determines the pitch of the speech and the pitch of the sound. In speech signal processing, pitch estimation is an important task, which can be used in speech synthesis, speech recognition, speech enhancement and other applications. Extended Kalman Filter (Extended Kalman Filter, EKF) is a filtering method for nonlinear systems, which can be used for pitch estimation.

       In speech signals, the periodic vibration component is called pitch. The pitch period refers to the time interval between two adjacent periodic waveforms, also known as the pitch period. Frequency refers to the number of cycles of vibration per second, and its reciprocal is called the cycle. For a pitch with period T, its frequency f = 1/T. The frequency range of the pitch is usually between 50Hz-500Hz.
      Kalman Filter (Kalman Filter, KF) is a filtering method for linear systems, which can infer the state of the system based on the known system model and initial state in noisy observation data. Extended Kalman filtering is a filtering method for nonlinear systems that approximates the nonlinear system by using local linearization at each time step and uses Kalman filtering for state estimation.

      Extended Kalman filtering requires a system model that describes the evolution of the pitch. In pitch estimation, the system model can be expressed as:
x(k) = A(k-1)x(k-1) + w(k-1)
where x(k) represents the state vector at time k, A(k-1) represents the state transition matrix, and w(k-1) represents the system noise. In pitch estimation, the state vector can be expressed as:
x(k) = [p(k), T(k)]
where p(k) represents the pitch period and T(k) represents the phase of the pitch. The state transition matrix A(k-1) can be expressed as:
A(k-1) = [1 0; 0 1]
This matrix indicates that the pitch period and phase remain unchanged in each time step. System noise w(k-1) can be expressed as:
w(k-1) = [w1(k-1), w2(k-1)]
where w1(k-1) and w2(k-1) are respectively Noise representing pitch period and phase.

         Extended Kalman filtering also requires an observation model, which describes the relationship between observation data and state vectors. In pitch estimation, the observation model can be expressed as:
y(k) = H(k)x(k) + v(k)
where y(k) represents the observation vector at time k, and H(k) represents the observation matrix, v(k) represents the observation noise. In pitch estimation, the observation vector can be expressed as:
y(k) = [y1(k), y2(k)]
where y1(k) and y2(k) represent the observed values ​​of pitch period and phase, respectively. The observation matrix H(k) can be expressed as:
H(k) = [1 0; 0 1]
This matrix means that we can directly observe the pitch period and phase. The observation noise v(k) can be expressed as:
v(k) = [v1(k), v2(k)]
where v1(k) and v2(k) represent pitch period and phase noise, respectively.

The extended Kalman filter algorithm can be divided into two steps: prediction and update. In the prediction step, we use the system model to predict the state vector and covariance matrix for the next time step. In the update step, we use the observed model to update the predicted values ​​based on the observed data. The following are the detailed steps of the extended Kalman filter algorithm:

Initialize the state vector and covariance matrix:
x(0) = [p(0), T(0)]
P(0) = diag([p_var(0), T_var( 0)])

For each time step k:
a. Prediction step:
       According to the system model, predict the state vector of the next time step:
x(k|k-1) = A(k-1)x(k-1| k-1)
       According to the system model, predict the covariance matrix of the next time step:
P(k|k-1) = A(k-1)P(k-1|k-1)A(k-1)^ T + Q(k-1)
b. Update step:
      Calculate the Kalman gain K(k):
K(k) = P(k|k-1)H(k)^T(H(k)P(k| k-1)H(k)^T + R(k))^(-1)
     According to the observed data, calculate the state vector of the current time step:
x(k|k) = x(k|k-1) + K (k)(y(k) - H(k)x(k|k-1))
     Calculate the covariance matrix of the current time step based on the observed data:
P(k|k) = (I - K(k)H (k))P(k|k-1)
       Among them, Q(k-1) represents the covariance matrix of the system noise, and R(k) represents the covariance matrix of the observation noise. For pitch estimation, we can set Q(k-1) and R(k) as constants as follows: Q(k-1)
= diag([q1, q2])
R(k) = diag([r1 , r2])
where q1 and q2 represent the noise variance of the pitch period and phase, respectively, and r1 and r2 represent the observed noise variance of the pitch period and phase, respectively.

3. MATLAB core program

..............................................................
%pitch tracking
for ii=2:size(datass,2)
    %基于先前估计的均值一步预测 
    One_step_state=F*(state(:,ii-1));
    P_OneStep(:,:,ii)=F*P(:,:,ii-1)*F'+C*Q*C';
    H=cos((B*One_step_state)'+pha')*G-(G*One_step_state)'*diag(sin(B*One_step_state+pha))*(B);
    O_covariance=(H*P_OneStep(:,:,ii)*H'+R);
    % Kalman gain
    K=P_OneStep(:,:,ii)*H'*O_covariance^(-1); 
    % 计算一步预测残差
    h=(G*One_step_state)'*cos(B*One_step_state+pha);
    correction_factor=K*(datass(:,ii)-h);
 
    state(:,ii)= One_step_state+correction_factor;
    P(:,:,ii)  = P_OneStep(:,:,ii)-K*H*P_OneStep(:,:,ii);  
end


%卡尔曼平滑器;
N=size(datass,2);

pitch(:,N)     = state(:,N);
P_upS(:,:,N)   = P(:,:,N);
for k = (N-1):-1:1
    %计算除最后一个步骤外的所有步骤的预测步骤
    sgain = (P(:,:,k)*F')/(F*P(:,:,k)*F' + C*Q*C');
    pitch(:,k)     = state(:,k)  + sgain*(pitch(:,k+1)  - F*(state(:,k)));
    P_upS(:,:,k)   = P(:,:,k)+ sgain*(P_upS(:,:,k+1) - P_OneStep(:,:,k+1))*sgain';
end

end
A866

4. Complete algorithm code file

V

Guess you like

Origin blog.csdn.net/hlayumi1234567/article/details/130548552