I'm new to Nyquist, though I have done some DSP programming before. I have the following code working very well in Faust DSP, but am having a lot of trouble getting it to work in Nyquist. It's basically a type of mixer/oscillator that precisely divides an audio frequency by two.
The code divides a frequency by two by mixing it with the downmixed output. In this case a 16kHz sinewave input is mixed with the 8Khz downmixed output by feeding the filtered 8kHz output signal back and multiplying it with the 16kHz input to produce the 8kHz difference. This requires the previous output sample of the routine to be sent back to the first stage for multiplication. So far I haven't found a way to do this in Nyquist that actually works.
The dither ensures the process starts reliably. The working routine needs a limiter in the feedback path to prevent overload. This has been omitted from the example below for simplicity.
It appears as if there is no feedback happening. If the main expression is changed to:
set d = bandpass2(a * (0 + (noise() * dither-level)),8000,100) * 10
.. it produces the same result.
I suspect this is due to Nyquist's "Lazy evaluation".. but how can it be made to work?
The code is shown below.
Code: Select all
set a = hzosc(16000,*table*,0) ;generate a 16kHz sinewave input signal for testing set ditherlevel = db-to-linear(-50) ;set dither level if ! fboundp(quote(d)) then set d = 0 ;set d to zero only if d is unbound set d = bandpass2(a * (d + (noise() * ditherlevel)),8000,100) * 10 ;d = BPF(a * (d + dither)) * 10 return d