试验交换机基本配置试验_第1页
试验交换机基本配置试验_第2页
试验交换机基本配置试验_第3页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实验十九通信原理综合实验-BPSK调制解调【设计要求】设计2PSK调制解调器设计环境:显示器设计指标:BPSK调制载波由信号 发生器参数,数据信号由微机参数,两个信号不同步 载波信号幅度Vpp = 2V,标称频率100Hz,误差一 10%PLL入锁频率范围_10Hz跟踪范围 _20Hz数据信号速率5 baud, 0/1方波。【系统设计】1. 总体设计根据系统设计指标,设计系统框图如下:调制系统由乘法器构成。硬件信号发生器产生的载波信号与本地信号发生 器产生的调制信号构成。SBpsK(t) =Am(t)cos(2 二 fct 入)=Acoscos(2二 fct)(t)%)其中:fc为载波频率,入

2、为载波初始相位。解调系统由载波恢复电路和相干解调器构成。由于BPSK信号中没有载波频率分量,因此,需要进行非线性变换为进行系统性能比拟,设计一非同步解调参考解调电路。2. 载波恢复模块设计载波恢复模块由平方倍频器与分频 PLL构成平方器输出为:s(t)二 A2m2(t)cos2(2二 fct 如A221 cos(4二 fct 2=0)在实际应用中A为缓变量,因此,要滤除直流分量不能用常量减法,只能用高通滤波器,其传递函数为:H(s)二PLL电路构成如下:环路中参加倍频器,锁相输出频率为 1/2输入频率。为使环路得到较好的稳定性,环路滤波器采用一阶滤波器H(j 戶根据系统入锁频差要求-n大约在1

3、020HZ之间。(选10Hz)由于BPSK信号的相位为阶跃函数,为保证跟踪锁相环开环增益在保证环路稳 定的条件下取较大值,开环增益中起主要作用的VCO增益取5000HZ/V。3. 解调电路设计解调电路由乘法器与低通滤波器构成。为保证低频数字信号的波形,采用通带平坦型2阶BUTTER低通滤波器,使通带内的相移较小。15791H (s)2 截止频率20Hzs2+178s+157914. 采集卡驱动程序设计MATLAB用S函数编写硬件接口, S函数在MATLAB中的调用过程为Simulink Engine|八:m&checkpaTBmetrurwradlsmtlnpLltp OMH Wi d

4、 th/nid Ismt ChibputP 口 rtAVid th ICLC1巾 Elnpiit P oltD irn!lls.s-:nIIlfp"nLdse 10 lltpctportn 旨 en Bionlnfo -:mdsl 巾 EInp.Llt P QTtS atraplfpTinl e An dsrtr OutputP ore SamplryTinlmX:mdlliiitializQSamplisTinies-IndlserTI 日 putpoTtDsataTypiT/mdlcfletoLlrputpeTtEI atatypIT- I w h- Wl-A 1-H N I 4

5、 i Vi Nili i I fe -h-r 了dlSedDe 即匚】LPQnDacaTyJle3 亠mdlsecLn patPortCQinplexS 曾 al/mdl SetOucpurF Qy C0nl.pl ac«gn:3 】 nidlS et D EfaLt;PQltc QnLPetc Si gn 巴uTuldMtart mdllliitkaliNmcclu-ditioIl?.Y目dloutpu晶-0 sim三邑吕sp99I d4F jv V i!1- d I- ri I J .» Ffllillligal llak F* mdlpTQniewsp 日.anler

6、l-erw*JIConstant blotks5indblnn optionally tails mdlCherkPfiraniete foHewed by mdlFrotessParomBleisSimulation LoopInitialize Model : di IFroc essFa ramecer ioIIbd when paromeiers.:md iGecTinLe OfNexrVarEfit :Called if sample lime oF thKS-fundioniv DriesI mdllmxalizeCondicicins i* tudlOucpUts«:

7、mdlUpdate :ntg ration >> ;mdlDeriva lives:Called if ItiisS-lundiDn hostonlinuous slatesCalled wh 01 poromerers dhangE!製 md lOvtpvt e :弐 mdIDeri vatives:Zero-crossing detection>! adlOucpuc* :Called f this Hun di聞 detects i w cressingsnLdlZes'DCrcBiELngs ; HLdlTetTSLinateEnd Simulation根据接

8、口定义与要求,驱动程序由以下程序构成test_matlab.cpp :/* $Revisio n: 1.3 $ */ Automatically gen erated by MATLAB Project Wizard versio n 1.0 /* Based on sfuntmpl_basic.c: Basic C template for a level 2 S-function.*| See matlabroot/simuli nk/sre/sfu ntmpl_doc.c for a more detailed template |* Copyright 1990-2000 The Ma

9、thWorks, Inc.* $Revision: 1.3 $*/#include "iostream.h"#include <math.h>#include <windows.h>#include "P1202DRV .H"P1202DRV MyDrv;#ifdef _cplusplusextern "C" / use the C fcn-call standard for all functions#endif/ defined within this scope/* You must specify th

10、e 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 SimStruct and* its associated macro definitions.*/#include "sim

11、struc.h"/* S-function methods */ 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 be persistent memory.* It cannot

12、 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/src/sfuntmpl_doc.c for more

13、details.*/* Abstract:*The sizes information is used by Simulink to determine the S-function*block's characteristics (number of inputs, outputs, states, etc.).*/static void mdlInitializeSizes(SimStruct *S)/* See sfuntmpl_doc.c for more details on the macros below */ ssSetNumSFcnParams(S, 0); /* N

14、umber of expected parameters */if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S) /* Return if number of expected != number of actual parameters */return;ssSetNumContStates(S, 0);ssSetNumDiscStates(S, 0);if (!ssSetNumInputPorts(S, 0) return;/ssSetInputPortWidth(S, 0, 1);/ssSetInputPortRequiredCont

15、iguous(S, 0, true); /*direct input signal access*/ssSetInputPortDirectFeedThrough(S, 0, 1);if (!ssSetNumOutputPorts(S, 1) return;ssSetOutputPortWidth(S, 0, 1);ssSetNumSampleTimes(S, 2);ssSetNumRWork(S, 0);ssSetNumIWork(S, 0);ssSetNumPWork(S, 1);ssSetNumModes(S, 0);ssSetNumNonsampledZCs(S, 0);/ssSetO

16、ptions(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*S-function. You must register the same number of sample times as* specified in ssSetNumSampleTimes.*/static void mdlI

17、nitializeSampleTimes(SimStruct *S)ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);ssSetOffsetTime(S, 0, 0.0);ssSetSampleTime(S, 1, 1.0/SAMPLERATE);ssSetOffsetTime(S, 1, 0.0);/ssSetOutputPortSampleTime(S, 0, 0.01);/ssSetOutputPortOffsetTime(S, 0, 0);/#define MDL_INITIALIZE_CONDITIONS/ Abstract:*This fu

18、nction is called once at start of model execution. If you*have states that should be initialized once, this is the place*to do it. Change to #undef to remove function */#undef MDL_INITIALIZE_CONDITIONS#if defined(MDL_INITIALIZE_CONDITIONS)/* Function: mdlInitializeConditions* Abstract:*In this funct

19、ion, you should 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

20、 be called 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_START

21、/* Change to #undef to remove function */#if defined(MDL_START)/* Function: mdlStartstatic void mdlStart(SimStruct *S)/* for(i=0;i<1024;i+)wavei=sin(i*2*3.1416/102.4);*/P1202DRV *MyDrv = new P1202DRV;if(MyDrv=NULL)ssSetErrorStatus(S, "error message");return;ssGetPWork(S)0=(void *)MyDrv;

22、if(MyDrv->Init()ssSetErrorStatus(S, "error message");return;MyDrv->StartScan();#endif /* MDL_START */mdlOutputs/* Function:* Abstract:*In this function, you compute the outputs of your S-functionblock. Generally outputs are placed in the output vector, ssGetY(S).*/static void mdlOutp

23、uts(SimStruct 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 tasks that should only take place once per* integration step.S, int_T tid)/const real_T *u = (const real_T*) ssGetInp

24、utPortSignal(S,0); real_T*y = ssGetOutputPortRealSignal(S,0);real_Tval,Sampletime;P1202DRV *MyDrv = (P1202DRV *)ssGetPWork(S)0;Sampletime=ssGetT(S);val=MyDrv->Read(Sampletime);if(val>100.0)ssSetErrorStatus(S, "Data overflow!");y0=val;#define MDL_UPDATE/* Change to #undef to remove fu

25、nction */#undef MDL_UPDATE#if defined(MDL_UPDATE)mdlUpdate/* Function:static void mdlUpdate(SimStruct Abstract:In this function, you should perform any actions that are necessary at the termination of a simulation.For example, if memory wasallocated in mdlStart, this is the place to free it.S, int_T

26、 tid)#endif /* MDL_UPDATE */#define MDL_DERIVATIVES/* Change to #undef to remove function */#undef MDL_DERIVATIVES#if defined(MDL_DERIVATIVES)mdlDerivatives/* Function:* Abstract:*In this function, you compute the S-function block's derivatives.*The derivatives are placed in the derivative vecto

27、r, ssGetdX(S).*/static void mdlDerivatives(SimStruct *S)#endif /* MDL_DERIVATIVES */*Function:mdlTerminatestatic void mdlTerminate(SimStruct *S)P1202DRV *MyDrv = (P1202DRV *)ssGetPWork(S)0;if(MyDrv=NULL)return;MyDrv->Stop();MyDrv->Close();delete MyDrv;return;/* See sfuntmpl_doc.c for the optio

28、nal 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/* Code generation registration function */#include "cg_sfun.h" #endif#ifdef _cplusplus / en

29、d of extern "C" scope#endifP1202DRV.H:/ P1202DRV .h: interface for the P1202DRV class./#if !defined(AFX_P1202DRV_H_455B5152_0FD1_4D8F_9BD3_9DFD0C69E6E7_INC LUDED_)#defineAFX_P1202DRV_H_455B5152_0FD1_4D8F_9BD3_9DFD0C69E6E7_INCLUDED_#if _MSC_VER > 1000#pragma once#endif / _MSC_VER > 10

30、00#define BUFFLEN 1000#define NUMCHAN 1#define INITFLAG 0X1#define ACTIVEFLAG 0X2#define SCANFLAG 0X4#define READFLAG 0x8#define SAMPLERATE 4000#include <math.h>#ifdef _cplusplusextern "C" / use the C fcn-call standard for all functions#endif / defined within this scope#define S_FUNC

31、TION_LEVEL 2#define S_FUNCTION_NAME test_matlab#include "simstruc.h"#ifdef _cplusplus / end of extern "C" scope#endifclass P1202DRVint initflag,buffindex,readcount;int ErrorFlag;time_T Ts,StartTime,EndTime;DWORD dwP1,dwP2;WORD wChannelStatus32,wChannelConfig32,wStatus;WORD wCard0

32、Buf0BUFFLEN*32,wCard0Buf1BUFFLEN*32; public:P1202DRV();virtual P1202DRV();public:int Init();int Close();int StartScan();double Read(time_T SampleTime);int Stop();WORD CardRead();/ !defined(AFX_P1202DRV_H_455B5152_0FD1_4D8F_9BD3_9DFD0C69E6E7_INCL UDED_)P1202DRV.C:/ P1202DRV .cpp: implementation of th

33、e P1202DRV class./#include <windows.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>#include "p1202.h"#include "P1202DRV .h"/ Construction/Destruction/P1202DRV:P1202DRV()P1202DRV:P1202DRV()P1202DRV:Init()int i;WORD wTotalBoard,wInitialCode;ErrorFl

34、ag=0;for(i=0; i<32; i+)wChannelStatusi=0;wChannelConfigi=0;/wChannelStatus0=1; / Add Ch:0 to be scanfor(i=0;i<NUMCHAN;i+)wChannelStatusi=1;buffindex=0;initflag=0;readcount=0;wInitialCode=P1202_DriverInit(&wTotalBoard);if( wInitialCode!=NoError )ErrorFlag=1;return 1;P1202_ActiveBoard( 0 );Ts=1.0/SAMPLERATE;StartTime=EndTime=0;initflag=INITFLAG|ACTIVEFLAG;return 0;P1202DRV:Close()P1202_DriverClose();initflag=0;return 0;P1202DRV:StartScan()if(ErrorFlag)return ErrorFlag;if(initflag&ACTIVEFLAG)=0)return -1;P1202_Card0_StartScan(WOR

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论