1
$\begingroup$

I have a total sound duration of $T$.

I break the duration to several sub-durations and in each sub-duration, I generate several discrete sinusoidal values by the formula $\sin(2\pi ft)$ with a sampling rate of $f_s$.

The frequency used in consecutive sub-durations is different.

Now when I generate sound using these values (using matlab) I get audible click sounds between the point where two sub-durations meet; I think because of discontinuity. How can I remove these audible click sounds?

Edit the code I am using (roughly)

duration = 0.25;
sampleRate = 44100;
numberOfSamples = (duration * sampleRate);
frequency = 19000:500:21500;
freqHopSamples = [];

for j = 1:length(frequency)
    startIndex = ((j-1)*(numberSubSamples) + 1);
    endIndex = j*numberSubSamples;
    t = (startIndex:endIndex)/sampleRate;
    freqHopSamples(startIndex:endIndex) = sin(2*pi*frequency(j)*t);
end

wavwrite(freqHopSamples, sampleRate, 'sound.wav');
$\endgroup$
  • $\begingroup$ You have to make sure of smoothest possible passage between the blocks. @OlliNiemato had a post for a similar question, where high order continuity of the pieces is maintained... Another option is to window the blocks but that would alter their waveforms significantly, if that's a matter. $\endgroup$ – Fat32 Oct 25 '17 at 5:35
  • $\begingroup$ Can you please share the link of the post if you have it? Thanks. $\endgroup$ – besabestin Oct 25 '17 at 7:12
  • $\begingroup$ you may search the site for " audio, block, pop, noise, click, burst, removal " $\endgroup$ – Fat32 Oct 25 '17 at 11:08
2
$\begingroup$

One method is to adjust the phase of the sinusoid at the beginning of each segment to minimized the 1st or 2nd delta phase difference from the phase at the end of the last segment. Another method might adjust several samples at each boundary to minimize multiple derivatives.

You currently seem to start with a phase of zero, which could randomize the phase delta between segments, depending on frequency and segment length.

$\endgroup$
  • $\begingroup$ Thanks for the reply! I ll consider to test the concept of changing the phase. I have previously used (as you said) adjusting several samples at each boundary (I make them fade to 0 when it is close to the boundary starting from some point). And it was working but the signal nature was a bit affected. A programmer myself, I haven't thought my hands much with dsp. When you say minimizing the delta phase difference, what does it mean? I haven't used any phase at all here. If you also have a link to share that would be nice. Thanks for your time. $\endgroup$ – besabestin Oct 25 '17 at 10:01
1
$\begingroup$

The simplest idea to me seems to be to write the for-loop so that it allows moving onto a new frequency only when the previous wave is at value 0. And obviously, the new frequency has to start drawing from value 0 as well.

Because of the nature of frequency meaning a different amount of oscillations per time segment, then it's of course not possible to fit them into even sub-segments without discontinuities.

Another option could be to specify a short amplitude cross-fade to occur whenever a change to a new frequency occurs. It doesn't have to be long, e.g. 5 ms is enough to remove the click.

Now if the sub-segments have to be exactly the same length, then I would go with hotpaw2's recommendation about computing the phase shift one needs to make the segments align.

$\endgroup$
  • $\begingroup$ thanks :) I like the idea of continuing after the previous hits 0. I ll try and let you know. $\endgroup$ – besabestin Oct 25 '17 at 11:19

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.