📄 wcdmareceivefilter.cpp
字号:
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "C:\MATLABR11\extern\include\mex.h"
//#include "mex.h"
void WCDMAReceiveFilter(double *,double *,unsigned ,unsigned ,double *,unsigned ,unsigned,
double *,double *,unsigned );
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
/**************************************************************************************
* void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
*
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
* Gateway function for WCDMAMReceiveFilter. Supports that passing of three input parameters
* and one output parameter. The threeinput parameters are
* IncomingSignal Complex matrix of incoming signals. The signals
* must be placed columnwise in the matrix.
* PulseShape Real valued vector containing the fitler's impulse response
* SamplesPerChip Contains the oversampling rate or "decimation" rate
*
* The one output is a matrix where each colum contains the filtered and decimated signal
* correspond to each signal in the IncomingSignal matrix
********************************************************************************/
{
double *mexInphaseSignalPtr,*mexQuadratureSignalPtr;
unsigned mexSignalLength,mexPulseLength,mexFilteredSignalLength,mexNumSignals;
double *mexInphaseFilterSignalPtr,*mexQuadratureFilterSignalPtr;
double *mexPulseShape;
const mxArray *tprhs;
int mrows,ncols;
unsigned mexSamplesPerChip;
double dbleScale,fraction,integer_portion;
//Check for the proper number of input and output arguments
if (nrhs != 3) mexErrMsgTxt("\nExactly 3 input arguemnts are required!!\n");
else if (nlhs != 1 ) mexErrMsgTxt("\nExactly ONE output arguement is required!!\n");
//First Inputs must be a matrix of Complex Values
//Incoming Signal
//Must be a double, complex, and a Matrix
tprhs = *prhs;
mrows = mxGetM(tprhs);
ncols = mxGetN(tprhs);
if ( !mxIsDouble(tprhs) || !mxIsComplex(tprhs) || (mrows ==1 && ncols ==1))
mexErrMsgTxt("\nChip Sequence must be a complex matrix or vector\n");
mexSignalLength = mrows;
mexNumSignals = ncols;
if (mexNumSignals >= mexSignalLength)
mexErrMsgTxt("\nThe signal length MUST EXCEED the number of singals\nIt may be necessary to transpose the matrix");
mexInphaseSignalPtr = mxGetPr(tprhs);
mexQuadratureSignalPtr = mxGetPi(tprhs);
//Pulse Sphape
//Must be a double, real and a vector
tprhs = *(prhs+1);
mrows = mxGetM(tprhs);
ncols = mxGetN(tprhs);
if ( !mxIsDouble(tprhs) || mxIsComplex(tprhs) || (mrows ==1 && ncols ==1) || (mrows >1 && ncols >1))
mexErrMsgTxt("\nPulse Shape must be a real vector\n");
if (mrows > ncols) mexPulseLength = mrows;
else mexPulseLength = ncols;
mexPulseShape = mxGetPr(tprhs);
//SampelsPerChip
//Must be a double, real and scalar
tprhs = *(prhs+2);
mrows = mxGetM(tprhs);
ncols = mxGetN(tprhs);
if ( !mxIsDouble(tprhs) || mxIsComplex(tprhs) || !(mrows ==1 && ncols ==1) )
mexErrMsgTxt("\nSamplesPerChip must be a real scalar\n");
//Check to make sure that it is an integer
dbleScale=mxGetScalar(tprhs);
fraction=modf(dbleScale,&integer_portion);
if (integer_portion <= 0.0) mexErrMsgTxt("\nMexSamplesPerChip must be positive\n");
mexSamplesPerChip = (unsigned) integer_portion;
if (fraction != 0) mexErrMsgTxt("\nMexSamplesPerChip must be an integer\n");
//Determine Size of output array
mexFilteredSignalLength = (mexSignalLength-(mexPulseLength -mexSamplesPerChip))/mexSamplesPerChip;
//Allocate output Array
*plhs = mxCreateDoubleMatrix(mexFilteredSignalLength,mexNumSignals,mxCOMPLEX);
mexInphaseFilterSignalPtr = mxGetPr(*plhs);
mexQuadratureFilterSignalPtr = mxGetPi(*plhs);
WCDMAReceiveFilter(mexInphaseSignalPtr,mexQuadratureSignalPtr,mexSignalLength,mexNumSignals,
mexPulseShape,mexPulseLength,mexSamplesPerChip,
mexInphaseFilterSignalPtr,mexQuadratureFilterSignalPtr,
mexFilteredSignalLength);
}
void WCDMAReceiveFilter(double *InphaseSignalPtr,double *QuadratureSignalPtr,unsigned SignalPoints,
unsigned NumSignals,double *PulseShapePtr,unsigned PulseLength,
unsigned SamplesPerChip,
double *InphaseFilteredSignalPtr,double *QuadratureFilteredSignalPtr,
unsigned FilteredSignalSamples)
/*************************************************************************************************
*void WCDMAReceiveFilter(double *InphaseSignalPtr,double *QuadratureSignalPtr,unsigned SignalPoints,
* unsigned NumSignals,double *PulseShapePtr,unsigned PulseLength,
* unsigned SamplesPerChip,
* double *InphaseFilteredSignalPtr,double *QuadratureFilteredSignalPtr,
* unsigned FilteredSignalSamples)
*
*
* Copyright 2002 The Mobile and Portable Radio Research Group
*
*This function filters and decimates the incoming complex-valued signal with the FIR impulse
*reponse stored in PulseShape. The decimation rate is equal to SamplesPerChip. Decimation is simply
*performed by filtering every SamplesPerChip'th output sample. The "delay" and "tail" due to the
*filtering is removed
*This fuction works on matrix of signal data, where each column in the the matrix is a
*different signal
*
*Parameters
* Input
* InPhaseSignal double * Pointer to matrix of length NumSamples that stores
* the inphase signal values
* QuadratureSignal double * Pointer to matrix of length NumSamples that stores
* the quadrature signal values
* SignalPoints unsigned Length of signal arrays
* NumSignals unsigned The number of signals in the matrix
* PulseShape double * Pointer to array of length PulseLength that stores
* the pulse shape
* PulseLength unsigned Length of the PulseShape array
* SamplesPerChip unsigned Number of chip duration
*
* Output
* InphaseFilteredSignal double * Pointer to matrix of filtered inphase signal values
* QuadratureFilteredSignal double * Pointer to matrix of filtered quadrature signal
* values
* FilteredSignalSamples unsigned legnth of filtered signal
*
**************************************************************************************************/
{
unsigned k,k1,k2,PaddedLength;
// double *InphasePaddedPtr,*QuadPaddedPtr;
double *InphaseSigPtr,*QuadSigPtr;
double *InphaseFilterSigPtr,*QuadFilterSigPtr;
double *InFilterTmpPtr,*QuadFilterTmpPtr;
double *InphaseTmpPtr,*QuadTmpPtr,*PulseTmpPtr;
unsigned loopstart;
PaddedLength = SignalPoints + 2 * PulseLength;
// InphasePaddedPtr = (double *) mxCalloc(PaddedLength,sizeof(double));
// QuadPaddedPtr = (double *) mxCalloc(PaddedLength,sizeof(double));
for (k=0;k<NumSignals;k++)
{
InphaseSigPtr = InphaseSignalPtr + SignalPoints * k;
QuadSigPtr = QuadratureSignalPtr + SignalPoints * k;
InphaseFilterSigPtr = InphaseFilteredSignalPtr + FilteredSignalSamples * k;
QuadFilterSigPtr = QuadratureFilteredSignalPtr + FilteredSignalSamples * k;
loopstart=PulseLength-1;
InFilterTmpPtr = InphaseFilterSigPtr;
QuadFilterTmpPtr = QuadFilterSigPtr;
InphaseSigPtr += loopstart;
QuadSigPtr += loopstart;
for (k1=loopstart;k1<SignalPoints;k1+=SamplesPerChip)
{
InphaseTmpPtr = InphaseSigPtr;
QuadTmpPtr = QuadSigPtr;
PulseTmpPtr = PulseShapePtr;
for (k2=0;k2<PulseLength;k2++)
{
*InFilterTmpPtr += *PulseTmpPtr * *InphaseTmpPtr--;
*QuadFilterTmpPtr += *PulseTmpPtr++ * *QuadTmpPtr--;
}
InFilterTmpPtr++;
QuadFilterTmpPtr++;
InphaseSigPtr += SamplesPerChip;
QuadSigPtr += SamplesPerChip;
}
}
// mxFree(InphasePaddedPtr);
// mxFree(QuadPaddedPtr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -