1、10通信原理综合标准实验报告实验十九 通信原理综合实验 BPSK调制解调【设计要求】设计2PSK调制解调器。设计环境:设计指标:BPSK调制载波由信号 发生器参数,数据信号由微机参数,两个信号不同步。载波信号幅度Vpp2V,标称频率100Hz,误差10PLL入锁频率范围10Hz跟踪范围20Hz数据信号速率5 baud,0/1方波。【系统设计】1 总体设计根据系统设计指标,设计系统框图如下:调制系统由乘法器构成。硬件信号发生器产生的载波信号与本地信号发生器产生的调制信号构成。 其中:为载波频率,为载波初始相位。解调系统由载波恢复电路和相干解调器构成。由于BPSK信号中没有载波频率分量,因此,需要
2、进行非线性变换。为进行系统性能比较,设计一非同步解调参考解调电路。2 载波恢复模块设计 载波恢复模块由平方倍频器与分频PLL构成 平方器输出为:在实际应用中A为缓变量,因此,要滤除直流分量不能用常量减法,只能用高通滤波器,其传递函数为: PLL电路构成如下: 环路中加入倍频器,锁相输出频率为1/2输入频率。 为使环路得到较好的稳定性,环路滤波器采用一阶滤波器。 根据系统入锁频差要求大约在1020Hz之间。(选10Hz) 由于BPSK信号的相位为阶跃函数,为保证跟踪锁相环开环增益在保证环路稳定的条件下取较大值,开环增益中起主要作用的VCO增益取5000Hz/V。3 解调电路设计解调电路由乘法器与
3、低通滤波器构成。为保证低频数字信号的波形,采用通带平坦型2阶BUTTER低通滤波器,使通带内的相移较小。截止频率20Hz4 采集卡驱动程序设计MATLAB用S函数编写硬件接口,S函数在MATLAB中的调用过程为根据接口定义与要求,驱动程序由下列程序构成:test_matlab.cpp:/* $Revision: 1.3 $ */ Automatically generated by MATLAB Project Wizard version 1.0/* * Based on sfuntmpl_basic.c: Basic C template for a level 2 S-function.
4、 * * - * | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template | * - * * Copyright 1990-2000 The MathWorks, Inc. * $Revision: 1.3 $ */#include iostream.h#include #include #include P1202DRV.HP1202DRV MyDrv;#ifdef _cplusplusextern C / use the C fcn-call standard for all functions #
5、endif / defined within this scope /* * You must specify the S_FUNCTION_NAME as the name of your S-function * (i.e. replace sfuntmpl_basic with the name of your S-function). */#define S_FUNCTION_LEVEL 2#define S_FUNCTION_NAME test_matlab/* * Need to include simstruc.h for the definition of the SimStr
6、uct and * its associated macro definitions. */#include simstruc.h/* Error handling * - * * You should use the following technique to report errors encountered within * an S-function: * * ssSetErrorStatus(S,Error encountered due to .); * return; * * Note that the 2nd argument to ssSetErrorStatus must
7、 be persistent memory. * It cannot be a local variable. For example the following will cause * unpredictable errors: * * mdlOutputs() * * char msg256; ILLEGAL: to fix use static char msg256; * sprintf(msg,Error due to %s, string); * ssSetErrorStatus(S,msg); * return; * * * See matlabroot/simulink/sr
8、c/sfuntmpl_doc.c for more details. */*=* * S-function methods * *=*/* Function: mdlInitializeSizes = * Abstract: * The sizes information is used by Simulink to determine the S-function * blocks characteristics (number of inputs, outputs, states, etc.). */static void mdlInitializeSizes(SimStruct *S)
9、/* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, 0); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S) /* Return if number of expected != number of actual parameters */ return; ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0
10、); if (!ssSetNumInputPorts(S, 0) return; /ssSetInputPortWidth(S, 0, 1); /ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ /ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 1) return; ssSetOutputPortWidth(S, 0, 1); ssSetNumSampleTimes(S, 2); ssSetNumRW
11、ork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 1); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); /ssSetOptions(S, 0); /ssSetOptions(S, SS_OPTION_ALLOW_CONSTANT_PORT_SAMPLE_TIME);/* Function: mdlInitializeSampleTimes = * Abstract: * This function is used to specify the sample time(s) for your *
12、 S-function. You must register the same number of sample times as * specified in ssSetNumSampleTimes. */static void mdlInitializeSampleTimes(SimStruct *S) ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); ssSetSampleTime(S, 1, 1.0/SAMPLERATE); ssSetOffsetTime(S, 1, 0.0); /ss
13、SetOutputPortSampleTime(S, 0, 0.01); /ssSetOutputPortOffsetTime(S, 0, 0);/#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */#undef MDL_INITIALIZE_CONDITIONS#if defined(MDL_INITIALIZE_CONDITIONS) /* Function: mdlInitializeConditions = * Abstract: * In this function, you shoul
14、d initialize the continuous and discrete * states for your S-function block. The initial states are placed * in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S). * You can also perform any other initialization activities that your * S-function may require. Note, this routine will be ca
15、lled at the * start of simulation and if it is present in an enabled subsystem * configured to reset states, it will be call when the enabled subsystem * restarts execution to reset the states. */ static void mdlInitializeConditions(SimStruct *S) #endif /* MDL_INITIALIZE_CONDITIONS */#define MDL_STA
16、RT /* Change to #undef to remove function */#if defined(MDL_START) /* Function: mdlStart = * Abstract: * This function is called once at start of model execution. If you * have states that should be initialized once, this is the place * to do it. */ static void mdlStart(SimStruct *S) /* for(i=0;iIni
17、t() ssSetErrorStatus(S, error message); return; MyDrv-StartScan(); #endif /* MDL_START */* Function: mdlOutputs = * Abstract: * In this function, you compute the outputs of your S-function * block. Generally outputs are placed in the output vector, ssGetY(S). */static void mdlOutputs(SimStruct *S, i
18、nt_T tid) /const real_T *u = (const real_T*) ssGetInputPortSignal(S,0); real_T *y = ssGetOutputPortRealSignal(S,0); real_T val,Sampletime; P1202DRV *MyDrv = (P1202DRV *)ssGetPWork(S)0; Sampletime=ssGetT(S); val=MyDrv-Read(Sampletime); if(val100.0) ssSetErrorStatus(S, Data overflow!); y0=val; #define
19、 MDL_UPDATE /* Change to #undef to remove function */#undef MDL_UPDATE#if defined(MDL_UPDATE) /* Function: mdlUpdate = * Abstract: * This function is called once for every major integration time step. * Discrete states are typically updated here, but this function is useful * for performing any task
20、s that should only take place once per * integration step. */ static void mdlUpdate(SimStruct *S, int_T tid) #endif /* MDL_UPDATE */#define MDL_DERIVATIVES /* Change to #undef to remove function */#undef MDL_DERIVATIVES#if defined(MDL_DERIVATIVES) /* Function: mdlDerivatives = * Abstract: * In this
21、function, you compute the S-function blocks derivatives. * The derivatives are placed in the derivative vector, ssGetdX(S). */ static void mdlDerivatives(SimStruct *S) #endif /* MDL_DERIVATIVES */* Function: mdlTerminate = * Abstract: * In this function, you should perform any actions that are neces
22、sary * at the termination of a simulation. For example, if memory was * allocated in mdlStart, this is the place to free it. */static void mdlTerminate(SimStruct *S) P1202DRV *MyDrv = (P1202DRV *)ssGetPWork(S)0; if(MyDrv=NULL) return; MyDrv-Stop(); MyDrv-Close(); delete MyDrv; return;/*=* * See sfun
23、tmpl_doc.c for the optional S-function methods * *=*/*=* * Required S-function trailer * *=*/#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */#include simulink.c /* MEX-file interface mechanism */#else#include cg_sfun.h /* Code generation registration function */#endif#ifdef _c
24、plusplus / end of extern C scope#endifP1202DRV.H:/ P1202DRV.h: interface for the P1202DRV class./#if !defined(AFX_P1202DRV_H_455B5152_0FD1_4D8F_9BD3_9DFD0C69E6E7_INCLUDED_)#define AFX_P1202DRV_H_455B5152_0FD1_4D8F_9BD3_9DFD0C69E6E7_INCLUDED_#if _MSC_VER 1000#pragma once#endif / _MSC_VER 1000#define
25、BUFFLEN 1000#define NUMCHAN 1#define INITFLAG 0X1#define ACTIVEFLAG 0X2#define SCANFLAG 0X4#define READFLAG 0x8#define SAMPLERATE 4000#include #ifdef _cplusplusextern C / use the C fcn-call standard for all functions #endif / defined within this scope #define S_FUNCTION_LEVEL 2#define S_FUNCTION_NAM
26、E test_matlab#include simstruc.h#ifdef _cplusplus / end of extern C scope#endifclass P1202DRV int initflag,buffindex,readcount; int ErrorFlag; time_T Ts,StartTime,EndTime; DWORD dwP1,dwP2; WORD wChannelStatus32,wChannelConfig32,wStatus; WORD wCard0Buf0BUFFLEN*32,wCard0Buf1BUFFLEN*32;public: P1202DRV(); virtual P1202DRV();public: int Init(); int Close(); int StartScan(); double Read(time_T SampleTime); int Stop(); WORD CardRead();#endif / !defined(AFX_P1202DRV_H_455B5152_0FD1_4D8F_9BD3_9DFD0C69E6E7_INCLUDED_)P1202DRV.C:/ P1202DRV.cpp: implementation of the P1202DRV class./
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1