Code of Highpass filter for objective function in pso algorithm.

조회 수: 2 (최근 30일)
Jayasree Das
Jayasree Das 2023년 11월 25일
답변: Pratyush Swain 2025년 3월 21일
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

답변 (1개)

Pratyush Swain
Pratyush Swain 2025년 3월 21일
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

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by