Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code 1:
- function E = FitnessE(d,x,W)
- % N = 51; % desired filter length
- % frequency grid, desired frequency response, weighting function
- %f = [linspace(-1,-.18,164),linspace(-.1,.3,80),linspace(.38,1,124)];
- %d = [zeros(1,164),ones(1,80),zeros(1,124)].*exp(-1i*pi*f*(N-1)/2);
- %w = [2*ones(1,164),ones(1,80),2*ones(1,124)];
- %f = f(:); d = d(:); w = w(:);
- % set up and solve overdetermined linear system
- %A = w(:,ones(1,N)) .* exp(-1i*pi*f*(0:N-1));
- x=w(:,ones(1,N)');
- W=exp(-1i*pi*f*(0:N-1));
- n=size(W,1);
- % y = A (w.*d);
- E=sum((d-x.*W).^2)+sum((x.*W).^2) % as a objective function
- end;
- Code 2:
- f=@(x)FitnessE(x,W,d);
- [x,,exitflag,output,population,scores]=ga(f,n,[],[],[],[],[],[],...
- [],options);
- x=ga(f,n);% x will be the optimized coefficients ,n will be the
- % value obtained by the optimized coefficients
- options=gaoptimiset(@ga);
- options.PopulationType='doubleVector';
- opttions.SelectionFcn=@slectionRoulette;
- options.Crossoverfcn=@mutation uniform;
- options.PopulationSize=100;
Add Comment
Please, Sign In to add comment