Created
December 4, 2016 14:55
-
-
Save wmuron/67a9c224113fc27f1219eddf3ccb9d50 to your computer and use it in GitHub Desktop.
sda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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