3/26/2018 Gmail - (no subject) https://mail.google.com/mail/u/0/?ui=2&ik=3fe50a2bf5&jsver=lr-NdqmOTUs.en.&view=pt&search=inbox&th=16260b9814b0609a&siml=16260b9814b0609a karthi Manne (no subject) 1...

1 answer below »
Code in C with Plots(Graphs)2 to 3 pages.


3/26/2018 Gmail - (no subject) https://mail.google.com/mail/u/0/?ui=2&ik=3fe50a2bf5&jsver=lr-NdqmOTUs.en.&view=pt&search=inbox&th=16260b9814b0609a&siml=16260b9814b0609a karthi Manne (no subject) 1 message mahender reddy Mon, Mar 26, 2018 at 4:13 PM To: karthi Manne #include #include int PSAP_StateMachine(int UpLinkChannel, int Operator, int ManualReset, int Sync, char *TX, int *RunModulator, int *RunDemodulator); void RecieveFrame(int *FrameDetected, int *CRC_check); int main() { int State; int UpLinkChannel, Operator, ManualReset, Sync; char TX[10]; int RunModulator; int RunDemodulator; UpLinkChannel = 0; Operator = 0; ManualReset = 0; Sync = 0; char Option; while(1) { State = PSAP_StateMachine(UpLinkChannel, Operator, ManualReset, Sync, &TX[0], &RunModulator, &RunDemodulator); if((kbhit())) { printf("\n \n Which Input you want to Change? u: UpLinkChannel o: Operator m: ManualReset s: Sync x: Exit"); printf("\n Please Enter your Option: "); getch(); Option = getch(); if(Option=='x') break; switch(Option) { case 'u': printf("\n\nEnter UpLinkChannel: "); scanf("%d", &UpLinkChannel); break; case 'o': printf("\n\nEnter Operator: "); scanf("%d", &Operator); break; case 'm': printf("\n\nEnter ManualReset: "); scanf("%d", &ManualReset); break; case 's': printf("\n\nEnter Sync: "); scanf("%d", &Sync); break; default: continue; } } } return 0; } int PSAP_StateMachine(int UpLinkChannel, int Operator, int ManualReset, int Sync, char *TX, int *RunModulator, int *RunDemodulator) { static int State=1; static int cnt_NumStartMsg=0; static int cnt_NumAckMsg =0; int FrameDetected, CRC_check; switch(State) { case 1: *RunModulator = 0; *RunDemodulator = 0; strcpy(TX,"No Processing"); printf("\nPsapIdle: State=%d, TX=%s, RunModulator=%d, RunDemodulator=%d\n", State, TX, *RunModulator, *RunDemodulator); if(UpLinkChannel==1 || Operator==1) { State = 2; } break; case 2: *RunModulator = 0; *RunDemodulator = 0; strcpy(TX,"Send Start msg"); printf("\nPsapIdle: State=%d, TX=%s, RunModulator=%d, RunDemodulator=%d\n", State, TX, *RunModulator, *RunDemodulator); cnt_NumStartMsg++; if(ManualReset==1) { cnt_NumStartMsg=0; State = 1; } else if(cnt_NumStartMsg==3) { cnt_NumStartMsg=0; State=3; } break; case 3: *RunModulator = 0; *RunDemodulator = 0; strcpy(TX,"Send Start msg"); printf("\nPsapStart: State=%d, TX=%s, RunModulator=%d, RunDemodulator=%d\n", State, TX, *RunModulator, *RunDemodulator); if(ManualReset==1) { State = 1; } else if(Sync==1) { *RunModulator = 1; State=4; } break; case 4: *RunModulator = 1; *RunDemodulator = 0; strcpy(TX,"Send Nack msg"); printf("\nPsapNack: State=%d, TX=%s, RunModulator=%d, RunDemodulator=%d\n", State, TX, *RunModulator, *RunDemodulator); RecieveFrame(&FrameDetected, &CRC_check); if(ManualReset==1) { State = 1; } else if(CRC_check==0) { State = 2; } else if(CRC_check==1) { *RunModulator = 0; *RunDemodulator = 1; State = 5; } break; case 5: *RunModulator = 0; *RunDemodulator = 1; strcpy(TX,"Send Ack msg"); printf("\nPsapNack: State=%d, TX=%s, RunModulator=%d, RunDemodulator=%d\n", State, TX, *RunModulator, *RunDemodulator); cnt_NumAckMsg++; if(cnt_NumAckMsg>=4) { cnt_NumAckMsg = 0; State = 1; } break; default: State=1; break; } return State; } void RecieveFrame(int *FrameDetected, int *CRC_check) { *FrameDetected=1; *CRC_check = 1; }
Answered Same DayMar 26, 2020

Answer To: 3/26/2018 Gmail - (no subject)...

Saurabh answered on Mar 28 2020
126 Votes
Solution/Code/ecall_defines.h#ifndef ECALL_DEFINES_H_
#define ECALL_DEFINES_H_
/*============================================================================*/
/* General conventions */
/* Display log messages by defining the following constants: */
/* */
/* #define LOG_IVS or makefile: DLOG_IVS */
/* #define LOG_PSAP or makefile: DLOG_PSAP */
/* #define LOG_SYNC or makefile: DLOG_SYNC */
/*----------------------------------------------------------------------------*/
typedef signed char Int8; /* 8 bit signed variable */
typedef signed short int Int16; /* 16 bit signed variable */
typedef signed int Int32; /* 32 bit signed variable */
typedef unsigned char Ord1; /* 1 bit variable */
typedef unsigned char Ord8; /* 8 bit unsigned variable */
typedef unsigned short int Ord16; /* 16 bit unsigned variable */
typedef unsigned int Ord32; /* 32 bit unsigned variable */
#define MAX(a,b) ((a)>(b) ? (a) : (b)) /* macr
o: maximum */
#define MIN(a,b) ((a)<(b) ? (a) : (b)) /* macro: minimum */
#define ABS(a) ((a)< 0 ? (-a) : (a)) /* macro: absolute value */
#define SIGN(a) ((a)< 0 ? (-1) : (1)) /* macro: sign */
#ifndef PCM_LENGTH
#define PCM_LENGTH (160) /* length of PCM frame in samples */
#endif
#ifndef MSD_MAX_LENGTH
#define MSD_MAX_LENGTH (140) /* length of MSD message in bytes */
#endif
/*============================================================================*/
/* Synchronization */
/*----------------------------------------------------------------------------*/
#define SYNC_EVENTS (3) /* IVS sync events required */
#define SYNC_BADCHECKS (8) /* IVS subsequent bad checks */
#define SYNC_IDXLEN (75) /* sync index length */
#define SYNC_THRESHOLD (10e6) /* sync threshold */
#define LOCK_START (3) /* START messages to lock sync */
#define FAIL_RESTART (3) /* START messages to restart */
#define NRF_WAKEUP (3) /* number of wakeup frames */
#define NRF_SYNC (13) /* number of sync frames */
#define NRF_SYNCOBSV (10) /* number of sync observe frames */
#define PNSEQ_OSF (22) /* oversampling of PN sequence */
#define PEAK_DIST_PP (30*PNSEQ_OSF) /* distance outer positive peaks */
#define PEAK_DIST_NN (54*PNSEQ_OSF) /* distance negative peaks */
#define PEAK_DIST_PN (12*PNSEQ_OSF) /* distance positive to negative */
/*============================================================================*/
/* Uplink/Downlink format */
/*----------------------------------------------------------------------------*/
#define ARQ_MAX (8) /* number of redundancy versions */
#define NRB_TAIL (3) /* number of encoder tail bits */
#define NRB_CRC (28) /* order of CRC polynomial */
#define NRB_INFO (8*MSD_MAX_LENGTH)
#define NRB_INFO_CRC (8*MSD_MAX_LENGTH + NRB_CRC)
#define NRB_CODE_ARQ (1380)
#define NRB_CODE_BUFFER (3*(8*MSD_MAX_LENGTH + NRB_CRC) + 4*NRB_TAIL)
#define NRF_DLDATA (3) /* downlink frames data */
#define NRF_DLMUTE1 (2) /* downlink frames 1st muting */
#define NRF_DLMUTE2 (2) /* downlink frames 2nd muting */
#define NRF_DLCHUNK (NRF_SYNC + NRF_DLMUTE1 + NRF_DLDATA + NRF_DLMUTE2)
/*============================================================================*/
/* IVS/PSAP processing */
/*----------------------------------------------------------------------------*/
#define NRF_MEMIVS (5) /* buffer size in frames */
#define NRF_MEMPSAP (2) /* buffer size in frames */
#define NRS_MEMSYNC (820) /* buffer size in samples */
#define IVS_THRESHOLD (40000) /* threshold feedback messages */
#define IVS_GOSTART (6) /* threshold for unreliable START */
#define IVS_TXFAST (10) /* fast modulator NACK condition */
#define IVS_TXINC (87) /* sample increment at restart */
#define FEC_VAR (30206) /* variance: 1/4550000 in Q37 */
#define FEC_MEAN (0xB9999A) /* mean: 5.8 in Q21 */
#define FEC_ITERATIONS (8) /* number of decoder iterations */
#define FEC_STATES (8) /* number of decoder states */
#define IntLLR Int16
#define LLR_MAX ((Int32)(0x7fff-1))
#define LOGEXP_RES (401) /* resolution of logexp table */
#define LOGEXP_DELTA (-6) /* internal Q-factor */
#define LOGEXP_QIN (8) /* input Q-factor of LLR values */
#endif
Solution/Code/ecall_fec.h#ifndef ECALL_FEC_H_
#define ECALL_FEC_H_
#include "ecall_defines.h"
#include "ecall_rom.h"
/*============================================================================*/
/* Encoder functions */
/*----------------------------------------------------------------------------*/
void FecEncode(Ord1*);
void AttachCrc(const Ord1*, Ord1*);
void Scramble(const Ord1*, Ord1*);
void EncodeTwo(Ord1*);
void EncodeOne(Ord1*, Int16);
/*============================================================================*/
/* Decoder functions */
/*----------------------------------------------------------------------------*/
Ord1 FecDecode(const IntLLR*, Int16, Ord1*);
void UpdateBuffer(IntLLR*, const IntLLR*, Int16);
void DecodeBuffer(const IntLLR*, const IntLLR*,
const IntLLR*, const IntLLR*, Ord1*);
Ord1 DecodeCrc(const Ord1*);
void Interleave(const IntLLR*, IntLLR*);
void Deinterleave(IntLLR*);
void Descramble(Ord1*);
void Bcjr(const IntLLR*, IntLLR*);
IntLLR GammaQ(Int16, Int16, const IntLLR*, const IntLLR*);
IntLLR JacLog(Int32, Int32);
#endif
Solution/Code/ecall_modem.h#ifndef ECALL_MODEM_H_
#define ECALL_MODEM_H_
#include "ecall_defines.h"
typedef enum {
Mod3bit4smp,
Mod3bit8smp
} ModType;
typedef struct {
Int16 bpsym; /* bits per symbol */
Int16 spmf; /* samples per modulation frame */
Int16 mfpf; /* modulation frames per frame = PCM_LENGTH/spmf */
Int16 decpos1; /* position 1st decoding trial */
Int16 decpos2; /* position 2nd decoding trial */
Int16 wutperiod; /* wakeup tone period in samples */
Int16 nfmute1; /* number of muting frames 1st interval */
Int16 nfmute4; /* number of muting frames 4th interval */
Int16 nfmuteall; /* number of muting frames total */
Int16 nfdata; /* number of data frames = NRB_CODE_ARQ/(mfpf*bpsym) */
const Int16 *ulPulse;
const Int16 *ulPulseMatch;
const Int16 *mgTable;
const Int16 *wakeupSin;
const Int16 *wakeupCos;
} ModState;
/*============================================================================*/
/* Modem functions */
/*----------------------------------------------------------------------------*/
void SetModState(ModState*, ModType);
void IvsTransmitter(const ModState*, const Ord1*, Int16*, Int16, Int16);
Int16 IvsReceiver(const Int16*, Int32*);
void PsapTransmitter(Int16*, Int16, Int16);
void PsapReceiver(const ModState*, const Int16*, IntLLR*);
void SymbolMod(const ModState*, Int16, Int16*);
void SymbolDemod(const ModState*, const Int16*, IntLLR*);
void Byte2Bit(const Ord8*, Ord1*, Int16);
void Bit2Byte(const Ord1*, Ord8*, Int16);
Int32 MpyLacc(Int32, Int16);
#endif
Solution/Code/ecall_rom.h#ifndef ECALL_ROM_H_
#define ECALL_ROM_H_
#include "ecall_defines.h"
/*============================================================================*/
/* Synchronization */
/*----------------------------------------------------------------------------*/
const Int16 wakeupSin500[16];
const Int16 wakeupCos500[16];
const Int16 wakeupSin800[10];
const Int16 wakeupCos800[10];
const Int16 syncPulseForm[5];
const Int16 syncSequence[15];
const Int16 syncIndexPreamble[SYNC_IDXLEN];
const Int16 syncFrame[1600];
/*============================================================================*/
/* Uplink/Downlink format */
/*----------------------------------------------------------------------------*/
const Int16 indexBits[24];
const Int16 m4smp_ulPulse[16];
const Int16 m8smp_ulPulse[32];
const Int16 m4smp_ulPulseMatch[64];
const Int16 m8smp_ulPulseMatch[128];
const Int16 m4smp_mgTable[54];
const Int16 m8smp_mgTable[104];
const Int16 dlPcmData[4][NRF_DLDATA*PCM_LENGTH];
const Int16 dlPcmDataMatch[4][NRF_DLDATA*PCM_LENGTH];
/*============================================================================*/
/* FEC encoder/decoder */
/*----------------------------------------------------------------------------*/
const Ord16 stateTrans[16];
const Ord16 revStateTrans[16];
const Ord1 outputParity[16];
const Ord1 crcPolynomial[NRB_CRC+1];
const Ord1 scramblingSeq[NRB_INFO_CRC];
const Ord16 interleaverSeq[NRB_INFO_CRC];
const Ord16 redVerIndex[8][NRB_CODE_ARQ];
const IntLLR logExpTable[LOGEXP_RES];
#endif
Solution/Code/ecall_sync.h#ifndef ECALL_SYNC_H_
#define ECALL_SYNC_H_
#include "ecall_defines.h"
typedef struct {
Int32 *state;
Int32 *wakeupState; /* memory for wakeup tone detector */
Int32 amplitude[3]; /* amplitudes (average, maximum, memory) */
Int16 corrIndex[4]; /* position of sync check */
Int32 checkMem[4]; /* correlation value memory of sync check */
Int16 peakPos[4]; /* position of sync peaks within feedback message */
Int16 checkCounter; /* counts subsequent sync check failures */
Int16 obsvCounter; /* counts frames after successful sync */
Int16 msgCounter; /* counts feedback messages */
Int16 index; /* frame reference for sync evaluation */
Int16 offset; /* frame offset */
Int16 delay; /* synchronization delay (position) */
Int16 tempDelay; /* temporary delay in two-stage peak evaluation */
Int16 prevDelay; /* previous sync delay */
Int16 trials; /* number of sync trials */
Int16 npeaks; /* number of sync peaks detected */
Int16 events; /* number of subsequent equal sync events */
Ord1 flag; /* indicates successful sync */
Ord1 checkOk; /* indicates successful sync check */
} SyncState;
/*============================================================================*/
/* Sync functions */
/*----------------------------------------------------------------------------*/
void EcallSync(SyncState*, const Int16*, const char*);
void EcallSyncCheck(SyncState*, const Int16*);
void ToneDetect(SyncState*, const Int16*);
Int16 UpdatePeak(const Int32*, const Int32*, Int16);
void CheckPosPeaks(SyncState*, const char*, const Int32*,
Int16, Int16, Int16, Int16, Int16);
void CheckNegPeaks(SyncState*, const char*, const Int32*,
Int16, Int16, Int16, Int16, Int16);
#endif
Solution/Code/modemx.h#ifndef MODEMX_H_
#define MODEMX_H_
#include "ecall_defines.h"
#include "ecall_modem.h"
#include "ecall_sync.h"
typedef enum {
DlMsgStart,
DlMsgNack,
DlMsgAck,
DlMsgIdle
} DlData;
void Abort(const char *format, ...);
/*============================================================================*/
/* IVS declarations */
/*----------------------------------------------------------------------------*/
void IvsReset(const Ord8 *msd, int length);
void IvsProcess(Int16 *pcm);
void IvsProcessSync(const Int16 *pcm);
void IvsProcessState(const Int16 *buffer);
typedef enum {
IvsIdle,
IvsSendMsd
} IvsState;
typedef struct {
ModState mod; /* IVS modulator struct */
SyncState sync; /* IVS sync struct */
Int32 syncBuffer[NRS_MEMSYNC];
Int16 delayBuffer[2*PCM_LENGTH];
Int16 pcmBuffer[NRF_MEMIVS*PCM_LENGTH];
Ord1 bitBuffer[NRB_CODE_BUFFER];
Int16 state; /* IVS state */
Int16 stateCnt[4]; /* state counters */
Int16 startCntIgnore; /* counts unreliable START messages */
Int16 globalNackCnt; /* counts NACK messages */
Int16 txN; /* TX number of frames */
Int16 txIndex; /* TX frame counter */
Int16...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here