Molding a tone to a given audio sample (matching silences)

Ok, so here is my question. I have this audio input:

I want to strengthen/restructure the signal (which, as it happens, is an infrared signal). To do this, I generate a tone (Sine, 19000 hz, 0.9 amp).

I then highlight the ‘silent’ areas in both tracks, and use the silence function (control+L) on them:

Now, since I have tons of these files, it’s a bit too tedious to do this by hand. I was wondering if there was an add-on/plug-in already available that could be used to do this for me? Or if anyone has any LISP tips on writing one for myself? (I’ve written a couple small add-ons for other projects in LISP/Nyquist, so I am familiar with it).

Thanks for your help,
Sean

That’s what the vocoder and other modulation tools do. You only get an output with the presence of both carrier (sine wave tone) and the performance (square wave).

You must have seen the Peter Frampton Geico commercial?

http://www.youtube.com/watch?v=B0Pw2W6zIZI

The guitar is only presented during the application of his voice. Electronically this is also known as a linear multiplier.

I have no idea how to program one.

Koz

Stevethefiddles amplitude modulation code would do the job on the first bit of signal where the square wave doesn’t go below zero

(sim (mult (aref s 1) -0.5)
   (mult (sum 0.5 (scale 0.5 (aref s 0)))(aref s 1)))

http://www.audacityteam.org/forum/viewtopic.php?f=28&t=9100&p=37121

Do you only want 19KHz pulses of sine when the square wave is positive ?


http://audacityteam.org/help/nyquist

Thanks for both the above posts, I’m checking them out now as I type this.

@ Trebor,
Yes, only want 19kHZ pulses when square waves is positive (or, to be safe, could even do >0.3 or so)

@Trebor
That was exactly what I was looking for. I’m very close now, just need a few touchups (that really shouldn’t be too tough).

So here is what I started with

Then after running this code:

(sim (mult (aref s 1) -0.4)
   (mult (sum 0.9 (scale 1 (aref s 0)))(aref s 1)))

I got this:

To finish it, all I have to do is get the parts of wave that are under an amplitude of, say, 0.6 to go silent.

I’m sure there exists an easy bit of code for this, and I’ll start looking for it (if you wish to give me a shortcut by posting it here, I will be forever grateful :smiley:).

Thanks for both of your guy’s help. I’m a computer engineer/scientist, and it’s not often I dwell in the realm of sound.

I found this code somewhere on the forums:

(setf v (snd-fetch s)

Apparently it returns amplitude. Is it possible to run this code through an entire <1 second file, and if the amplitude is less than 0.4 silence that section? If only LISP had if statements and curly braces instead of just lots… and lots… and lots of parenthesis.

There should be a simple way of doing this with nyquist code: if left channel is less than 0.6 then make amplitide of right channel zero, that sort of thing.

If all else fails you could use a gate such as GGate (free) to make the low level signal zero (silent). Gates are filters which make all the audio signal below an adjustable threshold zero.

You’ll need to install the “VST bridge” to use GGate in Audacity.

The above method is unnecessarily complicated but would work, hopefully Stevethefiddle will come to the rescue with some Nyquist code.

[I have GGate installed,
If your audio files are only a few seconds long you could email me a WAV and I will gate it (i.e. make the bits below 0.6 zero)
I have set you a PM with my email address}

From looking at the original waveforms, you might also benefit from some “fake samples.”

It takes a couple of pulses for the system to settle in, so putting two or three “fake” pulses ahead of the valuable data would cause the settling to happen on the known lead-in set and not the data. Alternatively, you could take two complete samples and discard the first one.

That will broaden the range for cleaning up since the data pulse is now reliably very much larger than the “dirt” in the silent patches.

And there is one other real-world problem. The pulses, even though they’re mostly audio won’t reliably go through an audio system. To recreate the square blasts of 19 KHz accurately, I bet your “sound system” had to respond out to at least 60 KHz and probably further. Starting a sine wave from a dead stop to maximum amplitude creates an infinite number of sidebands. If you don’t have an infinitely wide channel, the sine wave won’t start right or will be distorted on the way up and then again on the way down. In extreme cases, it might ring creating data errors.

This is basic AM Radio theory. The maximum fidelity possible on a 10 KHz wide restricted radio channel is 5 KHz audio. Sparkly crisp clear audio need not apply.

You realize, right, that we’re redesigning the Credit Card Magnetic Stripe Reader?

Koz

Ah, that may solve a couple problems I’ve been having. Thanks for the tip.

And there is one other real-world problem. The pulses, even though they’re mostly audio won’t reliably go through an audio system. To recreate the square blasts of 19 KHz accurately, I bet your “sound system” had to respond out to at least 60 KHz and probably further. Starting a sine wave from a dead stop to maximum amplitude creates an infinite number of sidebands. If you don’t have an infinitely wide channel, the sine wave won’t start right or will be distorted on the way up and then again on the way down. In extreme cases, it might ring creating data errors.

All that has been solved with a little engineering :wink:
It actually recreates square blasts of 38 KHz - 19 in left, then reverse 19 in right, which when played together through a little device I built adds the two together to create a 38 khz signal. It’s a neat piece of work.
Edit: Just found the patent for it

This is basic AM Radio theory. The maximum fidelity possible on a 10 KHz wide restricted radio channel is 5 KHz audio. Sparkly crisp clear audio need not apply.

Luckily, when these are outputted, they do not go through speakers or headphones or anything at all - they rather go through a box that connects them to some IR leds, and converts the signal into IR (essentially).

You realize, right, that we’re redesigning the Credit Card Magnetic Stripe Reader?

Really? I had not realized that. That’s kinda funny though - one of the other projects I was going to work on this summer with my friend was just that, a magnetic stripe reader. This, however, is part of a project to turn a laptop into a universal remote. We already finished the project, except adding new remotes is somewhat tedious as each signal has to be adjusted by hand - thus, this plug in. I’d be happy to post a description of the finished project once we’ve got this working if you’re interested :wink:

Ya, I figured there was. Still honing my skills with LISP though, I’m used to a heck of a lot less of parenthesis. We’ll see if steven comes to the rescue :wink:

If all else fails you could use a gate such as > GGate > (free) to make the low level signal zero (silent). Gates are filters which make all the audio signal below an adjustable threshold zero.

You’ll need to install the "> VST bridge> " to use GGate in Audacity.

I went ahead and tried this. I played with the settings quite a bit, but the best I could get it to do was to silence the unwanted tones in the front, and half of them in the end - it had no effect on those in between the signals I want to keep, or the first half of the end. I’ll keep playing around with it.

I didn’t quite appreciate how unlike audio your signals are: 19KHz is inaudible to most people, and your pulses are only about a millisecond long.

Ggate was designed to deal with audio, this may explain why it could not silence parts of your signal : its response time may not be quick enough to cope with millisecond pulses.

For your purposes the attack and fade times on GGate should both be set to “zero”, only experimenting with threshold value.
If that doesnt work then its down to Nyquist code, or possibly a hardware solution with a quicker respose time like a transistor gate.

[Re: hardware solution: I’ve seen similar pulse width modulation done with cheapo 555 timers, although the output was square not sine.
e.g http://www.dprg.org/tutorials/2005-11a/index.html, Pulse Width Modulation - Electronics in Meccano]

If you performed half-wave rectification on the square wave before using Steve’s Amplitude Modulation code that may help.
Here is a bit of Nyquist code which allegedly performs half-wave rectification returning only the positive half cycles of signal …

; pos neg and rectify functions by Steven Jones
; > http://www.shellworld.net/~davidsky/sj-plugs.htm >

; > Return only the positive half cycles of signal
(defun pos (signal)
(if (arrayp signal)
(vector (s-max (aref signal 0) 0.0) (s-max (aref signal 1) 0.0))
(s-max signal 0.0)))

http://n2.nabble.com/New-plug-in:-Self-ring-modulator-td2293146.html

May contain a clue to the solution.

Been working on this issue for several days now. Don’t have much progress to report. I started coding other LISP programs though (to get me more familiar with the language) so expect progress soon.

Let me know if any new thoughts strike you :slight_smile:

I have butchered one of David Sky’s plugins to produce the positive half wave rectification required, (guess where I have applied it in this waveform)
HalfWaveRectified.png
I have attached a zip file containing the aforementioned butchered plugin which I have called “Half Wave Rectifier (+ve)” which should appear on the (unsorted*) effects list after you extract the file (unzip) and place the “HalfWaveRectifier(Pos).NY” file in Audacity’s plug in folder then restart Audacity.

After half wave rectification you will still have to apply Steve’s Amplitude modulation code to create your pulses.

(* Audacity 1.3)
HalfWaveRectifier(Pos).zip (820 Bytes)

From top to bottom:
1000Hz square wave,
Half wave rectified 1000Hz square wave,
19KHz “sine”,
19KHz “sine” amplitude modulated by the rectified 1000Hz square wave.
1ms_Pulses_of_19KHz.png
[I put “sine” in quotes because at a sample rate of 44.1KHz a 19KHz sine wave is more like triangular waveform].

Trebor, I love you. Nuff said.

:stuck_out_tongue: On a more serious note, Thank you!!! I’ll be testing this out today. You’ve been a great help Trebor!

It works like a charm :slight_smile:

Thanks again Trebor!

Sorry I missed this one - been off-line due to a broadband fault :frowning:

Interesting to see the solution that you guys have come up with.
An alternative method would have been to modify the low frequency wave by using a combination of multiplying, and addition / subtraction and the “clip” function so that the modified low frequency wave had a maximum amplitude of 1.0 and a minimum amplitude of 0.0

Multiplying this modified low frequency wave with the high frequency wave would then produce the required modulation.

Here’s a single line of code that should do the job:

(mult (aref s 1)(sum 0.5 (scale 50 (clip (aref s 0) 0.01))))

Was just looking at this thread and noticed the rather complex code for a half-wave rectifier.

There is already such a function built into Nyquist: (s-max sound1 sound2). This takes two sounds (mono or multi-channel), or a sound and a FLONUM (or two FLONUM’s for that matter) and for corresponding samples in the sounds, it returns the maximum. So the expression (s-max s 0.0) will replace all the negative valued samples with zero.

To grab only the negative side of the signal, use (s-min s 0.0).