electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Number of Bits Needed for Seamless Frequency Sweep?
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [17 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Thu Jan 15, 2015 12:13 pm    Post subject: Number of Bits Needed for Seamless Frequency Sweep? Reply with quote  Mark this post and the followings unread

hi

how many bits of frequency resolution are needed to achieve smooth, seamless digital FM?

I do not mean frequency modulation in the sense of "FM Synthesis". i just mean setting the frequency with a digital number.

thx!

Last edited by johnyradio on Thu Jan 15, 2015 5:13 pm; edited 2 times in total
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Thu Jan 15, 2015 2:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

An interesting question to which I don't have a good answer.

I've done a bit of work with FM in FPGAs and that is where I think an experiment is best performed because the number of bits doesn't depend so much on architecture. In a CPU, you are bound by words of 8, 16, 32 or even 64 bits. An FPGA on the other hand can be programmed to use any number you would want or need, such as 19 or 35.

In the FPGA FM synth I designed, "bits" varied depending on the function. Operator values mostly used 32 bits, but control of the operators went as low as 14 bits. I've used this synth with Lorenz attractor as a modulator. You can hear a drone produced by it here

The Lorenz part requires 64 bit arithmetic.

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Thu Jan 15, 2015 2:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

lovely drone!

i appreciate your specificity, but i would be fine with an answer restricted to standard word-sizes.

but, wondering if word-size needed varies, depending on octave and/or binary-to-frequency method (linear vs exponential).

Last edited by johnyradio on Thu Jan 15, 2015 3:07 pm; edited 2 times in total
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Thu Jan 15, 2015 3:06 pm    Post subject: Reply with quote  Mark this post and the followings unread

In my case, there was no need to change word size depending on pitch or any other parameter.

The drone synth is an 8 operator FM synth with a fixed algorithm of 4 mixed 2 operator FM generators (basically a bell synth).

I've done no FM work with anything but an FPGA, so I really can't speak to what I would do with standard word sizes. I will guess, however, that 32 bit arithmetic is sufficient. Something like a (fast) ARM (with NEON floating point proc) would work nicely in an FM application. It is a 32 bit CPU. In such a CPU, wherever 32 bits is not sufficient, one can always use 64 (or more), but with the standard caveat that extending word size will cost CPU clocks (a fact the is not necessarily present with FPGAs).

One thing to remember about FM is the unpredictability of harmonics generated. Care needs to be taken to avoid audible alias artifacts. As such, high sample rate is your best friend which is why I suggested a fast processor.

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Thu Jan 15, 2015 3:09 pm    Post subject: Reply with quote  Mark this post and the followings unread

appreciate your tip about sample rate, but i believe that's an unrelated issue to bit-size.

Also, your suggestion "if 32 bits isn't enough, try 64 bits" doesn't really get to the answer of the question.

14 bits is 16,384 steps. So a 14-bit linear converter applied to a full-range of 20 hz to 20 khz would give 1.2 hz per step:

(20,000 - 20) / 16,384 = ~1.2

That's approx 1 semitone in the lowest octave (NOT enough resolution for a seamless FM) vs approx 1/600th of a semitone in the highest octave (probably way more resolution than needed).

Suggesting that ANY digital frequency controller using a linear algorithm like this is doing it wrong.

i was not suggesting changing word-size depending on octave, but rather using an exponential algorithm.
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Thu Jan 15, 2015 3:25 pm    Post subject: Reply with quote  Mark this post and the followings unread

johnyradio wrote:
appreciate your tip about sample rate, but i believe that's an unrelated issue to bit-size.


Bit size is not the only issue over which one needs to make choices, hence I was trying to give a wider scope.

Quote:
Also, your suggestion "if 32 bits isn't enough, try 64 bits" doesn't really get to the answer of the question.

14 bits is 16,384 steps. So a 14-bit linear converter applied to a full-range of 20 hz to 20 khz would give 1.2 hz per step:

(20,000 - 20) / 16,384 = ~1.2

That's approx 1 semitone in the lowest octave (NOT enough resolution for a seamless FM) vs approx 1/600th of a semitone in the highest octave (probably way more resolution than needed).


I can't hear much above 14 kHz. As such, I'd not need an instrument that produces 20 kHz fundamentals. In fact, I limit the fundamentals to a much lower frequency than even 14 kHz.

The phase accumulators for the sine generators are 32 bits. I never said they were 14 bits, only that some control values were 14 bits (such as the modulation index). Before deciding on the bit width, the boundaries of the instrument need to be defined, what is the lowest fundamental you want to produce? What is the highest? And then work out the bit width from that. (That is what I did, but I no longer have the scratch paper where I worked that out).

Quote:
Suggesting that ANY digital frequency controller using a linear algorithm like this is doing it wrong.


That would be your opinion. As you can tell, the system works, so I strongly disagree that it is "wrong".

Quote:
i was not suggesting changing word-size depending on octave, but rather using an exponential algorithm.


Then you are way ahead of me. I'll be interested in seeing and hearing your design.

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Thu Jan 15, 2015 4:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

JovianPyx wrote:
I can't hear much above 14 kHz. As such, I'd not need an instrument that produces 20 kHz fundamentals. In fact, I limit the fundamentals to a much lower frequency than even 14 kHz.


that's just rough math. Let's call it 10 khz if you prefer. The Hz resolution needed at the top end is still going to be less than the resolution at the bottom end.

Quote:
The phase accumulators for the sine generators are 32 bits. I never said they were 14 bits


i never said you said they were 14 bits. i never said anything about your phase accumulators. I was using 14 bits as an arbitrary example.

anyway, thanks for mentioning the accumulators, that's a technique to talk about. As i understand, the phase accumulator holds the current address being sampled in your wavetable, correct? And the phase increment register (PIR) holds the constant which gets added to the phase accumulator for each sample-- the number in the PIR indicates your desired frequency. If it's 32 bits, then i think your 32 bit word-size will determine your FM resolution.

Re linearity: if your PIR contains the number 1, then you're reading every address in the wavetable, and therefor outputting the lowest possible frequency. For this example, let's say 20 Hz (but will of course depend on your clock rate and wavetable size.)

Ok, then you change your PIR to the number 2. Then you'll be reading every other address in the wavetable, and your output frequency will now be 20 hz X = 40 hz: one octave higher.

Obviously i'm missing something here. How do you get the in-between notes? Change your clock frequency?

Quote:
Before deciding on the bit width, the boundaries of the instrument need to be defined, what is the lowest fundamental you want to produce? What is the highest? And then work out the bit width from that.


do you remember your math? The math must make assumptions about minimum word-size needed per.... something.

Quote:
As you can tell, the system works


i can't tell, because your sound sample does not contain a simple frequency sweep. When i say FM here, i'm not specifically talking about "FM Synthesis". I mean the general sense of setting the frequency of an oscillator with a number.
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Thu Jan 15, 2015 6:19 pm    Post subject: Reply with quote  Mark this post and the followings unread

Quoting all that is too difficult.

Yes, the frequency resolution of the phase accumulators is 32 bits.

As for the sine table, it holds 4096 samples so it's address bus is only 12 bits. The upper 12 bits of the 32 bit phase accumulator select samples from the table while the lower 20 bits are used for interpolation. The phase accumulator is thus used as an unsigned fixed point binary number in 12.20 format. As such, a PIR value of 0x00000001 would be an extremely low frequency (probably one you would never actually use). In fact, to get each sample (per sample time) the PIR would need to be 0x00100000. Note that this is for my design, you might use a larger sine table or a smaller one, your choice there.

Do I remember my math? I don't understand why you ask that.

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Thu Jan 15, 2015 6:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

JovianPyx wrote:
a PIR value of 0x00000001 would be an extremely low frequency (probably one you would never actually use). In fact, to get each sample (per sample time) the PIR would need to be 0x00100000.


You mean your PIR never goes does into the low numbers?
What's the lowest you push it down to?
What's your sample clock rate?
What is the frequency range of your output frequency?

Quote:
Do I remember my math? I don't understand why you ask that.


Because the math must make assumptions about minimum word-size needed per.... something.

thx for info

Last edited by johnyradio on Thu Jan 15, 2015 6:51 pm; edited 1 time in total
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Thu Jan 15, 2015 6:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

johnyradio wrote:
JovianPyx wrote:
a PIR value of 0x00000001 would be an extremely low frequency (probably one you would never actually use). In fact, to get each sample (per sample time) the PIR would need to be 0x00100000.


You mean your PIR never goes does into the low numbers?
What's the lowest you push it down to?
What's your sample clock rate?
What is the frequency range of your output frequency?

Quote:
Do I remember my math? I don't understand why you ask that.


Because the math must make assumptions about minimum word-size needed per.... something.

thx for info


Yes, I know how to do math. As I said, I don't have the notes for all of the calculations I did. The math was used to calculate the values in the tuning table based on the sample rate and the size of the phase accumulator. That's easy stuff and it needs to be calculated for each specific application. The exact values I have for my system won't do you much good.

As for these questions:

Quote:
You mean your PIR never goes does into the low numbers?


Yes, it does. It can and does use values less than 1.00000 if that's what you mean.

Quote:
What's the lowest you push it down to?


The C that is around 32 hertz

Quote:
What's your sample clock rate?


65.1 kHz

Quote:
What is the frequency range of your output frequency?


64 semitones. I will go higher, but that's the limit I put on my system mainly to keep from creating alias artifact problems. I found the pitch range (5 octaves) is sufficient for my uses. YMMV.

Last edited by JovianPyx on Thu Jan 15, 2015 6:53 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Thu Jan 15, 2015 6:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

i'm sure you know how to do math, i'm not suggesting otherwise. will contemplate the numbers you shared.

i may be misunderstanding your PIR scheme, but i believe your architecture would produce a linear frequency-resolution response, so the human-perceived resolution gets better the higher the frequency.

Try this thought experiment:
- say you're reading every address. Your output frequency is X.
- Next, you read every OTHER address. Now your output frequency is 2X, an octave higher. Am i right?

So, that's obviously too coarse of resolution at the bottom-end to play semi-tones. The first jump is an octave. The next just (reading every 3rd address) will be a little less than an octave. The higher you go, the smaller the jumps-- eventually one jump will be a semitone. Eventually the jumps will get so small that it sounds like a smooth frequency sweep. If we could find out that frequency, it would be a clue to my OP. (clock-rate and wavetable-length also come into the equation).

In that scenario, the way to have smooth sweeps is to never play your oscillator too low.

But i may be misunderstanding your PIR scheme, so i need to think about it more.
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Thu Jan 15, 2015 6:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

johnyradio wrote:
i'm sure you know how to do math, i'm not suggesting otherwise. will contemplate the numbers you shared.

i may be misunderstanding your PIR scheme, but i believe your architecture would produce a linear frequency-resolution response, so the human-perceived resolution gets better the higher the frequency.

Try this thought experiment:
- say you're reading every address. Your output frequency is X.
- Next, you read every OTHER address. Now your output frequency is 2X, an octave higher. Am i right?


Yes.

Quote:
So, that's obviously too coarse of resolution at the bottom-end to play semi-tones. The first jump is an octave. The next just (reading every 3rd address) will be a little less than an octave. The higher you go, the smaller the jumps-- eventually one jump will be a semitone. Eventually the jumps will get so small that it sounds like a smooth frequency sweep. If we could find out that frequency, it would be a clue to my OP. (clock-rate and wavetable-length also come into the equation).


There is interpolation to consider. PIR values are 32 bits, not 12. So they also contain fraction information which is used by the interpolator.

Quote:
In that scenario, the way to have smooth sweeps is to never play your oscillator too low.

But i may be misunderstanding your PIR scheme, so i need to think about it more.


Interpolation. That is what keeps if from stepping at low frequencies. It also allows using phase increment values like 1.23728. I use a simple linear interpolator, but there are others that provide curved interpolation (at higher CPU cost).

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Fri Jan 16, 2015 11:40 pm    Post subject: Reply with quote  Mark this post and the followings unread

Right! Interpolation! Thanks for reminding me of that. You can read every 1.5 addresses, meaning skip 2, then skip 3 twice, then skip 2, then skip 3 twice, etc. (Pseudo?) floating-point and your 32-bit accumulators make that possible.

Which means there's a slight amount of sine distortion, due to irregular addressing. Whether that's audible would, i think, be a factor of both sample rate and wavetable-length.

I'm thinking that, to get 1 semitone up from the lowest octave, you're doing something like, toggling between reading the entire wavetable and reading the entire wavetable less 1 address. Or even, reading the entire wavetable 19 times, and then reading the entire wavetable less 1 address, one time.

i wonder what kind of distortion that causes.
Back to top
View user's profile Send private message
Larva



Joined: Mar 30, 2011
Posts: 6
Location: The Soil

PostPosted: Sat Jan 17, 2015 3:34 am    Post subject: Reply with quote  Mark this post and the followings unread

Interpolation is not a system like skip 2 then skip 3 then skip 2 etc. That describes a variable sample rate which is not desirable in most digital synth applications.

Interpolation is a method that "guesses" what a value ought to be that lies literally between two adjacent known sample points. The word comes from two parts "inter" and "pole" where "pole" means point and "inter" means between.

Let's say you need the "virtual sample" at time position 6.42. It's between known samples at time 6.0 and time 7.0, so you need to get the values for those samples. The unknown sample is 0.42 sample times after time 6.0 and 0.58 before time 7.0. The 0.42 value is kind of like a slider in time and is computed simply as the fraction part of the number that is selecting the virtual sample.

interp = slider * sampleB + (1.0-slider) * sampleA

sampleA and sampleB are the amplitude values (not the time) of the two samples used for interpolation.

This is called linear interpolation because all of the virtual samples available lie on a straight line segment drawn between sampleA and sampleB. This turns a sine table into a set of points with line segments drawn between them. This does cause a small amount of distortion, but if the sine table has enough points, the distortion is insignificant.

There are also other types of interpolation that attempt to draw a curve between the two real points, however, these "higher order" interpolation methods are more CPU expensive.
Back to top
View user's profile Send private message
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Sat Jan 17, 2015 10:24 am    Post subject: Reply with quote  Mark this post and the followings unread

@JovianPyx, correct me if i'm wrong:

pitch of the sinewave is determined by how many addresses are skipped between each read.

getting higher pitches is achieved by skipping more addresses.

lower pitches are achieved by skipping fewer addresses.

Does your DDS system interpolate non-existent addresses in-between the existing addresses?

correct?
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1288
Location: West Red Spot, Jupiter
Audio files: 163

PostPosted: Wed Jan 21, 2015 7:34 am    Post subject: Reply with quote  Mark this post and the followings unread

johnyradio wrote:
@JovianPyx, correct me if i'm wrong:

pitch of the sinewave is determined by how many addresses are skipped between each read.

getting higher pitches is achieved by skipping more addresses.

lower pitches are achieved by skipping fewer addresses.

Does your DDS system interpolate non-existent addresses in-between the existing addresses?

correct?


Yes. The idea of interpolation is to create samples that don't exist between the real samples. Note also that the phase increment can be less than 1.00000 such as 0.25921. In that case, you don't "skip" any samples, you might interpolate between the same two real samples several times before moving on to the next set.

I would strongly suggest going to www.dspguide.com and reading the information there about sampling theory. It is well written and completely free.

_________________
FPGA, dsPIC and Fatman Synth Stuff

Time flies like a banana.
Fruit flies when you're having fun.
BTW, Do these genes make my ass look fat?
corruptio optimi pessima
Back to top
View user's profile Send private message Visit poster's website
johnyradio



Joined: Mar 13, 2014
Posts: 17
Location: San Francisco

PostPosted: Wed Jan 21, 2015 8:20 am    Post subject: Reply with quote  Mark this post and the followings unread

thx!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [17 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use