-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMRT_demo.m
171 lines (130 loc) · 4.36 KB
/
MRT_demo.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
% Demonstration script for the classe MRT
% This script can serve as a rough unitary test
%
% Copyright (c) 2012, Thomas Fillon,
% Institut Mines Telecom, Telecom-ParisTech, CNRS-LTCI
% All rights reserved.
%
%-------------------------------------------------------------------------
%
% This file is part of the MRT Toolbox.
%
% The MRT Toolbox is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% The MRT Toolbox is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with the MRT Toolbox. If not, see <http://www.gnu.org/licenses/>.
%
%-------------------------------------------------------------------------
% See also : MRT.m, MRT_demo_CQT.m, MRT_demo_MIDI, MRT_demo_ERB.m
clear
close all
% Load Sound file
[x,Fs] = wavread('audio/E-Core - Pingouin-Banquise_45s.wav');
x=sum(x,2); % Conversion from stereo to mono
x=x(1:20*Fs); % Select the first 10 seconds
%% MRT object creation
% Default MRT object creation
mrt_obj = MRT();
display(mrt_obj);
% MRT object creation with Fs
mrt_obj = MRT(Fs);
display(mrt_obj);
% MRT object creation with Fs and the frequency unit
mrt_obj = MRT(Fs, 'Hz');
display(mrt_obj);
mrt_obj = MRT(Fs, 'MIDI');
display(mrt_obj);
mrt_obj = MRT(Fs, 'ERB');
display(mrt_obj);
% Change Fs
mrt_obj.Fs = 32000; display(mrt_obj);
mrt_obj.Fs = Fs; display(mrt_obj);
% Change the frequency unit
mrt_obj.freqUnit = 'Hz'; display(mrt_obj);
%% Frequencies specification
% Set the frequency for each bin
freq = 0:1000:5000;
mrt_obj.freqHz = freq;
display(mrt_obj);
mrt_obj.frequencies = freq;
display(mrt_obj);
mrt_obj.freqUnit = 'ERB';
mrt_obj.frequencies = 0:1:10;
display(mrt_obj);
%% Frequency resolution specification
mrt_obj.deltafreqHz = 100; % Constant Resolution in Hz
display(mrt_obj);
mrt_obj.delta_frequencies = 1; % Constant Resolution in ERB
display(mrt_obj);
mrt_obj.delta_frequencies = 1:1:11; % Specify Resolution for each bin in ERB
display(mrt_obj);
mrt_obj.N = 500; % Constant kernel length for all bin
display(mrt_obj);
mrt_obj.N = [ones(1,6)*400 ones(1,5)*600]; % Specify every N value
display(mrt_obj);
mrt_obj.N(1:3) = 250; % Specify only few N values
display(mrt_obj);
% Resolution Criteria
mrt_obj.resolutionCriteria = '3dB'; % Frequency resolution = -3dB bandwidth
mrt_obj.delta_frequencies = 1; display(mrt_obj);
mrt_obj.resolutionCriteria = 'ML'; % Frequency resolution = Main lobe width
mrt_obj.delta_frequencies = 1; display(mrt_obj);
mrt_obj.resolutionCriteria = 'EN'; % Frequency resolution = Equivalent Noise bandwidth
mrt_obj.delta_frequencies = 1; display(mrt_obj);
% Specify the Q-factor
mrt_obj.freqHz(1) = 1;
mrt_obj.Q = 1;
display(mrt_obj);
% Try to specify Q with a null frequency
mrt_obj.freqHz(1) = 0;
try
mrt_obj.Q = 1;
catch exception
if strcmp(exception.identifier,'MRT:Q:zero_frequency')
display(exception.message);
else
throw(exception);
end
end
display(mrt_obj);
%% Kernel Parameter
clear mrt_obj;
mrt_obj = MRT(Fs, 'ERB');
mrt_obj.frequencies = 0:1:10;
mrt_obj.delta_frequencies = 1;
mrt_obj.display_kernels;
mrt_obj.display_kernels('MATRIX'); % Default
mrt_obj.display_kernels('TF'); % XY ticks in time-frequency units
% Specify Time alignement of the kernels
mrt_obj.windowAlignment = 'right';
mrt_obj.display_kernels;
mrt_obj.windowAlignment = 'left';
mrt_obj.display_kernels;
mrt_obj.windowAlignment = 'center';
mrt_obj.display_kernels;
% Specify the window function (cf. matlab 'window' function)
mrt_obj.windowFunction = @blackman;
mrt_obj.display_kernels;
mrt_obj.resolutionCriteria = '3dB'; % Frequency resolution = -3dB bandwidth
mrt_obj.windowFunction = @gausswin;
mrt_obj.windowOption = 2.5; % Specify window option ('winopt')
mrt_obj.display_kernels;
%% Transform
close all;
clear mrt_obj;
mrt_obj = MRT(Fs, 'ERB');
mrt_obj.frequencies = 0:1:30;
mrt_obj.delta_frequencies = 1;
% mrt_obj.R = 256;
mrt_obj.R = floor(mrt_obj.Nmin/2); % Specify the Step-Size
y = mrt_obj.transform(x);
% Display
mrt_obj.display_MRT(y);