0
$\begingroup$

I can create a swept / chirp signal using matlab / octave with the code below (also see spectrum taken). But how can I create a swept / chirp signal between a given starting audio signal and a given ending audio signal? (One way to look at it is morphing one image into another image but using two audio signals) or a sliding / chirp phase vocoder

clc,clear all
swept_startfreq = 500;
swept_endfreq = 225;
fs = 8000;
swept_dursec = 15;  % duration of signal in seconds  
swept_t = (0:swept_dursec*fs)/fs;  % Time vector

if (swept_startfreq == swept_endfreq)
      swept_phase = swept_startfreq * swept_t;
else
    swept_alpha = abs(log(swept_endfreq/swept_startfreq))/swept_dursec;
    swept_b = (swept_startfreq - swept_endfreq)/(1 - exp(-swept_alpha*swept_dursec));
    swept_a = swept_startfreq - swept_b;

    swept_phase = swept_a*swept_t - (swept_b/swept_alpha)*exp(-swept_alpha*swept_t);
endif

swept_sig_out = .8* cos(2*pi*swept_phase); %equation used to create signal
wavwrite([swept_sig_out'] ,fs,32,strcat('/tmp/swept_sig_out.wav'));  % export file

The frequency spectrum of the original code / chirp or swept signal it creates Frequency Spectrum

So I would have an initial audio signal (use as the initial audio signal for testing) and an ending audio signal (use as the ending audio signal for testing). How can I do a "morphing" between these two signals?

Here's what an example of the final file would sound like example of final audio signal when processed (please not this isn't exact but it shows how the pitch gradually changes from the original signal to the end audio signal over time If you would like to know how I created the final file I used the initial signal and Audacity with the effect - Sliding Time Scale/Pitch Shift to get as close as possible to what the ending signal sounds like.

Added from comments: Start with the frequency with the largest amplitude in the initial signal and "morph" it towards the frequency with the largest amplitude found in the ending signal

It would sound like "one one one one one" gradually decreasing or increase in pitch depending on the ending audio signals largest amplitude frequency found. Please note the Initial and ending audio signal may not be the same type of signal, the initial signal could be "one one one one" and the ending signal could be "two two two two"

Ps: I'm using Octave 4.0 which is like matlab

$\endgroup$
  • $\begingroup$ It's not well-defined. You'd need to pick out the dominant frequencies in both signals and re-synthesize them to shift to the new dominant frequencies. What if the first signal is a sawtooth chirping from 100 to 200 Hz, and the second signal is a sawtooth chirping from 600 Hz to 500 Hz. What if the first signal is a single sine wave tone and the second is a multi-tone piano chord? How do you want the frequencies to "morph"? Can you plot the spectrograms of each and draw how you'd like it to look? $\endgroup$ – endolith Jun 2 '17 at 18:36
  • $\begingroup$ @endolith sorry about that ... if you start with the frequency with the largest amplitude of the initial signal and "morph" it towards the ending signal frequency with the largest amplitude does that help define it better? ... I've included two signals located in dropbox to test with in the question above...."So I would have an initial audio signal and an ending audio signal It would sound like "one one one one one" gradually decreasing or increase in pitch depending on the ending audio signals frequency with the largest amplitude" $\endgroup$ – Rick T Jun 2 '17 at 19:10
  • $\begingroup$ by "one one one" you mean spoken word? that contains many frequencies, not just one. $\endgroup$ – endolith Jun 2 '17 at 20:31
  • $\begingroup$ @endolith Yes "one one one" spoken word an example test file is located in the question (dropbox file) above I was thinking an adapted vocoder would do it but I couldn't find anything that would accept an audio file for both starting signal and ending signal. I was able to add an example of what the final audio file would sound like dropbox.com/s/poife3pdmu38jaa/final_num_01.wav?dl=0# I also added the file link to the question $\endgroup$ – Rick T Jun 2 '17 at 21:22
  • $\begingroup$ Well the example files you posted are not morphing between different sounds. The first and last sound are the same, just pitch-shifted. Do you want to make a pitch-shifter? $\endgroup$ – endolith Jun 2 '17 at 21:46
1
+50
$\begingroup$

As noted by endolith in the first comment, the problem is not well defined, in that, there's no one right way of doing this audio morph/crossfade.

One method would be to use some form of interpolation between the source and destination spectra as discussed in this paper and implemented in this toolbox. A similar technique is also discussed in this paper.

This paper proposes another possible method inspired by the problem of heat diffusion. Imagine the left edge of a metal plate is held at a "temperature profile" that resembles the magnitude spectrum of the first signal and the right edge is held at a "temperature profile" resembling the magnitude spectrum of the second signal. The 2D "temperature profile" function between the two edges is reconstructed by solving a heat diffusion problem. An intuitively pleasing property of crossfades obtained with this method is that it produces smooth chirps if two sinusoidal frequencies are close to each other, but produces a fade-in/fade-out effect if they are farther apart. See their audio examples here.

I have not succeeded in locating good Matlab implementations of audio morphing algorithms. But there are a couple of good starting points. For instance, the Java library in the Spectral Toolbox has an audio morphing Java source code which can be converted to Matlab with some effort. Another good starting point might be this Github repo.

W. Sethares, J. Bucklew, Kernel techniques for generalized audio crossfades, Cogent Mathematics 2(1), 2015.

W. Sethares et al., Spectral Tools for Dynamic Tonality and Audio Morphing, Computer Music Journal 33(2), 2009.

M. Slaney, et al, Automatic Audio Morphing, Proc. IEEE ICASSP, 1996.

$\endgroup$
  • $\begingroup$ I was looking for some Octave / Matlab code that would do this but I didn't find it on any of the links you mentioned did I overlook it? $\endgroup$ – Rick T Jun 3 '17 at 15:38
  • $\begingroup$ I couldn't locate any Matlab code, but there's some Java code in contmorph.java in this toolbox homepages.cae.wisc.edu/~sethares/software/SpectralToolbox.zip. The code is quite readable and shouldn't be too hard to translate line-for-line into Matlab. $\endgroup$ – Atul Ingle Jun 5 '17 at 15:21
  • $\begingroup$ I tried but unfortunately I couldn't convert the java code into Octave / Matlab code. $\endgroup$ – Rick T Jun 6 '17 at 20:59
  • $\begingroup$ I edited the answer with a link to a Github repo which might be a good starting point for some Matlab code. $\endgroup$ – Atul Ingle Jun 7 '17 at 15:32

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.