forked from dario-pilori/dsp-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay_compensation.m
34 lines (30 loc) · 1.1 KB
/
delay_compensation.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
34
function y = delay_compensation(x,Parameters)
%DELAY_COMPENSATION Compensate for the skew between channels
% Ths function removes the skew between the input signals using a cubic
% interpolation
%
% It requires interp1, introduced before MATLAB R2006a
%
% INPUTS:
% x := Array of signals (column vectors) to process
% Parameters := Parameter structure (see GET_DEFAULT_PARAMS)
%
% OUTPUTS
% y := Array of processed signals (column vectors)
% Mar. 2016 - Dario Pilori <dario.pilori@polito.it>
%% Retrieve parameters from stucture
dt = Parameters.skew;
fs = Parameters.fADC;
%% Check input parameters
validateattributes(x,{'double'},{'2d'},'','x',1);
validateattributes(dt,{'numeric'},{'size',[size(x,2),1],'nonnan'},'Parameters','skew',2);
validateattributes(fs,{'numeric'},{'scalar','positive'},'Parameters','fADC',2);
%% Compensate for skew
y = NaN(size(x));
for ii = 1:size(x,2)
if dt(ii)==0
y(:,ii) = x(:,ii);
else
y(:,ii) = interp1((0:size(x,1)-1).'/fs, x(:,ii), (0:size(x,1)-1).'/fs+dt(ii), 'pchip');
end
end