LM Algoritması ile FIR Filtre Parametre Kestirimi

Aşağıda FIR filtre parametre kestirim işlemlerini gerçekleştiren Matlab kodları verilmiştir.

  1.  
  2. g_SAMPLE = 1000;
  3. g_ITERATION = 2;
  4. g_PARAMETER = 20;
  5.  
  6. f_1 = 10;
  7. f_2 = 500;
  8. f_3 = 1000;
  9. f_s = 5000;
  10. n_s = 1 : g_SAMPLE;
  11. INPUT = cos(2 * pi * n_s * f_1 / f_s) + cos(2 * pi * n_s * f_2 / f_s) + ...
  12.         cos(2 * pi * n_s * f_3 / f_s);
  13. [n_a n_b] = fir1(g_PARAMETER - 1, 200 / f_s, 'low');
  14. DESIRED_OUTPUT = filter_conv(INPUT, n_a)
  15. figure, plot(DESIRED_OUTPUT);
  16.  
  17. lamda = 0.01;
  18.  
  19. p_a = rand(1, g_PARAMETER);
  20.  
  21. for n_i = 1 : g_ITERATION
  22.     E(n_i) = 0;
  23.    
  24.     for n_j = 1 : g_SAMPLE - g_PARAMETER + 1;
  25.         OUTPUT_TRAIN(n_j) = filter_conv(INPUT(n_j : n_j + g_PARAMETER - 1), p_a);
  26.         ERROR(n_j) = DESIRED_OUTPUT(n_j) - OUTPUT_TRAIN(n_j);
  27.         E(n_i) = E(n_i) + 0.5 * ERROR(n_j) ^ 2;
  28.         JACOBIAN(n_j, : ) = INPUT(n_j : n_j + g_PARAMETER - 1);
  29.     end
  30.  
  31.     kontrol = 1;
  32.  
  33.     while(kontrol == 1)
  34.        
  35.          J_new = inv(JACOBIAN' * JACOBIAN + lamda * eye(g_PARAMETER,g_PARAMETER)) * JACOBIAN' * ERROR';
  36.          p_a_new = p_a + J_new';
  37.  
  38.          E_NEW(n_i) = 0;
  39.  
  40.          for n_j = 1 : g_SAMPLE - g_PARAMETER + 1;
  41.             OUTPUT_TRAIN(n_j) = filter_conv(INPUT(n_j : n_j + g_PARAMETER - 1), p_a_new);
  42.             ERROR_NEW(n_j) = DESIRED_OUTPUT(n_j) - OUTPUT_TRAIN(n_j);
  43.             E_NEW(n_i) = E_NEW(n_i) + 0.5 * ERROR_NEW(n_j) ^ 2;
  44.            
  45.         end
  46.        
  47.        if E_NEW(n_i) < E(n_i)
  48.           p_a = p_a_new;
  49.           lamda = lamda * .5;
  50.            kontrol = 0;
  51.        else
  52.             lamda = lamda / .5;
  53.        end;
  54.      end  
  55. end;
  56.  
  57. TEST_OUTPUT = filter_conv(INPUT, p_a)
  58. figure, plot(TEST_OUTPUT);
  1. function FILTER_OUT = filter_conv(INPUT, n_a)
  2.  
  3. for n_i = 1 : length(INPUT) - length(n_a) + 1
  4.     FILTER_OUT(n_i) = sum(INPUT(n_i : n_i + length(n_a) - 1).* n_a);
  5.    
  6. end