Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Lin to freq

DSP related issues, mathematics, processing and techniques

Lin to freq

Postby Drnkhobo » Tue Jan 08, 2013 11:12 pm

Hey does anyone know how to convert linear (0-1) to frequency (hz) ?

I want to display a value in hertz for my filter. What i have been trying is connecting the output of the cutoff knob and do a calculation to convert, but it isnt very accurate.

Ive searched the old SM forums, but im still not getting it right.

I thought ,so if 0-1 is 0-22050hz (44100 SR) then just scale it (Thanks Trog and your scaling module!)

This doesnt work so great.

I also have tested in my DAW, loading up a synth patch and checking the freqs this way (via Ozone's spectrum)

How can I do this correctly??
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

Re: Lin to freq

Postby Nubeat7 » Tue Jan 08, 2013 11:33 pm

hmm there are 0..1 to hz modules in the toolbox, but like you said 0..1 * SR/2...
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Lin to freq

Postby Drnkhobo » Wed Jan 09, 2013 1:38 pm

Yeah the 0-1 to hz module has a poly out. . . I don't know how to convert it to green.

I've seen examples of EQ schematics and they seem to have this sort of calc:

Input (from knob) to the pow 2.5 x (SR/2)

Which works amazing for their Schematic but when I try to modify it to mine, it's off.

This should be easy right?

If the cutoff sends a value of 0..1 that represents the whole spectrum 0..22050hz
Then surely there is a formula to convert that to a viable freq value?

A simple scaler is not correct , I've tried and analysed it, it's wrong.
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

Re: Lin to freq

Postby Nubeat7 » Wed Jan 09, 2013 8:04 pm

hmm, so if i understood right, this should be the right thing, i took i out of a freq splitter, you can choose the frequency range in the properties..
Attachments
0..1ToLog.fsm
(583 Bytes) Downloaded 1486 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Lin to freq

Postby Drnkhobo » Wed Jan 09, 2013 8:23 pm

:lol:

One step ahead of you! I tried that today but its not 100% accurate,
its pretty close >1000hz but as you go below, it starts to get off. . .

Its better then my previous one though ;)

So he is doing a 10pow(value from knob). . . . hmmm

- Its definitely an exponential function
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

Re: Lin to freq

Postby trogluddite » Wed Jan 09, 2013 8:47 pm

Hi there,
I find the pitch to frequency primitive useful here.

The trouble with a 0..1 frequency input is the log scaling - whenever you connect up a knob, you only really get any control over the upper frequencies. It's easy to explain why...
1 = 22050 Hz
0.5 = 11025 Hz (one octave down)
So half of the knob is just that single top octave. To get 1000Hz, you need a 0...1 range value of just 0.04 - and because of the way the knobs are slightly quantized (due to the mouse only registering exact pixels of movement), there's no hope of getting any control over the bass at all.

So, Pitch -> Frequency then....
Normally used to take a MIDI pitch (linear), and turn it into a 0...1 frequency input. Using this you can get a nice even spread of frequencies, with the octaves linearly spread around the circumference of the knob. Just set your knob range to the note numbers of the min and max frequencies that you want (it's OK to go outside the normal 0-127 MIDI range).
This is also the key to making synths with filters that track the keyboard note - or nice even pitch bend and vibrato effects in your modulation matrix.

Regarding the accuracy. Well 0...1 * SR/2 is certainly the right equation, so I suppose the question is - how far out are the numbers that you're getting? With the exception of Ruby, all of FS's calculations are only single-precision (i.e. 32 bits), so possibly you are seeing the result of rounding/truncation in the maths?
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Lin to freq

Postby Drnkhobo » Wed Jan 09, 2013 8:49 pm

Trog to the rescue.....!!!! :lol:

Thanks brother, I sit staring at the screen till you pipe up! lol!
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

Re: Lin to freq

Postby Drnkhobo » Wed Jan 09, 2013 8:59 pm

So half of the knob is just that single top octave. To get 1000Hz, you need a 0...1 range value of just 0.04 - and because of the way the knobs are slightly quantized (due to the mouse only registering exact pixels of movement), there's no hope of getting any control over the bass at all.


You are right on it, the lower freqs just get tooo small,move the knob 1-click (shft-drag) from 0+ and there are huge jumps.

im using green so im thinking ruby time!

So, Pitch -> Frequency then....
Normally used to take a MIDI pitch (linear), and turn it into a 0...1 frequency input. Using this you can get a nice even spread of frequencies, with the octaves linearly spread around the circumference of the knob. Just set your knob range to the note numbers of the min and max frequencies that you want (it's OK to go outside the normal 0-127 MIDI range).


So you are saying, set my knobs min/max to the note numbers as in C0-C12?

So:

C0(16.35hz) ...C12(???) ???


Ive tried with these settings:

KNOB( min(12)...max(127) ) - - - - - *(SR/2)

I get a reading from 16hz-12 543hz

Still need to verify, but then I need my knob to output 0...1 for my filter-how do i link that?
Im confused Trog!



**EDIT

What i have done is send the output from my cutoff knob (0...1) to a float scaler and scaled it to:

min:12 (16hz)
max:136.766 (22050.5hz)

that is sent to a calc: out=in*(SR/2)

Then to my label.

Seems like its handling the lower freqs more accurately... im gonna test now
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

Re: Lin to freq

Postby Drnkhobo » Wed Jan 09, 2013 9:26 pm

Tests. . .

Filter used was a Biquad Notch
Real reading comes from Ozone



Filter readout: +-130hz
Real Reading: +-84hz


Filter readout: +-243hz
Real Reading: +-175hz


Filter readout: +-719hz
Real Reading: +-580hz


Filter readout: +-1936hz
Real Reading: +-1796hz


Filter readout: +-2777.6hz
Real Reading: +-2750hz
Drnkhobo
 
Posts: 312
Joined: Sun Aug 19, 2012 7:13 pm
Location: ZA

Re: Lin to freq

Postby trogluddite » Wed Jan 09, 2013 10:35 pm

Drnkhobo wrote:I need my knob to output 0...1 for my filter-how do i link that?

Just apply the previous equation in reverse to turn Hz into 0..1 - divide by half the sample rate.

Drnkhobo wrote:Filter used was a Biquad Notch
Real reading comes from Ozone

Wow, that's really off down low.
I would first try doing the same tests but with a basic sine oscillator - they're accurate enough for well pitched notes, and have always given me pretty reliable readings. I'm just wondering whether the error really comes from the control system.
Biquad filters have a habit of being a bit inaccurate at low frequencies, and depending on the filter design, it could be using approximations or look-up tables for some of the sine/cosine functions where the filter coefficients get calculated. I suspect that it might be a limitation of the filter rather than anything you've done wrong with your knob design that is the problem.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Next

Return to DSP

Who is online

Users browsing this forum: Majestic-12 [Bot] and 38 guests