Note that there are some explanatory texts on larger screens.

plurals
  1. PODFT with Frequency Range
    primarykey
    data
    text
    <p>We need to change/reimplement standard DFT implementation in GSL, which is </p> <pre><code>int FUNCTION(gsl_dft_complex,transform) (const BASE data[], const size_t stride, const size_t n, BASE result[], const gsl_fft_direction sign) { size_t i, j, exponent; const double d_theta = 2.0 * ((int) sign) * M_PI / (double) n; /* FIXME: check that input length == output length and give error */ for (i = 0; i &lt; n; i++) { ATOMIC sum_real = 0; ATOMIC sum_imag = 0; exponent = 0; for (j = 0; j &lt; n; j++) { double theta = d_theta * (double) exponent; /* sum = exp(i theta) * data[j] */ ATOMIC w_real = (ATOMIC) cos (theta); ATOMIC w_imag = (ATOMIC) sin (theta); ATOMIC data_real = REAL(data,stride,j); ATOMIC data_imag = IMAG(data,stride,j); sum_real += w_real * data_real - w_imag * data_imag; sum_imag += w_real * data_imag + w_imag * data_real; exponent = (exponent + i) % n; } REAL(result,stride,i) = sum_real; IMAG(result,stride,i) = sum_imag; } return 0; } </code></pre> <p>In this implementation, GSL iterates over input vector twice for sample/input size. However, we need to construct for different frequency bins. For instance, we have 4096 samples, but we need to calculate DFT for 128 different frequencies. Could you help me to define or implement required DFT behaviour? Thanks in advance.</p> <p>EDIT: We do not search for first <code>m</code> frequencies.</p> <p>Actually, is below approach correct for finding DFT result with given frequency bin number? N = sample size B = frequency bin size</p> <pre><code>k = 0,...,127 X[k] = SUM(0,N){x[i]*exp(-j*2*pi*k*i/B)} </code></pre> <p>EDIT: I might have not explained the problem for DFT elaborately, nevertheless, I am happy to provide the answer below:</p> <pre><code>void compute_dft(const std::vector&lt;double&gt;&amp; signal, const std::vector&lt;double&gt;&amp; frequency_band, std::vector&lt;double&gt;&amp; result, const double sampling_rate) { if(0 == result.size() || result.size() != (frequency_band.size() &lt;&lt; 1)){ result.resize(frequency_band.size() &lt;&lt; 1, 0.0); } //note complex signal assumption const double d_theta = -2.0 * PI * sampling_rate; for(size_t k = 0; k &lt; frequency_band.size(); ++k){ const double f_k = frequency_band[k]; double real_sum = 0.0; double imag_sum = 0.0; for(size_t n = 0; n &lt; (signal.size() &gt;&gt; 1); ++n){ double theta = d_theta * f_k * (n + 1); double w_real = cos(theta); double w_imag = sin(theta); double d_real = signal[2*n]; double d_imag = signal[2*n + 1]; real_sum += w_real * d_real - w_imag * d_imag; imag_sum += w_real * d_imag + w_imag * d_real; } result[2*k] = real_sum; result[2*k + 1] = imag_sum; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload