Sine Wave Frequency Sweep with Audacity

November 5th, 2008  |  by Adam Pope  |  10 Comments

I was recently trying to create a sine wave frequency sweep audio sample file to test out a digital signal processing (DSP) filter I was trying to write.  Using Audacity, you can create plug-ins to achieve all sorts of cool effects.  After a little experimentation I came up with the following code:

;nyquist plug-in
;version 1
;type generate
;name "Frequency Sweep"
;action "Producing frequency sweep..."
;info "by Adam Pope"

;control startf "Start Frequency (Hz)" real "" 1 0 20000
;control endf "End Frequency (Hz)" real "" 10000 0 30000
;control duration "Duration (secs)" real "" 20 1 300
;control type "Sweep scale [1=Linear, 2=Exponential]" int "" 1 1 2
;control other "I dont know what this does" real "" 5 0 100

(if (= type 2)
(fmosc startf (pwe duration endf other))
(fmosc startf (pwl duration endf other)) )

Copy this code into a frequencysweep.ny file and place it in your Audacity plug-ins directory.  You’ll need to restart audactity for it to register the new plug-in.  Once you’re back in, click on ‘Generate’ on the menu bar and select ‘Frequency Sweep’ from the list of options.  You will then be presented with a dialog containing sliders to play with the parameters of your sweep.  If any of the limits are too restricitve for you, simply change the values in the plug-in file!

If anybody can explain what the 3rd parameter of pwe and pwl does, I’d love to know!

Update: Many thanks to Paul Schimmel who sent me this updated version which removes the unknown parameter and also adds output level control.

;nyquist plug-in
;version 1
;type generate
;name "Frequency Sweep..."
;action "Producing frequency sweep..."
;info "by Adam Pope and Paul Schimmel"

;control startf "Start Frequency (Hz)" real "" 20 20 20000
;control endf "End Frequency (Hz)" real "" 20000 20 20000
;control duration "Duration (secs)" real "" 30 1 300
;control level "Level (dBFS)" real " " 0 -40 0
;control type "Sweep scale [1=Linear, 2=Exponential]" int "" 2 1 2

(if (= type 2)
(scale-db level (fmosc 0 (pwev startf duration endf))) (scale-db level (fmosc 0 (pwlv startf duration endf))) )

Tagged in:    

blogrssblogtwitter

10 Responses to “Sine Wave Frequency Sweep with Audacity”

  1. David Sky says:

    Adam, you can ask about Nyquist on the Audacity-Nyquist list
    https://lists.sourceforge.net/lists/listinfo/audacity-nyquist
    By the way, this is a ;vertion 1 plug-in, ;version 3 plug-ins
    have additional special features which aren’t in your plug-in.
    Best
    David Sky

  2. Steve says:

    Sorry Adam, you only managed to recreate Generate -> Chirp…

    Better luck next time!

  3. kaylea says:

    i dont understand where i put the code to make it frequency sweap
    can someone help please.

  4. nomis says:

    To get this working int he current Audacity build, just change the code so it reads on the second line version 1 instead of 3

  5. Adam Pope says:

    Kaylea, you need to copy the code into a new file with a name like frequencysweep.ny and place it in to your Audacity plug-ins directory.

    http://audacityteam.org/wiki/index.php?title=Nyquist_Plug-ins

  6. Zeb says:

    Hello Adam, thanks for writing this plugin. I’ve searched everywhere for a frequency sweep plugin and this is the only place that I’ve found info for it.

    That being said, I can’t get it to work! I’ve tried both of the versions that you have posted up above and everytime I do either one I get an error chime and a widow pops up (in Audacity) that says “Nyquist returned the value: 0.00000″. I have noticed that when I change the level slider in version 2 (for example from 0.0dBFS to -3.5dBFS) the error message will say “Nyquist returned the value: -3.500000. Any idea what could be causing this?

    I’m running Audacity 1.26 on Windows Vista

    If I hit the debug button it gives me the same error and then pops up another window that says:

    error: unbound variable – TYPE
    if continued: try evaluating symbol again
    Function: #
    Arguments:
    (= TYPE 2)
    (SCALE-DB LEVEL (FMOSC 0 (PWEV STARTF DURATION ENDF)))
    (SCALE-DB LEVEL (FMOSC 0 (PWLV STARTF DURATION ENDF)))
    1> [ gc: total 18640, 3673 free; samples 1KB, 0KB free ]

    I’m definitely not a programmer so this is greek to me! Thanks for you help!

  7. tangofish says:

    The “cut and paste code” above seems to be a bit corrupt for some reason?
    After fixing it up the code is working for me now, thanks to Adam and Paul for
    the good work!

    ;nyquist plug-in
    ;version 1
    ;type generate
    ;name “Frequency Sweep…”
    ;action “Producing frequency sweep…”
    ;info “version 1.2 by Adam Pope and Paul Schimmel (fixed by tangofish)”

    ;control startf “Start Frequency (Hz)” real “” 20 20 20000
    ;control endf “End Frequency (Hz)” real “” 20000 20 20000
    ;control duration “Duration (secs)” real “” 30 1 300
    ;control level “Level (dBFS)” real ” ” 0 -40 0
    ;control type “Sweep scale [1=Linear, 2=Exponential]” int “” 2 1 2

    (if (= type 2)(scale-db level (fmosc 0 (pwev startf duration endf))) (scale-db level (fmosc 0 (pwlv startf duration endf))) )

  8. Austin says:

    hi i am trying to save the .ny file but i cannot. i am running windows vista 32 bit. i tried using notepad but it saves it as a .txt file…and i know that isnt what i want.

  9. Adam Pope says:

    Hi Austin, I would recommend downloading a better text editor. Something like Notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm) will allow you to save a file with arbitrary file extensions (as well as being very useful for a lot of other jobs!)

  10. Sajowe says:

    After I had just worked out how to do this log freq sweep by myself I thought I’d Google it … and well here I am. I hadn’t though of adding the level controller & now have worked out how to make is a generator rather than a process plugin.

    But what I really wanted to say was just a note for the corruptness: when you copy it from the web browser into notepad the quotation marks (ie. “”) are not the proper ones. Just check to see if they are as I’ve also come across coping stuff from Web Browsers (& also MS Word) to notepad the “”s are actually a different character as such. When pasted they become directional “”s but with programming they should be the same at each end of the quote.

    Here’s my version anyway (the units have been fixed up a bit too)
    ;nyquist plug-in
    ;version 1
    ;type generate
    ;name “Freq Sweep”
    ;action “Log Freq Sweep…”
    ;info “by Sajowe”

    ;control frest “Start freq” real “Hz” 20 5 20480
    ;control frefl “Final freq” real “Hz” 20480 5 20480
    ;control swpduration “Duration” real “sec” 20 1 300
    ;control level “Level (dBFS)” real “dBFS” -3 -40 0

    (scale-db level (fmosc 0 (pwe 0.000001 frest swpduration frefl 5.001)))


Leave a Reply

Copyright © 2010 Storm Consultancy EU Ltd. All Rights Reserved.

Entries (RSS) | Comments (RSS)