-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTX_reverse_finestrcture.m
97 lines (61 loc) · 2.92 KB
/
TX_reverse_finestrcture.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function [reverse_fine,reverse_env,fine_structure] = TX_reverse_finestrcture(x1,binsize, Fco, Fs)
% MULTI_BAND_CHIMERA - Synthesize pair of multi-band "auditory chimeras"
% by dividing each signal into frequency bands, then interchanging
% envelope and fine structure in each band using Hilbert transforms.
%
% Usage: [e1_fs2, e2_fs1] = multi_band_chimera(x1, x2, Fco, Fs, refilter)
% x1, x2 original signals
% Fco band cutoff frequencies (Nbands+1), or filter bank
% Fs sampling rate in Hz (default 1)
% refilter set to 1 to filter again after exchange operation (default 0)
% e1_fs2 chimera with envelope of x1, fine structure of x2 in each band
% e2_fs1 chimera with envelope of x2, fine structure of x1 in each band
%
% Copyright Bertrand Delgutte, 1999-2000
%
if nargin < 3, error('Specify original signals and cutoff frequencies'); end
if nargin < 4, Fs = 1; end
if nargin < 5, refilter = 0; end
if min(size(x1)) == 1, x1 = x1(:); end % make column vectors
nchan = size(x1, 2);
bin = floor( binsize / 1000 * Fs);
% Because the Hilbert transform and the filter bank are both linear operations,
% they commute and associate. We create a bank of complex FIR filters whose
% real and imaginary parts are in quadrature (cos and sin). This complex filter
% is directly applied the original signals. The Hilbert envelope in each band
% is the absolute value of the complex filter output.
% This approach avoids computation of large FFTs as in Matlab's 'hilbert'.
if min(size(Fco)) > 1 | isstr(Fs),
b = Fco; % kluge to specify filters
else b = quad_filt_bank(Fco, Fs);
end
reverse_fine = zeros(size(x1));
reverse_env = zeros(size(x1));
fine_structure = zeros(size(x1));
% loop over filters in bank
for k = 1:size(b,2),
zfilt1 = fftfilt(b(:,k), x1);
temp_fs = cos(angle(zfilt1));
fine_structure = fine_structure + temp_fs;
temp_env = abs(zfilt1);
for i = 1:floor(length(x1) / bin)
start_point = (i - 1) * bin + 1;
end_point = i * bin;
temp_fs(end_point:-1:start_point) = temp_fs(start_point:end_point);
temp_env(end_point:-1:start_point) = temp_env(start_point:end_point);
end
if end_point ~= length(x1)
start_point = i * bin + 1;
if length(x1(start_point:end)) < bin
temp_fs(end:-1:start_point) = temp_fs(start_point:end);
temp_env(end:-1:start_point) = temp_env(start_point:end);
end
end
% interchange envelope and fine structure
temp_reverse_fs_env = abs(zfilt1) .* temp_fs;
temp_fs_reverse_env = temp_env .* cos(angle(zfilt1));
% refilter backward to avoid delay accumulation
% accumulate over frequency bands
reverse_fine = reverse_fine + temp_reverse_fs_env;
reverse_env = reverse_env + temp_fs_reverse_env;
end