Skip to content

Instantly share code, notes, and snippets.

@wmuron
Created December 4, 2016 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmuron/67a9c224113fc27f1219eddf3ccb9d50 to your computer and use it in GitHub Desktop.
Save wmuron/67a9c224113fc27f1219eddf3ccb9d50 to your computer and use it in GitHub Desktop.
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