Code of Highpass filter for objective function in pso algorithm.
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to design an optimal linear phase high pass filter using pso algorithm but it is giving me the graph for low pass filter.Can anyone please help me with the code for high pass filter to use as objective function.
The code I am currently using is:
function [o] = objFunction(x)
M = 10;
wc = 0.5 * pi;
hr = 0;
for i = 1:(M/2)
hr = hr + 2 * x(i) * cos(wc * ((M/2) - i));
h(i) = 1-(cos(wc * (M/2)) - 1i * sin(wc * (M/2)));
end
hr = hr + x(M/2);
e1 = abs(hr - h);
o = 20 * log10(hr);
end
0 commentaires
Réponses (1)
Pratyush Swain
le 21 Mar 2025
Hi Jayasree,
The issue that you are facing currently is your obejctive function seems to be set up for low-pass filter.
Your current expression for (h):
h(i) = 1-(cos(wc * (M/2)) - 1i * sin(wc * (M/2)));
This above uses a fixed angle, resulting in same values of h(i) which could be why your original filter response was not shaping properly.
To modify it for a high-pass filter, you can adjust the desired response (h) and the way you compute the error (e1). Please refer to following implementation:
function [o] = objFunction(x)
M = 10;
wc = 0.5 * pi;
hr = 0;
h = zeros(1, M/2);
% Calculate the actual filter response hr
for i = 1:(M/2)
hr = hr + 2 * x(i) * cos(wc * ((M/2) - i));
end
hr = hr + x(M/2);
% Desired high-pass filter response
for i = 1:(M/2)
h(i) = -1 * (cos(wc * ((M/2) - i)) - 1i * sin(wc * ((M/2) - i)));
end
% Error between desired and actual response
e1 = abs(hr - h);
o = sum(e1);
end
Please note, for error calculation, you can also use the MSE(Mean Squared Error) as an alternative to absolute error.
Hope this helps
0 commentaires
Voir également
Catégories
En savoir plus sur Particle Swarm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!