Frequency Sweep Using MQS

andrewn2

New member
Hello,

I am using MQS to create a frequency sweep to drive a speaker. I have everything working, using some code I found on these forums:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthToneSweep tonesweep1; //xy=102,174
AudioAmplifier    amp1;   //xy=324,172
AudioOutputMQS    mqs1;   //xy=538,168
AudioConnection   patchCord1 (tonesweep1, amp1);
AudioConnection   patchCord2 (amp1, 0, mqs1, 0);
// GUItool: end automatically generated code

const float t_ampx  = 0.3;
const int t_lox = 1;
const int t_hix = 25;
const float t_timex = 100;   // Length of time for the sweep in seconds

void setup(void)
{
  // Wait for at least 3 seconds for the USB serial connection
  Serial.begin (9600);
  while (!Serial && millis () < 3000)
    ;

  delay (3000);

  AudioMemory (2);
  amp1.gain (1);

  Serial.println("setup done");

  if (!tonesweep1.play (t_ampx, t_lox, t_hix, t_timex)) {
    Serial.println ("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  Serial.println ("Tonesweep up started");
  while (tonesweep1.isPlaying ())
    Serial.println(tonesweep1.read())
    ;

  // and now reverse the sweep
  Serial.println ("Tonesweep down started");
  if (!tonesweep1.play (t_ampx, t_hix, t_lox, t_timex)) {
    Serial.println("ToneSweep - play failed");
    while (1)
      ;
  }

  // wait for the sweep to end
  while (tonesweep1.isPlaying ())
    ;
  Serial.println("Done");
}

void loop(void)
{
}

I am wondering how it would be possible to decrease the 'step' between frequencies. Currently, it steps up by 1 hz every couple seconds, but I would like it to be lower, such as 0.1 hz or so. Is this possible? If so, how can I implement it?

Let me know if you have any further questions.

Thanks!
 
Andrew: I believe what you're really after is how to make the "tonesweep" object do what you desire. If you'll open the "Audio System Design Tool" (I don't know what your development environment is, so to make things easy, <this> version is accessible from the PJRC website), you'll see all of the audio objects that are available from the Teensy audio library. On the left-hand side, scroll down until you find the "tonesweep" object (under the "synth" category). If you click on that "tonesweep" object, all of the particulars for that object will be shown in the right-hand margin. Note the particular details of the "play" function. You should be able to adjust the last parameter (time) to cause a slower sweep, which should then change at a finer frequency step size, like I believe you are after.

Hope that helps . . .

Mark J Culross
KD5RXT
 
Hi Mark, thanks for the response.

I'm somewhat familiar with the Audio System GUI, and have taken a look at the 'tonesweep' object functions/details. (On a side note, is there a more in-depth documentation for objects within the audio system?)

To my testing, using
Code:
Serial.println(tonesweep1.read())
to output the frequency, changing the time doesn't seem to change the step size, rather it just changes how much time is spend on each frequency. For the example I included in my initial post, it seemed like the program spent about 3-4 seconds on each frequency, before jumping up (or down) to the next, with a step of 1 hz. I changed the time a few times, and the time spend on each frequency changed, but not the step...

I'm wondering if I may have to generate a signal using the 'sine' object and just loop through different frequencies, with a smaller step size.

Thanks.
 
Hello,

I am using MQS to create a frequency sweep to drive a speaker. I have everything working, using some code I found on these forums:

That looks like the code I posted when the Teensy 4.0 came out. If so, I'm glad it was helpful.

I am wondering how it would be possible to decrease the 'step' between frequencies. Currently, it steps up by 1 hz every couple seconds, but I would like it to be lower, such as 0.1 hz or so. Is this possible? If so, how can I implement it?

Let me know if you have any further questions.

Thanks!

I don't believe the Audio SynthToneSweep function has an option to decrease the step. At least according to the documentation, there isn't an option to do what you want:

But since the library source is available, you could clone the function after changing the name, and add an extra argument to do what you want.
 
Hi Mark, thanks for the response.

I'm somewhat familiar with the Audio System GUI, and have taken a look at the 'tonesweep' object functions/details. (On a side note, is there a more in-depth documentation for objects within the audio system?)

To my testing, using
Code:
Serial.println(tonesweep1.read())
to output the frequency, changing the time doesn't seem to change the step size, rather it just changes how much time is spend on each frequency. For the example I included in my initial post, it seemed like the program spent about 3-4 seconds on each frequency, before jumping up (or down) to the next, with a step of 1 hz. I changed the time a few times, and the time spend on each frequency changed, but not the step...

I'm wondering if I may have to generate a signal using the 'sine' object and just loop through different frequencies, with a smaller step size.

Thanks.

Whoops !! Sorry my suggestion was not very helpful !! I should have looked at the source before I "assumed" that lengthening the time would automatically decrease the step size. It should be relatively easy to modify the source, either as Michael suggested (adding another parameter), or by calculating the step size based upon the duration (as I assumed earlier). Note that the minimum frequency change will always be constrained by the 2.9ms sample/process rate of the audio library.

And to answer your question on documentation, as far as I know, the documentation that I am aware of is either that given in the Audio System Design Tool, or any additional info available by looking at the comments in the source.

Mark J Culross
KD5RXT
 
Back
Top