<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Doubt about the sampling rate</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49897/doubt-about-the-sampling-rate</link><description>I am using 3 axis LIS2D12H accelerometer interfaced with NRF51832 with SPI interface. The sensor has sampling rate from 1 HZ to 5.376 KHz which is happening at sensor only. I am taking sensor data at 400 Hz by setting register values in sensor. I am implementing</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Aug 2019 08:38:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49897/doubt-about-the-sampling-rate" /><item><title>RE: Doubt about the sampling rate</title><link>https://devzone.nordicsemi.com/thread/202342?ContentTypeID=1</link><pubDate>Mon, 05 Aug 2019 08:38:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00d01c45-1069-428f-a865-139feb845903</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There seems to be some problems with your implementation.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;First off, the fft_generate_samples(..) function is only used in the example to generate some dummy data for the FFT to process. Since you have some actual data to process&amp;nbsp;from your accelerometer you don&amp;#39;t have to generate the data through this function (you can still look at the implementation of this function to see how the input array should be set up).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Instead you should buffer a series of samples from your accelerometer, and run the fft_process function once you have buffered the required 64 samples in your buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As you can see in fft_generate_samples(..) every&amp;nbsp;even index in the input buffer contains the real value (your accelerometer reading), while every odd index contains the imaginary value, which you can just set to 0.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Doubt about the sampling rate</title><link>https://devzone.nordicsemi.com/thread/202089?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 10:10:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab765638-34bb-4939-956c-b50461380333</guid><dc:creator>Yashodhan</dc:creator><description>[quote userid="2116" url="~/f/nordic-q-a/49897/doubt-about-the-sampling-rate/202058"]I assume you mean the &lt;em&gt;amplitude of the maximum frequency&lt;/em&gt; is always zero?[/quote]
&lt;p&gt;no at maximum amplitude of fft the frequency is always zero&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void draw_fft_data(float32_t * p_input_data, uint16_t data_size)
{

    float32_t max_value;
    uint32_t  max_val_index;
    float32_t freq; 
    // Search FFT max value in input array.
    arm_max_f32(p_input_data, data_size, &amp;amp;max_value, &amp;amp;max_val_index);
    freq = max_val_index*bin_resolution;

    
    // NRF_LOG_INFO(&amp;quot;Maximum value index %lu\r\n&amp;quot;,max_val_index);
    //NRF_LOG_INFO(&amp;quot;Max FFT Value: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot;\r\n&amp;quot;, NRF_LOG_FLOAT(max_value));

   //NRF_LOG_INFO(&amp;quot;Frequency of max: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot;\r\n&amp;quot;, NRF_LOG_FLOAT(freq));
         sprintf((char*)datafft,&amp;quot;Maximum value index = %lu,Max FFT Value = %.2f,Frequency of max = %.2f&amp;quot;,max_val_index,(float32_t) max_value,(float32_t) freq);
          (void) nrf_serial_write(&amp;amp;serial_uart,
                           &amp;amp; (datafft),strlen((char*)datafft),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
                           
         (void) nrf_serial_write(&amp;amp;serial_uart,
                           &amp;quot;\n\r&amp;quot;,
                           strlen(&amp;quot;\n\r&amp;quot;),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
            (void)nrf_serial_flush(&amp;amp;serial_uart, 0);
            nrf_delay_ms(5);
   
    /* NRF_LOG_RAW_INFO(&amp;quot;Maximum value index %lu\r\n&amp;quot;,max_val_index);
    NRF_LOG_RAW_INFO(&amp;quot;Max FFT Value: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot;\r\n&amp;quot;, NRF_LOG_FLOAT(max_value));

   NRF_LOG_RAW_INFO(&amp;quot;Frequency of max: &amp;quot; NRF_LOG_FLOAT_MARKER &amp;quot;\r\n&amp;quot;, NRF_LOG_FLOAT(freq));*/
   
   }

void compute_fft(float32_t inputbuf[],float32_t outbuf[],float32_t axis,char a)
{
         // uint8_t uartchar[10] ;
         // NRF_LOG_RAW_INFO(&amp;quot;Axis Data %c\r\n&amp;quot;,a);
         sprintf((char*)uartchar,&amp;quot;Axis Data = %c&amp;quot;,a);
          (void) nrf_serial_write(&amp;amp;serial_uart,
                           &amp;amp;(uartchar),strlen((char*)uartchar),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
                           
         (void) nrf_serial_write(&amp;amp;serial_uart,
                           &amp;quot;\n\r&amp;quot;,
                           strlen(&amp;quot;\n\r&amp;quot;),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
                           (void)nrf_serial_flush(&amp;amp;serial_uart, 0);
                           nrf_delay_ms(5);
          fft_generate_samples(inputbuf,
                             FFT_TEST_COMP_SAMPLES_LEN,
                             FFT_TEST_SAMPLE_FREQ_HZ,
                             axis);
                    
          fft_process(inputbuf,
                    &amp;amp;arm_cfft_sR_f32_len32,
                    outbuf,
                    FFT_TEST_OUT_SAMPLES_LEN); 
           draw_fft_data(outbuf, FFT_TEST_OUT_SAMPLES_LEN);         


}


#ifdef FPU_INTERRUPT_MODE
    // Enable FPU interrupt
    NVIC_SetPriority(FPU_IRQn, APP_IRQ_PRIORITY_LOWEST);
    NVIC_ClearPendingIRQ(FPU_IRQn);
    NVIC_EnableIRQ(FPU_IRQn);
#endif

 
    //for (;;)
    while(true)
    
    {
      //GetLis2dhData();
       
       for(volatile uint16_t j = 0; j&amp;lt;numsamples; j++)
       {
           GetLis2dhData();
       
           accdata[j] =gattdata.buff[0] ;
          sqrx+=  pow((float32_t)accdata[j],2);
         
           x_freq = (((uint32_t)accdata[j]) % ((uint32_t)(SINE_WAVE_FREQ_MAX * SIGNALS_RESOLUTION))) / SIGNALS_RESOLUTION;
          compute_fft(m_fft_input_f32_x,m_fft_output_f32_x,x_freq,&amp;#39;X&amp;#39;);
         
         
                 
       
       }
    
       (void) nrf_serial_write(&amp;amp;serial_uart,
                           &amp;amp;(outfft),
                           strlen((char*)outfft),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
                           
                           
                           
         (void) nrf_serial_write(&amp;amp;serial_uart,
                           &amp;quot;\n\r&amp;quot;,
                           strlen(&amp;quot;\n\r&amp;quot;),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
       &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Doubt about the sampling rate</title><link>https://devzone.nordicsemi.com/thread/202058?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 08:42:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:723cfad7-f92a-40b7-a0d5-0d6dc554713c</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
[quote user="Yashodhan"]what happens is I am geting frequency of maximum amplitude always zero.[/quote]
&lt;p&gt;I assume you mean the &lt;em&gt;amplitude of the maximum frequency&lt;/em&gt; is always zero?&lt;/p&gt;
&lt;p&gt;Could you show me the code you use to run the FFT?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Doubt about the sampling rate</title><link>https://devzone.nordicsemi.com/thread/201917?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 13:28:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60f8b806-c254-4570-ab72-87896aa5606b</guid><dc:creator>Yashodhan</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;nbsp;&amp;quot;I am not quite sure I understand this question, but I would expect that each sensor read is passed to the FFT after applying some simple processing of the data (at a minimum I would expect some unit conversion and scaling to be required). &amp;quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Actually raw data is being captured from sensor, when I apply FFT for buffer of samples like 32,64..., what happens is I am geting frequency of maximum amplitude always zero. So I am still confused shall it need to be sampled at microcontroller separately in order to take FFT&lt;/p&gt;
&lt;p&gt;&amp;quot;Also, assuming you are just using one dimensional FFT, how do you plan to convert the three dimensional sensor data to one dimension for the FFT?&amp;quot;&lt;/p&gt;
&lt;p&gt;Currenlty we are taking individual FFT for each axis and I want to send the output fft samples over serial.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Doubt about the sampling rate</title><link>https://devzone.nordicsemi.com/thread/201881?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 12:38:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19ec681e-0b78-4a62-8f10-bd8fe81fbc1f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
[quote user=""]Shall I take raw samples in buffer and sample them or shall I take each reading from sensor and sample them individually.[/quote]
&lt;p&gt;I am not quite sure I understand this question, but I would expect that each sensor read is passed to the FFT after applying some simple processing of the data (at a minimum I would expect some unit conversion and scaling to be required).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, assuming you are just using one dimensional FFT, how do you plan to convert the three dimensional sensor data to one dimension for the FFT?&lt;/p&gt;
[quote user=""]If that is the case how shall I select sampling frequency at microcontroller level and/or at what rate microcontroller shall read data[/quote]
&lt;p&gt;You mentioned the sensor is set to 400Hz, then the microcontroller should follow this I would assume?&lt;/p&gt;
&lt;p&gt;Normally you would run the sensor and the internal processing in sync, and set the frequency depending on the frequency range&amp;nbsp;of the data signal that you are trying to analyze.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>