All the signal re-sampling functions implemented in the DSP advanced library.
Following is a brief description of the frequency re-sampling algorithm used in this module. It is aimed for anybody so no specifics digital signal processing knowledges are required to understand this presentation.
The principle is simple, it consists in 2 main stages, up-sampling the signal frequency by an integer value (L), this action is also called interpolation, and then down-sampling it by another integer value (M), also known as decimation.
L and M are 2 integers that are calculated by getting the GCD (Greatest Common Divisor) of the input (Fsin) and the output (Fsout) frequencies.
The number resulting will divide Fsin and Fsout to respectively give M and L.
This process up samples the frequency of the input signal by an integer factor. The factor used at this stage of the process by the re-sampling algorithm will be the pre-calculated "interpolation factor" L. Which means, if we consider this process as a black box with 1 input (u) and 1 output (v), the output signal sampling frequency (Fs(v)) will be equals to the input signal sampling frequency (Fs(u)) multiplied by L.
The following describes the algorithm used to implement the interpolation.
The method consists in extending the signal by filling "blank spaces" with zeros, in order to obtain a signal with the desired sampling rate.
Then this signal goes through a filter in order to remove the highest frequencies, to give it back its original shape. The cut off frequency is calculated according to the input frequency of the signal.
The filter used in this algorithm, is most likely a lowpass FIR filter, which is used as a poly-phase filter. This optimizes greatly the performances of this process because poly-phase filters are simply, classical filters cut into pieces. And in this case, the aim is to have one piece with the original samples and the other with the zeros used to up sample the signal.
Then, by re-ordering the coefficients in a certain way, this process is equivalent to apply a filter only on the original sample parts since the result of filtering a null signal is a null signal.
Now, the signal is interpolated, it needs to be down sampled.
This process is much simpler than the interpolation.
It just consists in removing samples in order to keep the same signal wave form but with a lower sampling rate.
Therefore, to obtain the desired output sampling frequency, the signal has to be down sampled by M (decimation factor).
Every M samples are kept from the input signal and all the others are removed.
By processing these 2 main stages, the signal is re-sampled by a factor equals to L/M. Therefore, the smaller the 2 frequencies have their GCD (Greatest Common Divisor), the more memory it will need (to store the FIR filter coefficients).
This method is one of the most used in digital signal processing systems. It will generate a clean signal and evaluate at best the waveform of the output signal.
The signal is attenuated on high frequencies. Following are traces showing the frequency response of the re-sampling algorithm over different sampling rate conversions.
Data Structures | |
struct | dsp16_resampling_options_t |
Options to attribute to the resampling algorithm. More... | |
struct | dsp_resampling_context_t |
This structure is used to store the context of streaming information during resampling process. More... | |
struct | dsp_resampling_t |
This structure is used to store the context of a resampling process. More... | |
Functions | |
void | dsp16_resampling_compute (dsp_resampling_t *dsp_resampling, dsp16_t *output, dsp16_t *input, int channel) |
The re-sampling computation function. More... | |
int | dsp16_resampling_get_output_current_buffer_size (dsp_resampling_t *dsp_resampling) |
Returns the current length in sample of the output signal. More... | |
int | dsp16_resampling_get_output_max_buffer_size (dsp_resampling_t *dsp_resampling) |
Returns the maximal length in sample of the output signal. More... | |
bool | dsp16_resampling_link (dsp_resampling_t *dsp_resampling_output, dsp_resampling_t *dsp_resampling_input) |
Link a stream previously re-sampled using the dsp_resampling_input resampling structure with the new re-sampling structure dsp_resampling_output. This is used to keep the continuity with two pieces of a stream re-sampled using two different re-sampling parameters. More... | |
Resampling setup function | |
typedef void *(* | malloc_fct_t )(int) |
A pointer on a memory allocation function. More... | |
typedef void(* | free_fct_t )(void *) |
A pointer on a memory free function. More... | |
dsp_resampling_t * | dsp16_resampling_setup (int input_sample_rate, int output_sample_rate, int buffer_size, int order, int nb_channels, malloc_fct_t malloc_fct, dsp16_resampling_options_t *options) |
This function is the 16-bit signal resampling setup function. It has to be called only once at the initialization of the resampling process. More... | |
void | dsp16_resampling_free (dsp_resampling_t *dsp_resampling, free_fct_t free_fct) |
Function used to free the previously allocated structure issued by the dsp16_resampling_setup function. More... | |
typedef void(* free_fct_t)(void *) |
A pointer on a memory free function.
typedef void*(* malloc_fct_t)(int) |
A pointer on a memory allocation function.
void dsp16_resampling_compute | ( | dsp_resampling_t * | dsp_resampling, |
dsp16_t * | output, | ||
dsp16_t * | input, | ||
int | channel | ||
) |
The re-sampling computation function.
dsp_resampling | The re-sampling context structure associated. |
output | A pointer on a 16-bit vector used to store output data. The length of this vector is defined by the output of the dsp16_resampling_get_output_current_buffer_size function. |
input | A pointer on a 16-bit vector used as an input to the re-sampling process. It has to be of a length defined to the dsp16_resampling_setup function as for its sampling rate. |
channel | The channel number to compute (starting from 0 to nb_channels - 1 referred in dsp16_resampling_setup). |
References dsp_resampling_t::buffer_size, dsp_resampling_t::context, dsp_resampling_t::current_buffer_size, data, dsp_resampling_t::decimation_factor, DSP16_RESAMPLING_FUNCTION_NAME, DSP16_RESAMPLING_NO_LOOP_FUNCTION_NAME, dsp16_resampling_polynomial_interpolation(), dsp16_vect_copy(), dsp_resampling_t::filter_order, dsp_resampling_t::fir_coefs, i, dsp_resampling_context_t::index, dsp_resampling_context_t::input_buffer_pos, dsp_resampling_t::interpolation_factor, dsp_resampling_t::last_samples, dsp_resampling_t::link_required, LOOP_UNROLL, LOOP_UNROLL_PLUS_ONE, MREPEAT(), NB_PTS_TO_INTERPOLATE, and output.
Referenced by main(), and usb_stream_process().
void dsp16_resampling_free | ( | dsp_resampling_t * | dsp_resampling, |
free_fct_t | free_fct | ||
) |
Function used to free the previously allocated structure issued by the dsp16_resampling_setup function.
dsp_resampling | The re-sampling context structure to be freed. |
free_fct | A pointer on the free function to be used. |
Referenced by main(), and usb_stream_close().
int dsp16_resampling_get_output_current_buffer_size | ( | dsp_resampling_t * | dsp_resampling | ) |
Returns the current length in sample of the output signal.
dsp_resampling | The re-sampling context structure associated. |
References dsp_resampling_t::current_buffer_size.
Referenced by main(), and usb_stream_process().
int dsp16_resampling_get_output_max_buffer_size | ( | dsp_resampling_t * | dsp_resampling | ) |
Returns the maximal length in sample of the output signal.
dsp_resampling | The re-sampling context structure associated. |
References dsp_resampling_t::buffer_size, dsp_resampling_t::decimation_factor, dsp_resampling_t::filter_order, and dsp_resampling_t::interpolation_factor.
Referenced by main(), and usb_stream_init().
bool dsp16_resampling_link | ( | dsp_resampling_t * | dsp_resampling_output, |
dsp_resampling_t * | dsp_resampling_input | ||
) |
Link a stream previously re-sampled using the dsp_resampling_input resampling structure with the new re-sampling structure dsp_resampling_output. This is used to keep the continuity with two pieces of a stream re-sampled using two different re-sampling parameters.
dsp_resampling_output | The re-sampling context which will be updated according to the dsp_resampling_input context. |
dsp_resampling_input | The input re-sampling context. |
References dsp_resampling_t::buffer_size, dsp_resampling_t::context, dsp_resampling_t::decimation_factor, dsp16_vect_copy(), dsp_resampling_t::filter_order, dsp_resampling_context_t::index, dsp_resampling_context_t::input_buffer_pos, dsp_resampling_t::interpolation_factor, dsp_resampling_t::last_samples, dsp_resampling_t::link_required, and dsp_resampling_t::nb_channels.
Referenced by usb_stream_task().
dsp_resampling_t* dsp16_resampling_setup | ( | int | input_sample_rate, |
int | output_sample_rate, | ||
int | buffer_size, | ||
int | order, | ||
int | nb_channels, | ||
malloc_fct_t | malloc_fct, | ||
dsp16_resampling_options_t * | options | ||
) |
This function is the 16-bit signal resampling setup function. It has to be called only once at the initialization of the resampling process.
input_sample_rate | The sample rate of the input signal. |
output_sample_rate | The sample rate of the output signal. |
buffer_size | The size of the input buffers. |
order | The order of the re-sampling module. This defines indirectly the order of the filter to be used. Its order will be <order> * <interpolation factor>="">. |
malloc_fct | A pointer on a memory allocation function. |
nb_channels | The number of channels to compute. |
options | Add specific options to the algorithm. |
References Align_up, dsp_resampling_t::buffer_size, dsp16_resampling_options_t::coefficients_generation, dsp_resampling_t::context, dsp_resampling_t::decimation_factor, DEFAULT_FILTER_FUNCTION, DEFAULT_WINDOW_FUNCTION, dsp16_filt_interpolation_coefsort(), dsp16_op_abs(), DSP16_QB, dsp16_vect_realdiv(), dsp16_vect_realmul(), dsp16_vect_zeropad(), dsp_op_gcd(), dsp16_resampling_options_t::dynamic, dsp_resampling_t::filter_order, dsp_resampling_t::fir_coefs, dsp16_resampling_options_t::fixed, dsp_resampling_t::fs, i, dsp_resampling_context_t::index, input, dsp_resampling_context_t::input_buffer_pos, dsp_resampling_t::interpolation_factor, j, dsp_resampling_t::last_samples, dsp_resampling_t::link_required, Max, Min, dsp_resampling_t::nb_channels, NB_PTS_TO_INTERPOLATE, and NULL.
Referenced by main(), and usb_stream_init().