I need to reproduce a certain sound wave form, specifically, the sound

of a heartbeat, and I need to do it with only a few dozen bytes of ram,

on a PIC MCU. The sample itself is 250ms long, and I have it in

uncompressed audio format at 11khz, 8 bits, mono. Is there a way to

create a mathematical algorithm to generate the sound on the PIC?

Otherwise I would need 344 bytes of ram, and thats more than the PIC

has total not including the ram needed for code and all the other stuff

I am doing on it. The heartbeat must be exacly reproduced, so I cant

just generate an approximation.

First, to get the principles out of the way, you have an approximation

with your recording. It may be a good approximation, but it's still

only an approximation. Your decision is going to be how good must your

new approximation be, and what are the real criteria for deciding what

your approximation should look like?

Second, where do you get the 344 bytes number? 11KHz * .25 second =

2750 samples, which sounds very much like 2750 bytes. And, since the

typical heartbeat period is around 850ms, what do you really have? Only

the most obvious pulse, with none of the little stuff that goes on

between big pulses, or not even all of the main pulse?

Now, you have to decide what kind of accuracy you need in your

approximation. You already have a rather coarse 8 bits in your sample,

so experimenting with various piecewise leastsquares curve fits may give

an approximation as good as what you have, and save you some RAM at the

expense of some processing time. Or, a simple linear interpolation

between pairs of points at times selected to minimize slope errors --

assuming that's even important.

Next, if you have it pre-recorded, why not use a much better processor

than the PIC? For what you want to do I don't know of any processor

worse designed than the PIC (at least the 16... series, which are all

I've used). Use a decent processor and you can copy your entire sample

set out from flash at 11KHz.

John Perry

PS -- The PIC16 is atrocious for this kind of job, but it works OK for

other kinds of applications. Don't read more into my comment than I say.