[Csnd] Band-limited Waveforms
Date | 2012-11-02 22:10 |
From | Christopher Saunders |
Subject | [Csnd] Band-limited Waveforms |
I have a couple questions about generating band-limited waveforms - 1. Am I correct in the following? - I want to build an oscillator that, for a given fundamental, generates a sawtooth(or square or triangle) waveform containing all the partials up to the Nyquist frequency. An ideally rich, non-aliased spectra for every pitch. Ex. Given a fundamental of 261.626 Hz (Middle C), the oscillator will generate a sawtooth at that pitch with 76 harmonics. (I haven't had my calculations verified) I plotted points on a graph and came up with the equation - y = 1/(0.00005x) or Num_of_harmonics_before_nyquist = 1/ (0.00005 * fundamental_Hz) I've implemented this - and it sounds right to my ears- even with high register fundamentals, but is this the mathematical ideal I'm looking for? 2. Have I overlooked an opcode or UDO in Csound that does this? something like ares bandoscil xamp, xcps, iwaveform 3. What kind of resources out there for dynamically generating band-limited waveforms ? 4. Is there a better way to do subtractive synthesis in Csound? Christopher Saunders B.A. North Carolina State University 2009 B.M. Berklee College of Music 2011 topher@tophersaunders.com www.tophersaunders.com |
Date | 2012-11-02 22:53 |
From | zappfinger |
Subject | [Csnd] Re: Band-limited Waveforms |
Hi Christopher, The VCO opcode can generate band limited signals. (saw, square, triangle) Richard -- View this message in context: http://csound.1045644.n5.nabble.com/Band-limited-Waveforms-tp5717626p5717627.html Sent from the Csound - General mailing list archive at Nabble.com. |
Date | 2012-11-03 01:40 |
From | Adam Puckett |
Subject | Re: [Csnd] Re: Band-limited Waveforms |
Or try gbuzz. That also kinda sounds like subtractive synthesis if you sweep kmult and knh. (I think those are the parameter names). On 11/2/12, zappfinger |
Date | 2012-11-03 09:19 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Csnd] Band-limited Waveforms |
The maths is wrong; if freq f and nyquist frequency F, we want the integer part of f*2^n = F so n = log2(F/f) and you need int(log2(F/f) assuming i am sufficiently awake to get it right...... ==John ff > I plotted points on a graph and came up with the equation - > > y = 1/(0.00005x) > > or > > Num_of_harmonics_before_nyquist = 1/ (0.00005 * fundamental_Hz) > |
Date | 2012-11-03 18:36 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 3, 2012, at 11:19 , jpff@cs.bath.ac.uk wrote: > The maths is wrong; if freq f and nyquist frequency F, we want the integer > part of > f*2^n = F > > so n = log2(F/f) and you need int(log2(F/f) > > assuming i am sufficiently awake to get it right...... Your math isn't right either. You are counting how many times the frequency can be doubled before it reaches the Nyquist frequency... The number of harmonics, what Christopher asked for, is easily obtained as: F/f where F is the Nyquist frequency (sr/2) and f is the fundamental frequency. Couple of existing opcode alternatives were given earlier in this thread. But if you really want to play with bandlimited oscillator algorithms (I think that's what you were asking with your question about 'dynamic generation'), there are several alternatives that are quite easy to implement with Csound. You should note that many of those algorithms aren't ideally bandlimited, that is, have no aliasing distortion at all. Those algorithms take advantage of psychoacoustics by removing/reducing aliasing distortion where it is more easily audible. Cheers, Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-03 21:59 |
From | Christopher Saunders |
Subject | Re: [Csnd] Band-limited Waveforms |
Thanks for correcting my math! My problem was that I was comparing the highest harmonic against the wrong value for (sr/2)...D'oh! > The number of harmonics, what Christopher asked for, is easily obtained as: > > F/f > > where F is the Nyquist frequency (sr/2) and f is the fundamental frequency. I've verified this equation using num_harmonics = (sr/2)/ Hz_fundamental Hz_of_highest_harmonic = Hz_fundamental + Hz_fundamental*(num_harmonics) and I get a Hz_of_highest_harmonic < (sr/2) every time However, when cast to an (int)... num_harmonics = (sr/2)/ Hz_fundamental Hz_of_highest_harmonic = Hz_fundamental + Hz_fundamental*(int(num_harmonics)) ... Hz_of_highest_harmonic is often off by +1/-1. is there a way to round to the nearest whole number? > > Couple of existing opcode alternatives were given earlier in this thread. But if you really want to play with bandlimited oscillator algorithms (I think that's what you were asking with your question about 'dynamic generation'), there are several alternatives that are quite easy to implement with Csound. You should note that many of those algorithms aren't ideally bandlimited, that is, have no aliasing distortion at all. Those algorithms take advantage of psychoacoustics by removing/reducing aliasing distortion where it is more easily audible. Anywhere online or in print where I can study these algorithms? Re: VCO opcode do the waveforms generated by vco contain harmonics up to the Nyquist for every fundamental or are they static tables? Christopher Saunders B.A. North Carolina State University 2009 B.M. Berklee College of Music 2011 topher@tophersaunders.com www.tophersaunders.com |
Date | 2012-11-03 22:14 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 3, 2012, at 23:59 , Christopher Saunders wrote: > I've verified this equation using > > num_harmonics = (sr/2)/ Hz_fundamental > > Hz_of_highest_harmonic = Hz_fundamental + Hz_fundamental*(num_harmonics) > > and I get a Hz_of_highest_harmonic < (sr/2) every time > > > > However, when cast to an (int)... > > num_harmonics = (sr/2)/ Hz_fundamental > > Hz_of_highest_harmonic = Hz_fundamental + Hz_fundamental*(int(num_harmonics)) > > > ... Hz_of_highest_harmonic is often off by +1/-1. > > is there a way to round to the nearest whole number? Actually the frequency of the highest harmonic should be int(num_harmonics)*Hz_fundamental. Maybe that causes that offset? On Nov 3, 2012, at 23:59 , Christopher Saunders wrote: > Anywhere online or in print where I can study these algorithms? Mostly in print. I collected a list of all publications dealing with this topic to a website last year: http://www.acoustics.hut.fi/~jpekonen/Papers/fa2011/ That list haven't been updated since I left Aalto University. There are several papers that have been published this year that are obviously missing from that list. On Nov 3, 2012, at 23:59 , Christopher Saunders wrote: > Re: VCO opcode > > do the waveforms generated by vco contain harmonics up to the Nyquist for every fundamental or are they static tables? Maybe someone who is more familiar with the VCO opcode could answer this? zappfinger? Cheers, Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-03 22:18 |
From | Justin Smith |
Subject | Re: [Csnd] Band-limited Waveforms |
On Sat, Nov 3, 2012 at 3:14 PM, Jussi Pekonen <jussi.pekonen@gmail.com> wrote:
no, because with 0 harmonics you still have a sine wave at the base frequency, with 1 harmonic you have that plus another an octave higher, with 2 harmonics you have fundamental+octave+~fifth, etc.
|
Date | 2012-11-03 22:30 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 4, 2012, at 00:18 , Justin Smith wrote: > no, because with 0 harmonics you still have a sine wave at the base frequency, with 1 harmonic you have that plus another an octave higher, with 2 harmonics you have fundamental+octave+~fifth, etc. Ha! But what is the definition of a harmonic? Some define the fundamental (base) frequency as the first harmonic. Why? Nth harmonic -> frequency is N times the fundamental frequency. I use this definition. Nevertheless, my calculations are still correct: num_harmonics_below_Nyquist = (sr/2)/Hz_fundamental => Hz_of_highest_harmonic = int(num_harmonics_below_Nyquist)*Hz_fundamental Think about case a where sr = 44100 Hz and Hz_fundamental = 882 Hz: => num_harmonics_below_Nyquist = (sr/2)/Hz_fundamental = 25 => Hz_of_highest_harmonic = int(num_harmonics_below_Nyquist)*Hz_fundamental = 22050 (= sr/2) Another case with Hz_fundamental = 880 Hz: => num_harmonics_below_Nyquist = (sr/2)/Hz_fundamental = 25.05 => Hz_of_highest_harmonic = int(num_harmonics_below_Nyquist)*Hz_fundamental = 22000 => Hz_fundamental + int(num_harmonics_below_Nyquist)*Hz_fundamental = 22880 So the last one is above the Nyquist frequency, hence it will alias (though you most probably won't hear it) Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-03 22:38 |
From | joachim heintz |
Subject | Re: [Csnd] Band-limited Waveforms |
not sure if this is what you require, but i have written an UDO for generating a function table for the standard waveforms by adding harmonics: http://www.csounds.com/udo/displayOpcode.php?opcode_id=100 joachim Am 02.11.2012 23:10, schrieb Christopher Saunders: > 2. Have I overlooked an opcode or UDO in Csound that does this? something like > > ares bandoscil xamp, xcps, iwaveform |
Date | 2012-11-03 22:44 |
From | Justin Smith |
Subject | Re: [Csnd] Band-limited Waveforms |
On Sat, Nov 3, 2012 at 3:30 PM, Jussi Pekonen <jussi.pekonen@gmail.com> wrote:
That is not a standard or even common definition for harmonic. Furthermore it is not even useful. Given the fact that most sounds in nature don't even have a harmonic series (because they don't have a one dimensional limitation to their vibration, unlike a string or tube), calling the lowest present frequency a harmonic is absurd. Harmonics are defined by relation to another frequency, so you cannot call a frequency a harmonic of itself.
Nevertheless, my calculations are still correct: whether you hear it is entirely dependent on its amplitude, but its presence will make little change in the resulting sound since it will produce a 880hz waveform which is the same as the fundamental anyway. But if you had started with a slightly lower or higher pitch you could easily have produced a discord, which would be readily apparent even for a very low amplitude.
|
Date | 2012-11-03 22:50 |
From | Justin Smith |
Subject | Re: [Csnd] Band-limited Waveforms |
On Sat, Nov 3, 2012 at 3:44 PM, Justin Smith <noisesmith@gmail.com> wrote:
Have to correct myself here, I misread, the resulting frequency for the nyquist foldover will be 830, which will be just below a g# (where the 880 is the a above that), which will produce a noticeable dissonance if the harmonic is at an amplitude above the threshold of hearing.
|
Date | 2012-11-03 22:55 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 4, 2012, at 00:44 , Justin Smith wrote: > That is not a standard or even common definition for harmonic. Furthermore it is not even useful. Given the fact that most sounds in nature don't even have a harmonic series (because they don't have a one dimensional limitation to their vibration, unlike a string or tube), calling the lowest present frequency a harmonic is absurd. Harmonics are defined by relation to another frequency, so you cannot call a frequency a harmonic of itself. In music, yes, that definition I gave is not standard nor common. But in engineering, where my background is, this definition is widely used. I would say that both of these should be kept in mind. Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-03 23:00 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 4, 2012, at 00:50 , Justin Smith wrote: > Have to correct myself here, I misread, the resulting frequency for the nyquist foldover will be 830, which will be just below a g# (where the 880 is the a above that), which will produce a noticeable dissonance if the harmonic is at an amplitude above the threshold of hearing. Umm, no. That harmonic folds back to frequency 22050 - 830 = 21220 Hz. I doubt that you will hear that component, unless it has a huge amplitude. In that case you most probably feel it, not hear it. Remember that the Nyquist foldover mirrors the frequencies with respect to the Nyquist frequency. Then, if the folded frequency gets below 0 Hz, it gets mirrored again with respect to DC. And the process continues and continues and continues... Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-03 23:01 |
From | Richard Dobson |
Subject | Re: [Csnd] Band-limited Waveforms |
On 03/11/2012 22:30, Jussi Pekonen wrote: > > On Nov 4, 2012, at 00:18 , Justin Smith wrote: > >> no, because with 0 harmonics you still have a sine wave at the base >> frequency, with 1 harmonic you have that plus another an octave >> higher, with 2 harmonics you have fundamental+octave+~fifth, etc. > > Ha! But what is the definition of a harmonic? Some define the > fundamental (base) frequency as the first harmonic. Why? Nth harmonic > -> frequency is N times the fundamental frequency. I use this > definition. > A harmonic is a "mode of vibration" - most simply understood with respect to a stretched string. The fundamental is the first (lowest available) mode of vibration, so is also called the first harmonic. Beyond that, the underlying assumption is the arithmetical one, that to be a harmonic the frequency has to be an integer multiple of the fundamental, Otherwise it is merely an inharmonic "partial" or "component". Richard Dobson |
Date | 2012-11-03 23:03 |
From | Justin Smith |
Subject | Re: [Csnd] Band-limited Waveforms |
the mirroring happens as a modulo, 22051 will produce 1 hz - it is very easy to demonstrate on graph paper if you take the time (and yeah, you were right about counting harmonics) On Sat, Nov 3, 2012 at 4:00 PM, Jussi Pekonen <jussi.pekonen@gmail.com> wrote:
|
Date | 2012-11-03 23:10 |
From | Justin Smith |
Subject | Re: [Csnd] Band-limited Waveforms |
and I was wrong again, it is a mirroring not modulo, I will have to bow out of this discussion and re-evaluate what I actually know about this stuff On Sat, Nov 3, 2012 at 4:03 PM, Justin Smith <noisesmith@gmail.com> wrote: the mirroring happens as a modulo, 22051 will produce 1 hz - it is very easy to demonstrate on graph paper if you take the time |
Date | 2012-11-03 23:13 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 4, 2012, at 01:10 , Justin Smith wrote: > and I was wrong again, it is a mirroring not modulo, I will have to bow out of this discussion and re-evaluate what I actually know about this stuff No worries. :) I just happen to know about aliasing quite much, as you may see from the list of publications I gave a few emails back. Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-03 23:18 |
From | Richard Dobson |
Subject | Re: [Csnd] Band-limited Waveforms |
This is a case where divorcing the term from its origin in real physical systems can cause problems. The starting point is an oscillatory system (simple "harmonic motion", the canonical example of which is the pendulum), and the reference point is the period or wavelength of that physical system. Yes, a number cannot be meaningfully said to be relative to itself, but a mode of vibration can be said to be not so much relative to as ~determined by~ the fundamental period of the system, a period with exists by definition. Of course, if the pendulum is stationary, there is no vibration at all, so has a frequency of zero, and is then identical to all other stationary pendulums. But that pendulum still has a length, and thus has a potential fundamental mode of vibration. Extending this to the stretched string model, multiple nodes and antinodes are possible via integer divisions of the string. There will always be at least two nodes - the fixed ends of the string. The first harmonic (aka fundamental) corresponds to the mode of vibration having just one antinode. It is one of those many many accidents or conveniences of language that one word can be used variously as a noun ("the harmonic") and as an adjective "is harmonic to". The first is absolute, the second is relative. Richard Dobson On 03/11/2012 22:55, Jussi Pekonen wrote: > > On Nov 4, 2012, at 00:44 , Justin Smith wrote: > >> That is not a standard or even common definition for harmonic. >> Furthermore it is not even useful. Given the fact that most sounds >> in nature don't even have a harmonic series (because they don't >> have a one dimensional limitation to their vibration, unlike a >> string or tube), calling the lowest present frequency a harmonic is >> absurd. Harmonics are defined by relation to another frequency, so >> you cannot call a frequency a harmonic of itself. > > In music, yes, that definition I gave is not standard nor common. But > in engineering, where my background is, this definition is widely > used. I would say that both of these should be kept in mind. > |
Date | 2012-11-03 23:35 |
From | Jussi Pekonen |
Subject | Re: [Csnd] Band-limited Waveforms |
On Nov 4, 2012, at 01:18 , Richard Dobson wrote: > This is a case where divorcing the term from its origin in real physical systems can cause problems. The starting point is an oscillatory system (simple "harmonic motion", the canonical example of which is the pendulum), and the reference point is the period or wavelength of that physical system. Yes, a number cannot be meaningfully said to be relative to itself, but a mode of vibration can be said to be not so much relative to as ~determined by~ the fundamental period of the system, a period with exists by definition. Of course, if the pendulum is stationary, there is no vibration at all, so has a frequency of zero, and is then identical to all other stationary pendulums. But that pendulum still has a length, and thus has a potential fundamental mode of vibration. > > Extending this to the stretched string model, multiple nodes and antinodes are possible via integer divisions of the string. There will always be at least two nodes - the fixed ends of the string. The first harmonic (aka fundamental) corresponds to the mode of vibration having just one antinode. > > It is one of those many many accidents or conveniences of language that one word can be used variously as a noun ("the harmonic") and as an adjective "is harmonic to". The first is absolute, the second is relative. I think you Richard nailed it. Thanks! Jussi Pekonen Jussi.Pekonen@gmail.com |
Date | 2012-11-13 20:22 |
From | Robert or Gretchen Foose |
Subject | Re: Re: [Csnd] Band-limited Waveforms |
I seem to recall from (very) long ago, my acoustics professor emphasizing the difference between 'partials' which are numbered from zero, and 'harmonics', which are integer multiples of a 'fundamental' (which is the 'zero' partial). His point was that many people use the the term harmonic when they mean partial, leading to all sorts of confusion, eg. there is no 'zero harmonic'. Not sure if that's part of what's happening here, but thought I'd point it out just in case. Bob On 13:59, Richard Dobson wrote: > On 03/11/2012 22:30, Jussi Pekonen wrote: >> >> On Nov 4, 2012, at 00:18 , Justin Smith wrote: >> >>> no, because with 0 harmonics you still have a sine wave at >>> the base >>> frequency, with 1 harmonic you have that plus another an octave >>> higher, with 2 harmonics you have fundamental+octave+~fifth, >>> etc. >> >> Ha! But what is the definition of a harmonic? Some define the >> fundamental (base) frequency as the first harmonic. Why? Nth >> harmonic >> -> frequency is N times the fundamental frequency. I use this >> definition. >> > > > A harmonic is a "mode of vibration" - most simply understood > with respect to a stretched string. The fundamental is the first > (lowest available) mode of vibration, so is also called the > first harmonic. Beyond that, the underlying assumption is the > arithmetical one, that to be a harmonic the frequency has to be > an integer multiple of the fundamental, Otherwise it is merely > an inharmonic "partial" or "component". > > Richard Dobson > |