Guest User

Untitled

a guest
Jan 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Code 1:
  2. function E = FitnessE(d,x,W)
  3. % N = 51; % desired filter length
  4. % frequency grid, desired frequency response, weighting function
  5. %f = [linspace(-1,-.18,164),linspace(-.1,.3,80),linspace(.38,1,124)];
  6. %d = [zeros(1,164),ones(1,80),zeros(1,124)].*exp(-1i*pi*f*(N-1)/2);
  7. %w = [2*ones(1,164),ones(1,80),2*ones(1,124)];
  8. %f = f(:); d = d(:); w = w(:);
  9.  
  10. % set up and solve overdetermined linear system
  11. %A = w(:,ones(1,N)) .* exp(-1i*pi*f*(0:N-1));
  12. x=w(:,ones(1,N)');
  13. W=exp(-1i*pi*f*(0:N-1));
  14. n=size(W,1);
  15. % y = A (w.*d);
  16.  
  17. E=sum((d-x.*W).^2)+sum((x.*W).^2) % as a objective function
  18.  
  19. end;
  20.  
  21. Code 2:
  22.  
  23. f=@(x)FitnessE(x,W,d);
  24. [x,,exitflag,output,population,scores]=ga(f,n,[],[],[],[],[],[],...
  25. [],options);
  26. x=ga(f,n);% x will be the optimized coefficients ,n will be the
  27. % value obtained by the optimized coefficients
  28. options=gaoptimiset(@ga);
  29. options.PopulationType='doubleVector';
  30. opttions.SelectionFcn=@slectionRoulette;
  31. options.Crossoverfcn=@mutation uniform;
  32. options.PopulationSize=100;
Add Comment
Please, Sign In to add comment