Random LFO

Algorithm development and general DSP issues

Moderator: frank

Post Reply
AudibleObjects
Posts: 2
Joined: Fri Apr 15, 2011 10:14 am

Random LFO

Post by AudibleObjects »

I've been trying to wrap my head around converting this code to work with the FV-1 Anyone willing to help push me in the right direction?

% Random LFO Generator
% creates a random sinusoidal waveform with no discontinuities
% rate = average rate in Hz
% N = run length in samples
% Fs = sample frequency in Hz
function y = random_lfo(rate, N, Fs)

step_freq_scale = Fs / (1*rate);
min_Cn = 0.1 * step_freq_scale;
An = 0;
lastA = 0;
Astep = 0;
y = zeros(1,N); % output
x = 0; % sine phase
lastSign = 0;
amp_scale = 0.6;
new_amp_scale = 0.6;
amp_scale_ramp = exp(1000/Fs)-1;
for (n=1:N)
if (An == 0) || (An>=Cn)
% generate a new random freq scale factor
Cn = floor(step_freq_scale * rand());
% limit to prevent rapid transitions
Cn = max(Cn, min_Cn);
% generate new value & step coefficient
newA = 0.1 + 0.9*rand();
Astep = (newA - lastA) / Cn;
A = lastA;
lastA = newA;
% reset counter
An = 0;
end
An = An + 1;
% generate output
y(n) = sin(x) * amp_scale;
% ramp amplitude
amp_scale = amp_scale + ( new_amp_scale - amp_scale ) * amp_scale_ramp;
sin_inc = 2*pi*rate*A/Fs;
A = A + Astep;
% increment phase
x = x + sin_inc;
if (x >= 2*pi)
x = x - 2*pi;
end
% scale at each zero crossing
if (sign(y(n)) ~= 0) && (sign(y(n)) ~= lastSign)
lastSign = sign(y(n));
new_amp_scale = 0.25 + 0.75*rand();
end;
end;


On another note... has anyone come up with any good Comb Filter algorithms?

Ok that is all... for now :)
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Post by frank »

Interesting little algo there, will take a look deeper into it later.

A comb filter is simply adding a delayed version of a signal to its self to create constructive and destructive interference, very simple program. So what do you mean by "good comb filter"?
Frank Thomson
Experimental Noize
AudibleObjects
Posts: 2
Joined: Fri Apr 15, 2011 10:14 am

Post by AudibleObjects »

Thanks for taking a look at the code.

The features I would love in a good comb filter would be cv control over delay time, resonance and volume. The delay time would be 2.0ms - 25ms.
Post Reply