# How can i implement Chirp Signal using C? [closed]

I would like to implement Chirp signal using C code

Do you have any idea how can I do it?

Edit

Goal is to send this signal to an DAC Component (µC intern or external peripheral). But I need fast sample rate like 10 Msamples or 20 Msamples. FPGA is not provided, any other µC is possible

• C code can't really be made to chirp on its own, perhaps you could show what you have already tried. – Erik Friesen Jan 30 '15 at 14:41
• First figure out if you are feeding samples into a DAC or (as is more typical on the small platforms you tagged) dividing down your clock to make a square wave. Then decide if you can afford trig and floating point, or if you need to use lookup tables and integer math. – Chris Stratton Jan 30 '15 at 14:47

This reference has a simple Chirp function. Call it with the parameters and the time and it returns the signal value at that time. The w1, w2 are angular frequencies, so $2\pi f_1$, $2\pi f_2$, M is the chirp duration, A is the peak amplitude.

double Chirp(double w1, double w2, double A, double M, double time)
{
double res;
res=A*cos(w1*time+(w2-w1)*time*time/(2*M));
return res;
}


Edit: With 10-20MSps you'll likely be looking at dedicated hardware such as a DDS that supports a chirp function and has internal trig tables. You may be able to find a processor with a DMA function that would allow a pre-calculated table to be output to a DAC, but that would be a peripheral function.

• My assumption is the OP wants to us an 8-bit micro for this, and this function would take a disgusting amount of time to run on that platform. – Matt Young Jan 30 '15 at 14:46
• @MattYoung Well, there's nothing to indicate that. These days it could as easily be an ARM platform with single-precision floating point FPU built in. The above function can, of course, be used to precalculate a table and then the 8 bit (or 4 bit) micro could just index into the LUT. We use CORDIC HDL algorithms to generate this kind of stuff in real time inside FPGAs. – Spehro Pefhany Jan 30 '15 at 14:50
• It's tagged PIC and AVR and neither of those are ARM cores with built in FPU. – Matt Young Jan 30 '15 at 14:51
• i have edited the post. please review and waiting for your kindly anwers – user3213767 Jan 30 '15 at 15:28
• Alright, 10-20 MSps definitely puts 8-bit parts out of the equation. – Matt Young Jan 30 '15 at 15:56

Make your external peripheral a DDS (direct digital synthesis) chip. This sort of thing is well within the capabilities of even a relatively low-end chip such as the Analog Devices AD5930.

I think the way to go would be to generate a look up table of full-integer-scale of one cycle of a sine wave at your lowest frequency, and then modulo-index into it with increasing step sizes, possibly doing linear interpolations between two points if using the nearest point is too rough.

Lastly, depending on the relationship between your output rate and your highest wave frequency, you might consider sending this out via low-pass-filtered high res PWM as opposed to a DAC. It might be a lot faster.

• Since a full sine cycle has 4-way symmetry, you only need to store 1/4 cycle. I go into more detail on that at electronics.stackexchange.com/a/16516/4512. – Olin Lathrop Jan 30 '15 at 16:44
• Good point,@OlinLathrop, and the original post is a nice resource. – Scott Seidman Jan 30 '15 at 16:45