Process.m
function [out] = process(in,key)
%PROCESS takes in a sound vector and a vector containing the %target signal
%and outputs a filtered version of the original signal
a = in;
b = a(:,1);
%take only the first channel
l = length(b);
%length of the input signal
n = floor(l/1024);
%number of fourier transforms
out = zeros(n*1024,1);
%output vector to be filled
for c = 0:n-1
r
= b(1024*c+1:1024*(c+1));
%sampling the signal
d
= fft(r,1024);
%putting the sample into f-domain
e
= stopbands(d,key);
%this is a filtered signal
f
= ifft(e,1024);
%returning the sample to time domain
out(1024*c+1:1024*(c+1))
= f; %reconstituting
the vector of samples
end
out = 5.*out;
%this amplifies the signal
Findvoice.m
function
[index] = findvoice(spec,key)
%FINDVOICE
takes in a spectrum and a frequency pattern and returns the integer
%showing how many indices the pattern was shifted in order to correlate
maximally with
%the input signal
specl
= spec;
%artifact
corr
= xcorr(key,specl);
%finding the correlation between signals
index
= 1;
M
= max(corr);
while
corr(index)~=M
%finding the index of maximal correlation
index
= index+1;
end
ls
= length(spec);
lk = length(key);
if
ls>lk
%finding the actual shift
l = ls;
else
l = lk;
end
index = index-l;
%amount that the pattern was shifted
Stopband.m
function [signal] = stopbands(vec,key)
%STOPBANDS takes in a signal and a pattern and uses a matched filter to
adaptively filter
%the signal with two butterworth stopbands and an elliptical lowpass filter
index = findvoice(vec,key);
%determining filter shift
if abs(index)>50
%sanity check on filter shift
index = 0;
else index = index;
end
fs = 44100;
denom = fs/2;
%normalizes cutoff freq.s
factor = 43;
%Hz per index of spectrogram
W1 = (93+index)*factor/denom;
%lower limit
W2 = (105+index)*factor/denom;
%upper
limit
Wstop = [W1 W2];
%first stopband f-vector
[stop1,stop2] = butter(3,Wstop,'stop','s');
%designing first stopband
W3 = (162+index)*factor/denom;
%lower
limit
Wstop2 = [W3 W4];
%second stopband f-vector
[stop3,stop4] = butter(3,Wstop2,'stop','s');
%designing second stopband
%Wlow = (139+index)*factor/denom; %determining
lowpass cutoff
[low1,low2] = ellip(6,0.5,20,Wlow); %designing
the lowpass
lowered = filter(low1,low2,vec); %lowpass
filter
stopped = filter(stop1,stop2,lowered); %first
stopband filter
stopped = filter(stop3,stop4,stopped); %second
stopband filter
signal = stopped; |