ita_ctc_channelSeparation.m 3.24 KB
Newer Older
1
function [ CS_L CS_R CS_L_singleSpectrum CS_R_singleSpectrum ] = ita_ctc_channelSeparation(HRTF_real, CTCFilter, varargin)
2
3
4
%ITA_CTC_CHANNELSEPARATION Returns and plots channelseparation for ctc
%systems
%   HRTF_real represent the real HRTFs that will occure in the CTC system,
5
%   either as multi-instance itaAudio or coded in channels
6
7
8
9
10
%   HRTF.ch(1) = HRTF_LS1_Left;
%   HRTF.ch(2) = HRTF_LS1_Right;
%   HRTF.ch(3) = HRTF_LS2_Left;
%   HRTF.ch(4) = HRTF_LS2_Right;
%   HRTF.ch(5) = HRTF_LS3_Left;
11
12
13
14
15
16
17
%
%   CTC has to be multi-instance itaAudio:
%   [LS1_left_CTCFilter LS1_right_CTCFilter]
%   [LS2_left_CTCFilter LS2_right_CTCFilter]
%   [LS3_left_CTCFilter LS3_right_CTCFilter]
%   ...
%
18
19
% TODO: Frequency ranges

20
opts.naturalCS      = false;
21
22
23
opts.doubleSpectrum = true;
opts.singleSpectrum = true;
opts.plot           = true;
24

25
opts=ita_parse_arguments(opts, varargin);
26

27
hrtf=ita_merge(HRTF_real(:));
28
hrtf.signalType='energy';
29
L=itaAudio;
30
L.signalType='energy';
31
32
33
34
helper=ita_convolve(hrtf.ch(1),CTCFilter(1));
numSamples=helper.nSamples;

%% Left channel input
35
L.time=zeros(numSamples,1);
36
37
38
39
40
41
42
43
R=L;
for k=1:size(CTCFilter,1)
    L=L+ita_convolve(hrtf.ch(2*k-1),CTCFilter(k,1));
    R=R+ita_convolve(hrtf.ch(2*k),CTCFilter(k,1));
end
CS_L = ita_merge(L,R);

%% Right channel input
44
L.time=zeros(numSamples,1);
45
46
47
48
R=L;
for k=1:size(CTCFilter,1)
    L=L+ita_convolve(hrtf.ch(2*k-1),CTCFilter(k,2));
    R=R+ita_convolve(hrtf.ch(2*k),CTCFilter(k,2));
49
end
50
CS_R = ita_merge(L,R);
51

52
%% Bruno Diss p 83 (5-11)
53
54
55
56
if opts.singleSpectrum
    CS_L_singleSpectrum = ita_divide_spk(CS_L.ch(1),CS_L.ch(2));
    CS_R_singleSpectrum = ita_divide_spk(CS_R.ch(2),CS_R.ch(1));
end
57
58
59

%% Natural channel separation
if opts.naturalCS
60
    [ natCS_L natCS_R ] =ita_ctc_channelSeparation_naturalOptimum(hrtf);
61
62
end

63
64
%% Plot
if opts.plot
65
    if opts.doubleSpectrum
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
        CS_L.pf; legend({'Left in, left ear' 'Left in, right ear'});
        title('Channel separation - left ear');
        set(gcf,'name','Channel separation - left ear');
        CS_R.pf; legend({'Right in, left ear' 'Right in, right ear'});
        title('Channel separation - right ear');
        set(gcf,'name','Channel separation - right ear');
    end
    if opts.singleSpectrum && opts.naturalCS
        merged_CS_L=ita_merge(natCS_L,CS_L_singleSpectrum);
        merged_CS_R=ita_merge(natCS_R,CS_R_singleSpectrum);
        merged_CS_L.pf; legend({'Optimal natural CS for left in' 'CTC CS for left in' });
        title('Channel separation - left ear (natural vs CTC)');
        set(gcf,'name','Channel separation - left ear');
        merged_CS_R.pf; legend({'Optimal natural CS for right in' 'CTC CS for right in' });
        title('Channel separation - right ear (natural vs CTC)');
        set(gcf,'name','Channel separation - right ear');
    elseif opts.singleSpectrum
        merged_CS = ita_merge(CS_L_singleSpectrum, CS_R_singleSpectrum);
        merged_CS.pf;
        legend({'CS for left in' 'CS for right in' });
        title('Channel separation');
        set(gcf,'name','Channel separation');
    elseif opts.naturalCS
        merged_CS = ita_merge(natCS_L, natCS_R);
        merged_CS.pf;
        legend({'Optimal natural CS for left in' 'Optimal natural CS for right in'});
        title('Channel separation');
        set(gcf,'name','Channel separation');
94
    end
95
end