vult-dsp / vult

Vult is a transcompiler well suited to write high-performance DSP code
https://vult-dsp.github.io/vult
Other
490 stars 25 forks source link

Recovery From Instability // Frequency Mapping #30

Closed Miserlou closed 1 year ago

Miserlou commented 4 years ago

The biggest problem I am having as a Vult language user is unrecoverable instability.

This seems to come from my problem converting from actual-frequencies to w0 values for filters - there are some combinations which I'd expect to work, but will just totally crash the module in an unrecoverable way (ex, cutoff of .5 works but .4 crashes the plugin). Annoying! Can you explain the best way to convert from actual frequencies to values the filters from the cookbook will expect and not crash from (ex, 800Hz becomes .52 - how?)

Cheers! R

modlfo commented 4 years ago

Seems like these are two different issues. In general, w should have a range from 0 to 1. However, within this range you may encounter instabilities because of the limitations of the integration method. From DSP theory, a system becomes unstable of the poles move out of the unit circle. Depending on the system, you can expand the stability range by oversampling.

Regarding the conversion from f to w. One approximation is:

w = 2 Pi f / fs

This formula is not very good for f close to fs. If I remember correctly, the filters in the cookbook use the bilinear transform where w is as follows:

wd = 2 Pi  f
T  = 1 / fs
w = 2 / T  Tan(wd  T / 2);

You need to check the stability margins. Otherwise the filter will not be reliable no matter which language you use to implement it.