[sdiy] DSP books [was: Re: OBJECT ORIENTED C in synth programming]

Noah Vawter nvawter at media.mit.edu
Sun Apr 10 03:33:55 CEST 2011


It should be......  but let's try an example below...

p.s. believe it or not you can use goto's in C.  In pro dev, it's  
considered bad form, but if you're just learning, it's fine.

Q: the arrow symbols?  Hmmm.  I don't remember them in Basic, and I  
don't have hal chamberlin's books and can't find one free online....
if you have an example, I'd be happy to take a look at it...

Now, let's take the an example from http://www.dspguide.com/ch8/6.htm  
the basic DFT function:
I would translate this into the following:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

float xx[511];

// btw this function isn't actually in the dspguide example, I created  
it myself.
void fillData(void)
{
	int i;
	for(i=0;i<511;i++)
	{
                 // this should make a sinusoid with added noise.   25  
means the 25th harmonic.
		xx[i] = 100*sin((float)i*3.14159/511.0*25.0) + random()%10;
	}
}

// example code starts for real here
int main(int argc, char*argv[])
{
	int i,k;   // note, in C you have to declare every variable.  in  
BASIC, they're already there

	float rex[256];    // this si the equiv of dim[] in basic
	float imx[256];

	float pi=3.11459;	   // note you have to tell C if the variable is  
going to hold floating point numbers or ints
	float n=512;

	fillData();    // instead of saying GOSUB in BASIC, you "call" the  
"function"

         // clear accumulators
	for(k=0;k<=256;k++)   // loop structure is similar in basic, just  
watch the boundaries carefully
	{
		rex[k] = 0;    // note you didn't need those icky % signs as in  
basic.  not every basic needs them either fwiw
		imx[k] = 0;
	}

         // compute the DFT, the slow, but understandable way (vs. FFT)
	for(k=0;k<256;k++)
	{
		for(i=0;i<511;i++)
		{
			rex[k] = rex[k] + xx[i] * cos(2.0*pi*(float)k*(float)i/n);
			imx[k] = imx[k] - xx[i] * sin(2.0*pi*(float)k*(float)i/n);
		}
	}

         // print the results
         for(k=0;k<256;k++)
         {
                float mag = sqrt(rex[k]*rex[k] + imx[k]*imx[k]);
                printf("%.1f %.1f %.1f\n",rex[k],imx[k], mag);
         }

}
I hope that gives you enough hints to get going...  ask here if you  
have Qs, this list seems to have enough am/experts we can get you going.


P.S. If you don't have a C compiler handy, let me introduce you to  
this AWESOME resource, http://codepad.org

all you have to do is go to http://codepad.org/mNouQeR4

and you'll find that program cut and pasted.  Also, codepad.org LET'S  
YOU RUN THE PROGRAM ON THEIR SERVER.

yes!  And it's even secure, you can't crash their servers with evil  
code.



-Noah


On Apr 9, 2011, at 8:39 PM, Dan Snazelle wrote:

> Is it pretty easy to convert basic programs to C???
>
> When i looked at hal chamberlins basic examples, 2 things popped  
> out....lots of goto's and weird arrow symbols in the code. Not sure  
> what the arrows are for
>
>
>
> Thanks for the book ideas too!!!
>
> Sent from my iPhone
>
> On Apr 9, 2011, at 8:22 PM, Noah Vawter <nvawter at media.mit.edu> wrote:
>
>>
>> oh gosh yes I wish there was, too.  A great many of us I have  
>> discovered, learn best with actual arithmetic/numerical examples.   
>> Don't ask me why, but I suppose us types have an intuitive, yet  
>> limited understand of numbers.  The same seems true of me and  
>> analog electronics.  anyway, that reminds me of a 2nd book I like.   
>> It's free online:  http://www.dspguide.com/pdfbook.htm
>>
>> cool thing about that one, besides free, is that it has many  
>> examples written in basic!  so you can try them in your favorite  
>> language (or basic) and see the numbers yourself and learn that  
>> way.  it is also very thorough and has helped me with a great  
>> number of lessons.
>>
>> Oh yeah, the closest I have seen to a cookbook is RBJ's famous  
>> biquad cookbook:  http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
>> It tells exactly in cookbook fashion how to make LPF, BPF, HPF, and  
>> several other filters!  I have used this many times!
>>
>>
>> On Apr 9, 2011, at 7:07 PM, Dan Snazelle wrote:
>>
>>> My big fear of dsp is high level math
>>>
>>> Maybe there is a "cookbook" for dsp?
>>>
>>> Sent from my iPhone
>>>
>>> On Apr 9, 2011, at 1:55 PM, Noah Vawter <nvawter at media.mit.edu>  
>>> wrote:
>>>
>>>>
>>>> On Apr 9, 2011, at 3:01 AM, <lanterma at ece.gatech.edu> wrote:
>>>>
>>>>> On Apr 8, 2011, at 10:46 PM, Jay Schwichtenberg wrote:
>>>>>
>>>>>> Interfacing with C - Howard Hutchings - Butterworth Heinemann
>>>>>> A Digital Signal Processing Primer with Applications to Digial  
>>>>>> Audio and
>>>>>> Computer Music - Ken Steiglitz - Addison-Wesley
>>>>>
>>>>> Let me also toss in "Signal Processing First," by Schafer,  
>>>>> McClellan, and Yoder. We use it in the "ECE2025: Introduction to  
>>>>> Signal Processing" class that I've taught a lot (and am  
>>>>> incidentally teaching again this summer).
>>>>
>>>> I'm a fan of Rick Lyon's book:
>>>> http://www.amazon.com/Understanding-Digital-Signal-Processing-2nd/dp/0131089897
>>>>
>>>> although I have to remind that no single book has ever been able  
>>>> to teach me everything about DSP.  It's a pretty diverse topic,  
>>>> but Lyon's book is written in clear English with a smaller number  
>>>> of topics explained most thoroughly, like a set of college  
>>>> lectures.
>>>>
>>>>
>>>> _______________________________________________
>>>> Synth-diy mailing list
>>>> Synth-diy at dropmix.xs4all.nl
>>>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>>>>
>>>
>>
>>
>




More information about the Synth-diy mailing list