qam_symbtowave.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:4k
- //
- // File = qam_symbtowave.cpp
- //
- #include <stdlib.h>
- //#include <fstream>
- #include "parmfile.h"
- #include "qam_symbtowave.h"
- #include "model_error.h"
- #include "misdefs.h"
- #include "model_graph.h"
- #include "typedefs.h"
- //#include "cmpxsig.h"
- extern ParmFile *ParmInput;
- #ifdef _DEBUG
- extern ofstream *DebugFile;
- #endif
- //======================================================
- QamSymbsToQuadWaves::QamSymbsToQuadWaves( char* instance_name,
- PracSimModel* outer_model,
- Signal<byte_t>* in_symb_seq,
- Signal<float>* i_out_sig,
- Signal<float>* q_out_sig,
- Signal<bit_t>* symb_clock_out )
- :PracSimModel(instance_name,
- outer_model)
- {
- MODEL_NAME(QamSymbsToQuadWaves);
- ENABLE_MULTIRATE;
- //----------------------------------------
- // Read model config parms
- OPEN_PARM_BLOCK;
- GET_INT_PARM(Bits_Per_Symb);
- GET_INT_PARM(Samps_Per_Symb);
- GET_DOUBLE_PARM(Symb_Duration);
- //-------------------------------------
- // Connect input and output signals
- In_Symb_Seq = in_symb_seq;
- I_Out_Sig = i_out_sig;
- Q_Out_Sig = q_out_sig;
- Symb_Clock_Out = symb_clock_out;
- MAKE_OUTPUT( I_Out_Sig );
- MAKE_OUTPUT( Q_Out_Sig );
- MAKE_OUTPUT( Symb_Clock_Out );
- MAKE_INPUT( In_Symb_Seq );
- // one sample per symbol from input
- double resamp_rate = double(Samps_Per_Symb);
- SET_SAMP_INTVL( In_Symb_Seq, Symb_Duration);
- CHANGE_RATE( In_Symb_Seq, Symb_Clock_Out, resamp_rate );
- CHANGE_RATE( In_Symb_Seq, I_Out_Sig, resamp_rate );
- CHANGE_RATE( In_Symb_Seq, Q_Out_Sig, resamp_rate );
- //-----------------------------------------
- // Set up derived parms
- Num_Symb_Rows = 1;
- for(int i=1; i<=Bits_Per_Symb/2; i++)
- Num_Symb_Rows *=2;
- //------------------------------------------------------------
- // generate tables of I & Q values for desired constellation
- I_Compon = new float[Num_Symb_Rows];
- Q_Compon = new float[Num_Symb_Rows];
- for(int isymb=0; isymb<Num_Symb_Rows; isymb++)
- {
- I_Compon[isymb] = float(1 - Num_Symb_Rows + 2 * isymb);
- Q_Compon[isymb] = float(1 - Num_Symb_Rows + 2 * isymb);
- }
- }
- //===========================================
- QamSymbsToQuadWaves::~QamSymbsToQuadWaves( void ){ };
- //===========================================
- void QamSymbsToQuadWaves::Initialize(void)
- {
- In_Block_Size = In_Symb_Seq->GetBlockSize();
- Out_Block_Size = I_Out_Sig->GetBlockSize();
- }
- //============================================
- int QamSymbsToQuadWaves::Execute(void)
- {
- byte_t *in_symb_seq_ptr;
- byte_t i_part, q_part;
- float i_comp, q_comp;
- float *i_out_sig_ptr, *q_out_sig_ptr;
- int in_block_size;
- int out_block_size;
- bit_t *symb_clock_out_ptr;
- int is;
- #ifdef _DEBUG
- *DebugFile << "In QamSymbsToQuadWaves::Execute " << endl;
- #endif
- i_out_sig_ptr = GET_OUTPUT_PTR( I_Out_Sig );
- q_out_sig_ptr = GET_OUTPUT_PTR( Q_Out_Sig );
- symb_clock_out_ptr = GET_OUTPUT_PTR( Symb_Clock_Out );
- in_symb_seq_ptr = GET_INPUT_PTR( In_Symb_Seq );
- in_block_size = In_Symb_Seq->GetValidBlockSize();
- out_block_size = Samps_Per_Symb * in_block_size;
- I_Out_Sig->SetValidBlockSize(out_block_size);
- Q_Out_Sig->SetValidBlockSize(out_block_size);
- Symb_Clock_Out->SetValidBlockSize(out_block_size);
- for (is=0; is<in_block_size; is++)
- {
- // get input symbol and split into ideal I & Q components
- i_part = (*in_symb_seq_ptr)/Num_Symb_Rows; // 2 MSBs
- q_part = (*in_symb_seq_ptr)%Num_Symb_Rows; // 2 LSBs
- i_comp = I_Compon[i_part];
- q_comp = Q_Compon[q_part];
- in_symb_seq_ptr++;
- for(int isamp=0; isamp<Samps_Per_Symb; isamp++)
- {
- *i_out_sig_ptr++ = i_comp;
- *q_out_sig_ptr++ = q_comp;
- if(isamp == (Samps_Per_Symb-1))
- *symb_clock_out_ptr++ = 1;
- else
- *symb_clock_out_ptr++ = 0;
- }
- }
- return(_MES_AOK);
- }