How to store and manage ADC values in a 2D array for FFT processing in an FMCW radar system

I am using an FMCW radar to determine the distance and speed of a moving object with an STM32L476 microcontroller. To find the range of a stationary object, I store the ADC values into the "fft_in" array using the "HAL_ADC_ConvCpltCallback" function. I have initialized "is_data_ready_for_fft = 1" as follows:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc1) {
is_data_ready_for_fft = 1;
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc1) {
is_data_ready_for_fft = 1;
}
Then, I calculate the range using FFT. Now, I need to store this 1D array of ADC values in a 2D array to calculate the Doppler frequency across the chirp index. The code that copies ADC values into the fft_in array and performs the range calculation is in the file below () Here is the desired matrix structure, where each fft_in array at different times forms rows of the matrix:
[0,0] = fft_in(0)[0], [0,1] = fft_in(0)[1], ..., [0,512] = fft_in(0)[512]
[1,0] = fft_in(1)[0], [1,1] = fft_in(1)[1], ..., [1,512] = fft_in(1)[512]
[2,0] = fft_in(2)[0], [2,1] = fft_in(2)[1], ..., [2,512] = fft_in(2)[512]
...
[19,0] = fft_in(19)[0], [19,1] = fft_in(19)[1], ..., [19,512] = fft_in(19)[512]
#The chirp index is taken as 20, and the number of samples is 512. Thus, FFT across rows yields range, and FFT across columns yields velocity.
[0,0] = fft_in(0)[0], [0,1] = fft_in(0)[1], ..., [0,512] = fft_in(0)[512]
[1,0] = fft_in(1)[0], [1,1] = fft_in(1)[1], ..., [1,512] = fft_in(1)[512]
[2,0] = fft_in(2)[0], [2,1] = fft_in(2)[1], ..., [2,512] = fft_in(2)[512]
...
[19,0] = fft_in(19)[0], [19,1] = fft_in(19)[1], ..., [19,512] = fft_in(19)[512]
#The chirp index is taken as 20, and the number of samples is 512. Thus, FFT across rows yields range, and FFT across columns yields velocity.
Solution:
Yes, precisely!👍 @Sterling As you proceed through each chirp, that will store your {fft_in} array into the matrix row by row. After that, you may examine the matrix to calculate the velocity or any other desired parameter.
Jump to solution
7 Replies
UC GEE
UC GEE4mo ago
@Sterling You can create a 2D array where each row will represent the fft_in values at a specific time, or “chirp index” as you’re calling it. For example, if you’re capturing 20 chirps, you’ll want a 20x512 matrix—20 rows for each chirp and 512 columns for the samples.
Sterling
Sterling4mo ago
Hmm, makes sense tho. But how do I actually store the fft_in array into that matrix every second?
UC GEE
UC GEE4mo ago
You’d create the 2D matrix first, something like float32_t fft_matrix[20][512];. Then, each time your fft_in array updates, you copy its contents into the next available row of your matrix. You can do this in your existing loop where you process the FFT. @Sterling
Sterling
Sterling4mo ago
@UC GEE So I believe it's something like this yhhh ??
// Assuming you're inside your main loop
if (is_data_ready_for_fft == 1) {
// Copy fft_in to the matrix row corresponding to the current chirp
for (size_t i = 0; i < ADC_BUF_LENGTH; i++) {
fft_matrix[chirp_index][i] = fft_in[i];
}

// Process the FFT as usual
is_data_ready_for_fft = 0;
arm_rfft_fast_f32(&fft_handler, fft_in, fft_out, 0);
arm_cmplx_mag_f32(fft_out, fft_out2, ADC_BUF_LENGTH);
fft_out2[0] = 0;
arm_max_f32(fft_out2, ADC_BUF_LENGTH/2, &Result, &Index);

R = (300000000 * 0.004064 * Index) / 500000000;

// Increment the chirp index
chirp_index++;

// Reset if you've captured all chirps
if (chirp_index >= 20) {
chirp_index = 0; // or handle it depending on your needs
}
}
// Assuming you're inside your main loop
if (is_data_ready_for_fft == 1) {
// Copy fft_in to the matrix row corresponding to the current chirp
for (size_t i = 0; i < ADC_BUF_LENGTH; i++) {
fft_matrix[chirp_index][i] = fft_in[i];
}

// Process the FFT as usual
is_data_ready_for_fft = 0;
arm_rfft_fast_f32(&fft_handler, fft_in, fft_out, 0);
arm_cmplx_mag_f32(fft_out, fft_out2, ADC_BUF_LENGTH);
fft_out2[0] = 0;
arm_max_f32(fft_out2, ADC_BUF_LENGTH/2, &Result, &Index);

R = (300000000 * 0.004064 * Index) / 500000000;

// Increment the chirp index
chirp_index++;

// Reset if you've captured all chirps
if (chirp_index >= 20) {
chirp_index = 0; // or handle it depending on your needs
}
}
Solution
UC GEE
UC GEE4mo ago
Yes, precisely!👍 @Sterling As you proceed through each chirp, that will store your {fft_in} array into the matrix row by row. After that, you may examine the matrix to calculate the velocity or any other desired parameter.
Sterling
Sterling4mo ago
Thanks very much man🙏🏽
Want results from more Discord servers?
Add your server