# Prevent clicking noises during chirp generation

I am trying to generate a tonal sound which changes in frequency and amplitude over time. The goal is to emulate an engine order during driving. So I don't know the frequencies and the amplitudes upfront. They depend on the driving situation. So far I managed to get it to work. However in the generated sound sometimes clicks occur. I think it happens when the amplitude changes too fast. As I can't control the amplitude I would like to know what I can do to prevent this clicking noise to happen?

Matlab code: yo=sin(2*pi*cumtrapz(Time,(Rpm_vec/60*order(k)))+pi*start_phase(k)/180).*Amplitude(Time);

Rpm_vec and Time are vectors with the engine speed and the corresponding time trace obviously.

In the following picture the blue curve is the generated sound pressure, while the red curve is the absolute value of the sound pressure and the green curve is the amplitude that I have to deal with. In black I have encircled where a step in sound pressure happens causing a clicking sound.

Any help is kindly appreciated!

Edit

Thank you for the good comments! k is an enumerator in case I want to emulate multiple Engine Orders. For this example k can be just 1. I think the hint to keep the argument between 0 and 2pi makes sense. Using cumtrapz is not good. I'll try to avoid that. Further I had the idea to smoothen the Amplitude with a lowpass filter. The lower the frequency I want to emulate the lower should be the stopband of that lowpass-filter. Steep changes in the amplitude combined with a low frequency lead to clicks I guess.

• Your code is just a fragment and hard to read since it's all jammed in a single line. I'm guessing this is a phase discontinuity and not an amplitude problem. Plot the argument of the sine over time and see how that looks like. Infinite phase integration doesn't work that well since the accumulated phase gets so large that adding a small number is lost in the numerical noise. Try keeping it always in $[0,2\pi]$ Dec 17, 2020 at 14:20
• Can't tell what $k$ is from your code. You could try to smooth the amplitude discontinuity by adjusting the constant phase offset of the new chirp to match the ending chirp. This may help if the discontinuity is of limited size - if it's too big then you can't make it match. You could also try a linear cross fade between the amplitude portions i.e. ramp one amplitude down and ramp one amplitude up. Dec 17, 2020 at 16:40