0
$\begingroup$

I'm trying to merge 2 identical audio files. The Audio file is nothing more than white noise generated using MATLAB commands

block_len = 4096;
Y = wgn(block_len, 1, 5, 120, 'dBm', 'real');

Rather than generating a longer block of data, i would like to make a longer file by concatenating the block of 4096 samples.

Therefore I tried a simple,

datat = [Y;Y;Y;Y;Y];
soundsc(datat)

The output file is not smooth enough. There is an audible periodic pattern that indicates the multiple 'Y' segments. I believed this could be due to the imperfect combination at the beginning and End of each Y segment.

Therefore I added the lines

Y(1) = 0;
Y(end) = 0;

Concatenating after these still does not have a smoothness to it. I searched on stackoverflow and found this link.

I tried the code based on the link above. I still can't get a smoothness to the white noise. What other methods can i try to make the sound as smooth as possible?

$\endgroup$
1
$\begingroup$

Rather than generating a longer block of data, i would like to make a longer file by concatenating the block of 4096 samples.

Bad idea. That means your noise becomes perfectly correlated with a period of 4096 samples, and that's definitely not white noise anymore, and you'll stand a realistic chance of noticing that audibly; depending on the sampling rate, that $\frac{f_\text{sample}}{4096}$ might be a directly audible frequency.

A lot of signal processing algorithms are sensitive to periodicity, so: really, don't do that.

By the way, you might be clipping. Gaussian noise amplitude is unbound, but your sound card's acceptable numeric range very much is.

The output file is not smooth enough. There is an audible periodic pattern that indicates the multiple 'Y' segments.

Which was predictable, because that's exactly what you've been asking it to generate.

I believed this could be due to the imperfect combination at the beginning and End of each Y segment.

No, this was you; you introduced periodicity, and your human sound system notices that. Congratulations! Your hearing is functional :)

You using a "blend over" technique on white noise says you haven't really thought about what white means: it means that there's no correlation between successive samples. Thus, if you concatenate two different, uncorrelated white noise sequences, you get a white noise sequence.

If you concatenate the same sequence, you get something periodic.

What you need to do is generate white noise of the desired length instead of concatenating short sequences. You forgot to mention why you would even want to do that, because (haven't benchmarked matlab) white noise generation should really be fast.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ White noise, by definition, means equal intensities at different frequencies. If we adhere to this definition, how can concatenating two same blocks of white noise change anything? The spectral content hasn't changed, has it? $\endgroup$ – dsp_user Nov 11 '19 at 11:35
  • $\begingroup$ White noise, by definition, is uncorrelated (which is exactly the same as saying the expectation of the noise power spectral density is a constant): So yes, the spectral content very much changes. As explained in length, you introduce periodicities. So, afterwards, you are correlated, and you see exactly that in the PSD; it's pretty obviously no longer white. $\endgroup$ – Marcus Müller Nov 11 '19 at 16:34
  • $\begingroup$ @dsp_user remember the definition of "spectrum": It's the fourier transform of the autocorrelation function of a stochastic signal. Now, your stochastic signal repeats every 4096 samples, meaning you get a strong peak in the autocorrelation function every 4096 sampling duration, which, after Fourier Transformation, yields a peak at a frequency (and its negative counterpart); it can't be white anymore. $\endgroup$ – Marcus Müller Nov 11 '19 at 16:41
  • $\begingroup$ the problem is I still hear the concatenated signal as white noise. It takes probably a minute or so to simulate this in Audacity and I can't hear any audible anomaly (sorry couldn't find a better word) in the signal generated (but granted I didn't concatenate two 4096 sample blocks). $\endgroup$ – dsp_user Nov 11 '19 at 19:51
  • $\begingroup$ @dsp_user you might simply have a different noise realisation than OP – op describes distinguishable "repeating" features. And, OP doesn't seem to be randomly seeding their noise generator, thus always producing the same noise. $\endgroup$ – Marcus Müller Nov 11 '19 at 19:53
1
$\begingroup$

We discussed this phenomenon on the music-dsp mailing list in May 2014.

For long enough a period, the audible repetition is not directly about the frequency spectrum but that instances of white noise are not white but usually contain distinct features or patterns that can be learned and then recognized in the later periods. In some instances, there will be more distinct features than in others. An interesting follow-up question would be, how can we create noise that is as featureless as possible? Spectrogram smoothing works to some extent, but I don't think it's the last word.

Clips of white noise can be readily concatenated, because white noise has zero autocorrelation at non-zero time lags. Other types of noise would require more gentle splicing.

|improve this answer|||||
$\endgroup$
0
$\begingroup$

If you were to assemble a very large number of these segments and then take the FFT of the entire signal, you would see that you have a series of spectral sticks every FS/4096 hz, with nothing in between, because the signal you have made by concatenation is periodic.
However your ear does not have an infinite analysis window, so once your block length is much longer than, say, 50ms, you shouldn’t be able to hear the effects of concatenation. If your FS is set to 48khz, then 4096 samples represents about 85ms in time. Therefore I’m surprised you can hear any effect. What is your sample-rate? If it’s very high then the repetition rate will be faster and may be audible.
Also you might try removing the mean from your 4K noise segment before concatenation (although in theory this should not be necessary)

Bob

|improve this answer|||||
$\endgroup$
  • $\begingroup$ He doesn't say he hears the repetitivity as a "tonal experience", but as repeating pattern - which fits nicely into your explanation. $\endgroup$ – Marcus Müller Nov 11 '19 at 16:35
0
$\begingroup$

@Marcus I took your advice based on the correlation. So i modified the Y segments to generate different white noise at each instance. Here is the MATLAB code for the same.

clc;clear all;close all;

block_len = 4096;
YY = wgn(block_len, 1, 50, 10, 'dBm', 'real');
XY = wgn(block_len, 1, 50, 10, 'dBm', 'real');
ZY = wgn(block_len, 1, 50, 10, 'dBm', 'real');
VY = wgn(block_len, 1, 50, 10, 'dBm', 'real');
S1 = YY/max(YY);
S2 = XY/max(XY);
S3 = ZY/max(ZY);
S4 = VY/max(VY);

% S1 = rand(1000,1);
% S2 = rand(1000,1) + 1;

%\\ cross-fade over last 200 elements
n = 256;
nob = 2;

W = linspace(1,0,n)';                                    %'

S1(end-n+1:end) = S1(end-n+1:end).*W;
S2(1:n) = S2(1:n).*(1-W);
S2(end-n+1:end) = S2(end-n+1:end).*(W);

S12 = zeros(size(S1,1) + size(S2,1) + size(S2,1) + size(S2,1) - n, 1);
S12(1:size(S1,1)) = S1;
S12((block_len*2)-n-size(S1,1)+1:(block_len*2)-n) = S12((block_len*2)-n-size(S1,1)+1:(block_len*2)-n) + S2;

startpt = (block_len*3)-(2*n)-size(S1,1)+1;
endpt = (block_len*3)-(2*n);
S12(startpt:endpt) = S12(startpt:endpt) + S3;

startpt = (block_len*4)-(3*n)-size(S1,1)+1;
endpt = (block_len*4)-(3*n);
S12(startpt:endpt) = S12(startpt:endpt) + S4;

soundsc(S12) 

Now the periodic pattern is not audible. Therefore it was that correlation that was to blame.

@Bob I also changed

  block_len = 16384

and

startpt = (block_len*3)-(2*n)-size(S1,1)+1;
endpt = (block_len*3)-(2*n);
S12(startpt:endpt) = S12(startpt:endpt) + S2;

startpt = (block_len*4)-(3*n)-size(S1,1)+1;
endpt = (block_len*4)-(3*n);
S12(startpt:endpt) = S12(startpt:endpt) + S2;

at which point, the periodic pattern wasn't noticeable anymore. So both your explanations hold true.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.