Skip to content

Instantly share code, notes, and snippets.

@wmuron wmuron/dasda
Created Dec 4, 2016

Embed
What would you like to do?
sda
function signalFiltered = highPassFilter(signal, fc, fs)
signalFrecDomain = fft(signal);
frecs = 0 : ((fs/2)/length(signalFrecDomain)) : (fs/2);
minLength = min(length(signalFrecDomain), length(frecs));
signalFrecDomain = signalFrecDomain(1 : minLength);
frecs = frecs(1:minLength);
for ind = 1 : length(frecs)
hvals(ind) = getHValue(frecs(ind), fc, fs);
end
filteredFrecDomain = hvals' .* signalFrecDomain;
signalFiltered = ifft(filteredFrecDomain);
end
function hvalue = getHValue(f, fc, fs)
conditionOne = and(f >= 0, f <= fc);
conditionTwo = and(f > fc, f <= (fs/2));
hvalue = 0;
if conditionOne
hvalue = 0.5 - 0.5 * cos (pi * f / fc);
elseif conditionTwo
hvalue = 1;
else
hvalue = 1;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.