Run FFT of self produced signal.


I am doing a project where I use a STM32F103RB, with the Arduino IDE, and I have a triangular signal coming out of the MCP4725 DAC. The signal goes into a radar module, and the received signal is then going to be analyzed by FFT on the board.

I have code working for the DAC and FFT working on their own, but I am wondering how this could be merged into a single code (the microcontroller producing and doing the FFT of the produced signal at the "same" time).

Could I use millis() somehow? Do it in sequence?

Best regards,

Your code will be generating samples to put into the DAC. So instead of putting them there you should put them into the FFT’s input buffer instead.

Thank you for answering. Could you elaborate a bit further? Not sure if I follow.

Could you elaborate a bit further?

Sorry I don’t know what to say other than what I have said.

Maybe if you describe what you don’t understand exactly I could explain that bit to you.

If you don’t understand the concept then sorry this project is outside your current skill level.

A block diagram of your proposed system, an outline of it's operation, and identification of the particular radar module to be used might clarify what it is you're trying to accomplish.

Here is an example of generating a test signal, then running an FFT:

  example sketch for testing the fft library.
  This generates a simple sine wave data set consisting
  of two frequences f1 and f2, transforms it, calculates
  and prints the amplitude of the transform.

// do #defines BEFORE #includes
#define LIN_OUT 1 // use the lin output function
#define FFT_N 64 // set to 64 point fft

#include <FFT.h> // include the library

void setup() {
  Serial.begin(9600); // output on the serial port
  int i, k;
  float f1 = 2.0, f2 = 5.0; //the two input frequencies (bin values)

  for (i = 0 ; i < FFT_N ; i++) { // create samples
    // amplitudes are 1000 for f1 and 500 for f2
    k = 1000 * sin(2 * PI * f1 * i / FFT_N) + 500.*sin(2 * PI * f2 * i / FFT_N);
    fft_input[2 * i] = k; // put real data into even bins
    fft_input[2 * i + 1] = 0; // set odd bins to 0

  //  fft_window();  //Try with and without this line, it smears

  fft_reorder(); // reorder the data before doing the fft
  fft_run(); // process the data using the fft
  fft_mag_lin(); // calculate the magnitude of the output

  // print the frequency index and amplitudes

  Serial.println("bin  amplitude");
  for (i = 0; i < FFT_N / 2; i++) {
    Serial.print("       ");
    Serial.println(2 * fft_lin_out[i]); //*2 for "negative frequency" amplitude

void loop() {}

Here you can see a simple block diagram: :slight_smile:

The basic idea is that the microcontroller tells the DAC to make a 0-5V sweep which then goes into the radar The radar is VCO 24GHz, and will send out a wave and get a wave in return from the object it is hitting. The microcontroller is then going to take the FFT of the in and out signals of the radar, to be able to decide the distance of the objects the wave is hitting. I am sadly not able to tell you the radar modules name, but there is not much more to it than that.

The STM32F1xx microcontrollers have a DMA controller which can be configured to handle the ADC and DAC process. I've done ADC DMA with direct register configuration, as I'm not aware of any Arduino library that does this. No doubt STM has something under their development toolsets. The FFT would run after an ADC buffer is sufficiently full to perform the transform.

Doing some rough system analysis, the minimum range resolution at the fastest STM32 ADC sampling rate is going to be something in excess of 75 meters. The minimum useful range is determined by the length of the chirp, but would be many times that. I'd be surprised if the STM32 can sweep the DAC fast enough to be useful in this application.

There are likely significant licensing and safety concerns with any radar module that can be usefully applied to this scenario. If you're just interested in demonstrating the concept of a chirped radar, perhaps you would consider doing an acoustic rather than radio frequency system.