-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatchedFilter.m
33 lines (26 loc) · 1.01 KB
/
matchedFilter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
%% Implements the basic Matched Filter algorithm
% by Renato Naville Watanabe
% Inputs:
% - st is a vector with the template of the signal to be found.
% - x is vector with the signal to be analised.
% - Rv is a covariance matrix with of the noise present in the signal x.
% If you have no information about Rv, use an identity matrix.
% - threshold is a real scalar with the tg=hreshold to identify the
% template.
% Outputs:
% - matchedSignal is a vector of the same size of x with the identified
% signals similar to the template st.
% - y is a vector of the same size of x with the projection of st in x
% at each instant
function [matchedSignal, y] = matchedFilter(st, x, Rv, threshold)
y = zeros(size(x));
matchedSignal = zeros(size(x));
h = 2/length(st)*(Rv\st);
begin = 1;
for i = begin:length(x)-length(st)+begin
y(i) = h'*x(i-begin+1:i+length(st)-begin);
end
[pks,locs] = findpeaks(y,'MinPeakHeight',threshold*max(y));
for i = 1:length(locs)
matchedSignal(locs(i):locs(i)+length(st)-1)= st;
end