Skip to content

Commit bbf36bb

Browse files
committed
Updated repet.original function.
1 parent d5011d2 commit bbf36bb

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

repet.m

+26-22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
% http://zafarrafii.com
3535
% https://github.com/zafarrafii
3636
% https://www.linkedin.com/in/zafarrafii/
37-
% 01/21/21
37+
% 01/22/21
3838

3939
% Define the properties
4040
properties (Access = private, Constant = true)
@@ -92,42 +92,44 @@
9292
% Get the number of samples and channels in the audio signal
9393
[number_samples,number_channels] = size(audio_signal);
9494

95-
% Window length, window function, and step length for the STFT
96-
window_length = repet.windowlength(sampling_frequency);
97-
window_function = repet.windowfunction(window_length);
98-
step_length = repet.steplength(window_length);
95+
% Set the parameters for the STFT
96+
% (audio stationary around 40 ms, power of 2 for fast FFT and constant overlap-add (COLA),
97+
% periodic Hamming window for COLA, and step equal to half the window length for COLA)
98+
window_length = 2^nextpow2(0.04*sampling_frequency);
99+
window_function = hamming(window_length,'periodic');
100+
step_length = window_length/2;
99101

100-
% Number of time frames
101-
number_times = ceil((window_length-step_length+number_samples)/step_length);
102+
% Derive the number of time frames
103+
number_times = ceil(((number_samples+2*floor(window_length/2))-window_length) ...
104+
/step_length)+1;
102105

103106
% Initialize the STFT
104107
audio_stft = zeros(window_length,number_times,number_channels);
105108

106109
% Loop over the channels
107-
for channel_index = 1:number_channels
110+
for i = 1:number_channels
108111

109-
% STFT of the current channel
110-
audio_stft(:,:,channel_index) ...
111-
= repet.stft(audio_signal(:,channel_index),window_function,step_length);
112+
% Compute the STFT of the current channel
113+
audio_stft(:,:,i) = repet.stft(audio_signal(:,i),window_function,step_length);
112114

113115
end
114116

115-
% Magnitude spectrogram (with DC component and without mirrored
116-
% frequencies)
117+
% Derive the magnitude spectrogram
118+
% (with the DC component and without the mirrored frequencies)
117119
audio_spectrogram = abs(audio_stft(1:window_length/2+1,:,:));
118120

119-
% Beat spectrum of the spectrograms averaged over the channels
120-
% (squared to emphasize peaks of periodicitiy)
121+
% Compute the beat spectrum of the spectrograms averaged over
122+
% the channels (take the square to emphasize periodicity peaks)
121123
beat_spectrum = repet.beatspectrum(mean(audio_spectrogram,3).^2);
122124

123-
% Period range in time frames for the beat spectrum
125+
% Get the period range in time frames for the beat spectrum
124126
period_range = round(repet.period_range*sampling_frequency/step_length);
125127

126128
% Repeating period in time frames given the period range
127129
repeating_period = repet.periods(beat_spectrum,period_range);
128130

129-
% Cutoff frequency in frequency channels for the dual high-pass
130-
% filtering of the foreground
131+
% Get the cutoff frequency in frequency channels for the dual
132+
% high-pass filtering of the foreground
131133
cutoff_frequency = ceil(repet.cutoff_frequency*(window_length-1)/sampling_frequency);
132134

133135
% Initialize the background signal
@@ -136,16 +138,18 @@
136138
% Loop over the channels
137139
for channel_index = 1:number_channels
138140

139-
% Repeating mask for the current channel
141+
% Compute the repeating mask for the current channel given
142+
% the repeating period
140143
repeating_mask = repet.mask(audio_spectrogram(:,:,channel_index),repeating_period);
141144

142-
% High-pass filtering of the dual foreground
145+
% Perform a high-pass filtering of the dual foreground
143146
repeating_mask(2:cutoff_frequency+1,:) = 1;
144147

145-
% Mirror the frequency channels
148+
% Recover the mirrored frequencies
146149
repeating_mask = cat(1,repeating_mask,repeating_mask(end-1:-1:2,:));
147150

148-
% Estimated repeating background for the current channel
151+
% Synthesize the repeating background for the current
152+
% channel
149153
background_signal1 ...
150154
= repet.istft(repeating_mask.*audio_stft(:,:,channel_index),window_function,step_length);
151155

0 commit comments

Comments
 (0)