-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaudio_time_fft.m
62 lines (49 loc) · 1.67 KB
/
audio_time_fft.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
function [ time_sf freq time peak samples_nr] = audio_time_fft( Y , FS , time_range , n , smooth )
% [ time_sf freq time peak samples_nr] = audio_time_fft( Y , FS , time_range , n , smooth )
% Aguments:
% Y: audio track
% time_range: interval of the first alalyzed section.
% n: nr. of analyzed sections
% smooth: smooth ratio of the spectra.
%
% returns:
% time_sf: ( n x sample_nr x channels ) matrix that stores the resulting spectals.
% freq: a vector of size sample_nr that store the fequncies of time_sf
% time: a vector of size n that stores the times for each section.
% peak: absolute maximal amplitude.
% sample_nr: number of saples for easch section
% example:
% audio_time_fft( Y , 44100 , [0 0.1] , 200 ) ;
%
% see also: plot_audio_time_fft
if time_range(2) < time_range(1)
error('error: negative time range') ;
end
if time_range(2) < 0 || time_range(1) < 0
error('error: the values in time range must be positives') ;
end
t = 1/FS ;
s_begin = floor( time_range(1) / t ) + 1 ;
s_end = floor( time_range(2) / t ) + 1 ;
start_sample = s_begin ;
samples_nr = s_end - s_begin ;
time = time_range(1) + (time_range(2) - time_range(1)) * (1:n) ;
ch = size(Y,2) ;
time_sf = zeros(n,samples_nr,ch) ;
p = 1 ;
for j=1:n
end_sample = start_sample + samples_nr - 1 ;
s = Y( start_sample:end_sample , : ) ;
s_f = fft( s ) ;
s_f = abs( s_f ) ;
for i=1:ch
s_f(:,i) = fastsmooth( s_f(:,i) , smooth , 1 , 1 ) ;
m(p) = max( abs(s_f(:,i) ) ) ;
p = p + 1 ;
end
time_sf(j,:,:) = gather( s_f ) ;
start_sample = start_sample + samples_nr ;
end
peak = gather( max( m ) ) ;
freq = ( FS / samples_nr ) * [0:(samples_nr-1)] ;
end