Signal re-sampling
[Advanced]


Detailed Description

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.

Summary

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 calculation

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.
resampling_l_and_m.gif

Interpolation (frequency up-sampling)

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.
resampling_interpolation.gif
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.
resampling_interpolation2.gif
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.
resampling_interpolation3.gif
Now, the signal is interpolated, it needs to be down sampled.

Decimation (frequency down-sampling)

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).
resampling_decimation.gif
Every M samples are kept from the input signal and all the others are removed.
resampling_decimation2.gif

Conclusion

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.

Frequency response

The signal is attenuated on high frequencies. Following are traces showing the frequency response of the re-sampling algorithm over different sampling rate conversions.
freq_resp_from_32kHz_to_44.1KHz.jpg

Frequency response from 32KHz to 44.1KHz

freq_resp_from_48kHz_to_48.51KHz.jpg

Frequency response from 48KHz to 48.51KHz


Data Structures

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...

Resampling setup function

enum  dsp_resampling_options_t { DSP_RESAMPLING_OPTIONS_NONE, DSP_RESAMPLING_OPTIONS_NORMALIZE_FILTER_COEFFICIENTS }
 Options to attribute to the resampling algorithm. More...
typedef void *(* malloc_fct_t )(int)
 A pointer on a memory allocation function.
dsp_resampling_tdsp16_resampling_setup (int input_sample_rate, int output_sample_rate, int buffer_size, int filter_order, int nb_channels, malloc_fct_t malloc_fct, dsp_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.

Resampling setup function

typedef void(* free_fct_t )(void *)
 A pointer on a memory free function.
void dsp16_resampling_free (dsp_resampling_t *dsp_resampling, free_fct_t free_fct)
 Function used to free the previously allocted structure issued by the dsp16_resampling_setup function.

Functions

void dsp16_resampling_compute (dsp_resampling_t *dsp_resampling, dsp16_t *output, dsp16_t *input, int channel)
 The re-sampling computation function.
int dsp16_resampling_get_output_current_buffer_size (dsp_resampling_t *dsp_resampling)
 Returns the current length in sample of the output signal.
int dsp16_resampling_get_output_max_buffer_size (dsp_resampling_t *dsp_resampling)
 Returns the maximal length in sample of the output signal.
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.


Typedef Documentation

typedef void(* free_fct_t)(void *)

A pointer on a memory free function.

Definition at line 206 of file dsp_resampling.h.

typedef void*(* malloc_fct_t)(int)

A pointer on a memory allocation function.

Definition at line 181 of file dsp_resampling.h.


Enumeration Type Documentation

Options to attribute to the resampling algorithm.

Enumerator:
DSP_RESAMPLING_OPTIONS_NONE  No specific options.
DSP_RESAMPLING_OPTIONS_NORMALIZE_FILTER_COEFFICIENTS  Normalize the filter coefficients to ensure the output won't be too reduced.

Definition at line 171 of file dsp_resampling.h.


Function Documentation

void dsp16_resampling_compute ( dsp_resampling_t dsp_resampling,
dsp16_t output,
dsp16_t input,
int  channel 
)

The re-sampling computation function.

Parameters:
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 refered in dsp16_resampling_setup).

void dsp16_resampling_free ( dsp_resampling_t dsp_resampling,
free_fct_t  free_fct 
)

Function used to free the previously allocted structure issued by the dsp16_resampling_setup function.

Parameters:
dsp_resampling The re-sampling context structure to be freed.
free_fct A pointer on the free function to be used.

int dsp16_resampling_get_output_current_buffer_size ( dsp_resampling_t dsp_resampling  ) 

Returns the current length in sample of the output signal.

Parameters:
dsp_resampling The re-sampling context structure associated.

int dsp16_resampling_get_output_max_buffer_size ( dsp_resampling_t dsp_resampling  ) 

Returns the maximal length in sample of the output signal.

Parameters:
dsp_resampling The re-sampling context structure associated.

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.

Precondition:
Some considerations have to be taken care of before using this function. The two structure MUST have in common: the number of channels, the filter order and the input buffer size.
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.
Returns:
true if the process succeed, false otherwise. A process can fail only if the preliminary conditions are not respected.

dsp_resampling_t* dsp16_resampling_setup ( int  input_sample_rate,
int  output_sample_rate,
int  buffer_size,
int  filter_order,
int  nb_channels,
malloc_fct_t  malloc_fct,
dsp_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.

Parameters:
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.
filter_order The order of the filter to be used.
malloc_fct A pointer on a memory allocation function.
nb_channels The number of channels to compute.
options Add specific options to the algorithm.
Returns:
A pointer on a structure containing the context that will be used during the re-sampling process.
Note:
The output must be freed with the dsp16_resampling_free function once the re-sampling process is completed.


Generated on Fri Feb 19 02:28:01 2010 for AVR32 - Fixed point DSP Library by  doxygen 1.5.5