⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrc_complex_send.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/*************************************************************************** *    rrc_complex_send.c  -  Shapes the signal with an rrc ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//** * Takes a signal and upsamples it by a factor of 2, putting an RRC with * roll-off factor of 0.22 on it. */#include "spc.h"#include "rrcs.h"#define DBG_LVL 0// ADD_HERE, int, double, char[128], void*// BEFORE each declaration, write a short description.// ON THE SAME LINE as the declaration, write the default value// Example:// {//   // size of the input in bytes//   int size; // 2560// }typedef struct {  // Which of the rrcs to use  int rrc_index; // 0  // What amplitude  double amplitude; // 1}config_t;// ADD_HERE, int, double, char[128], void*// for the rest, the same definition as the confit_t is valid.typedef struct {}stats_t;// ADD HERE anything you want!typedef struct {  int rrc_len;  double rrc[MAX_RRC_LEN];  double rrc_amp;}private_t;/* * The initialisation function, or constructor,  * is called the first time this module is instantiated. */int send_init( swr_sdb_t *context ) {  // Begin system-definitions {  config_t *config;  stats_t *stats;  MOD_INC_USE_COUNT;  if ( sizeof( private_t ) > 0 )    context->private_data = swr_malloc( sizeof( private_t ) );  swr_sdb_get_config_struct( context->id, (void**)&config );  swr_sdb_get_stats_struct( context->id, (void**)&stats );  // } End of system-definitions  /**   * Put your initialisation here. All parameters you define in config_t,   * stats_t and private_t can be accessed through config->, stats-> and   * private-> respectively   * ADD HERE   */  config->rrc_index = 0;  config->amplitude = 1;  // Begin system-definitions  swr_sdb_free_stats_struct( context->id, (void**)&stats );  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;  // End system-definitions}int send_reconfig( swr_sdb_t *context ) {  config_t *config;  int i;  swr_sdb_get_config_struct( context->id, (void**)&config );  if ( ( config->rrc_index < NUM_OF_RRCS ) && ( config->rrc_index >= 0 ) ){    private->rrc_len = *rrcs[ config->rrc_index ];    private->rrc_amp = 0;    for ( i=0; i<private->rrc_len; i++ ){      private->rrc[i] = rrcs[ config->rrc_index ][ i + 1 ];      private->rrc_amp += abs( private->rrc[ i ] );    }    if ( config->amplitude > 0 ){      private->rrc_amp /= config->amplitude;    }  }  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * To configure the inputs * this is called when the output-sizes change. */int send_configure_inputs( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  size_in(0) = size_out(0) / 2;  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}/* * To configure the outputs * this is called when the input-sizes change */int send_configure_outputs( swr_sdb_t *context ) {  // Definition of variables - don't touch  config_t *config;  swr_sdb_get_config_struct( context->id, (void**)&config );  size_out(0) = size_in(0) * 2;  // Definition - don't touch  swr_sdb_free_config_struct( context->id, (void**)&config );  return 0;}#define CPLX(c) ((c).real + I*(c).imag)#define SYMB(re,im) (SYMBOL_COMPLEX){ re, im }#define MULT(cplx,r) SYMB( (cplx).real*(r), (cplx).imag*(r) )#define ADD(c1,c2) SYMB( (c1).real+(c2).real, (c1).imag+(c2).imag )/* * This is the function that implements the `main method' of the class * Every class has got just ONE method/working-mode. */int send_pdata( swr_sdb_t *context ) {  // Definition of variables - don't touch  SYMBOL_COMPLEX *in, *out, *buf;  int i, j, mp = private->rrc_len, buflen;  in = buffer_in( 0 );  out = buffer_out( 0 );#if 1  buflen = sizeof( SYMBOL_COMPLEX ) * ( size_out( 0 ) + 4 * mp );  buf = swr_malloc( buflen );  memset( buf, 0, buflen );  for ( i=0; i<size_in(0); i++ ){    buf[ 2 * i + 3 * mp / 2 ] = in[ i ];  }  // convolution  memset( out, 0, sizeof( SYMBOL_COMPLEX ) * size_out( 0 ) );  for ( i=0; i < size_out(0) + 2 * mp - 1; i++ ){    double complex o = 0;    for ( j=0; j<mp; j++ ){      o += CPLX( buf[ i + j ] ) * private->rrc[ j ];    }    o /= private->rrc_amp;    out[ i - mp ] = SYMB( creal( o ), cimag( o ) );  }  swr_free( buf );#else  memset( out, 0, sizeof( SYMBOL_COMPLEX ) * size_out( 0 ) );  for ( i=0; i < size_in(0); i++ ){    out[ 2*i ] = in[ i ];  }#endif  return(0);}/* * This is the `destructor'. */int send_finalize( swr_sdb_t *context ) {  if ( sizeof( private_t ) > 0 )    swr_free( private );  MOD_DEC_USE_COUNT;  return 0;}/* * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */swr_spc_id_t send_id;int send_module_init(void) {  swr_spc_desc_t *desc;  /**   * Get a description-part from SPM   * Give the following parameters:   * Input-ports, output-ports, config-params, stat-params   */  desc = swr_spc_get_new_desc( 1, 1, 2, 0 );  if ( !desc ) {    PR_DBG( 0, "Can't initialise the module. This is BAD!\n" );    return -1;  }  /**   * Define the different parts of config and stats. You have to define   * them in the same order as they appear in the structures. The names   * can be freely chosen.   *   * UM_CONFIG_{INT,DOUBLE,DOUBLE_COMPLEX,STRING128,POINTER}( "name" );   * UM_STATS_{INT,DOUBLE,DOUBLE_COMPLEX,STRING128,POINTER,BLOCK,IMAGE}( "name" );   */  UM_CONFIG_INT( "rrc_index" );  UM_CONFIG_DOUBLE( "amplitude" );   /**   * The in- and outputs have also to be defined in the right order. First   * port first. The additional flag is not used yet, but it will...   *   * UM_INPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32,DOUBLE_{,COMPLEX}}, 0 );   * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32,DOUBLE_{,COMPLEX}}, 0 );   */  UM_INPUT( SIG_SYMBOL_COMPLEX, 0 );  UM_OUTPUT( SIG_SYMBOL_COMPLEX, 0 );  // Initialise the callback-functions. Delete the ones you don't use  desc->fn_init              = send_init;  desc->fn_process_data      = send_pdata;  desc->fn_reconfigure       = send_reconfig;  desc->fn_configure_inputs  = send_configure_inputs;  desc->fn_configure_outputs = send_configure_outputs;  desc->fn_finalize          = send_finalize;  // And register the module in the SPM. Change the name!  send_id = swr_cdb_register_spc( &desc, "rrc_complex_send" );  if ( send_id == SWR_SPM_INVALID_ID ) {    swr_spc_free_desc( desc );    PR_DBG( 0, "Couldn't register the module!\n" );    return 1;  }  PR_DBG( 4, "Ready\n" );  return 0;}/* * This is called upon rmmod */void send_module_exit( void ) {  PR_DBG( 4, "Freeing id: %i\n", send_id );  if ( swr_cdb_unregister_spc( send_id ) < 0 ) {    PR_DBG( 0, "Still in use somewhere\n" );  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -