基带传输编码解码代码(ami,cmi,manchester)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
a=n/2; b=n%2; sum+=(1<<(m-i))*b; n=a; } sum=sum+n; return sum; } 旋转因子: #include "wchange.h"
void wchange(float p,float n,float *a,float *b)//a为实部,b为虚 部
} void deamistream(FILE *filein,FILE *fileout) {
long fstr; int i,k; char ch; fseek(filein,0,SEEK_END); fstr=ftell(filein); fseek(filein,0,SEEK_SET); for(i=0;i<fstr;i++) {
fs=fopen("code.cds","r"); fami=fopen("ami.cds","w+r"); fmanchester=fopen("manchester.cds","w+r"); fhdb3=fopen("hdb3.cds","w+r"); fcmi=fopen("cmi.cds","w+r"); fdeami=fopen("deami.cds","w+r"); fdecmi=fopen("decmi.cds","w+r"); fdemanchester=fopen("demanchester.cds","w+r"); fseek(fs,0,SEEK_END);
{ *a=(float)cos(2*pie*p/n); *b=(float)sin(2*pie*p/n); //cout<<*a<<" "<<*b;
} 蝴蝶运算:
#include "bfchange.h"
void bfchange(cds *x,cds *y,cds w) {
cds temp1,temp2;
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); k=atoi(&ch); cmi(k,fileout); } } void decmistream(FILE *filein,FILE *fileout) {
long fstr; int i,k,l; char ch; fseek(filein,0,SEEK_END); fstr=ftell(filein); fseek(filein,0,SEEK_SET); for(i=0;i<fstr/2;i++) {
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); k=atoi(&ch); deami(k,fileout); }
} Cmi函数部分:
#include "cmi.h" void cmi(int n,FILE *file) {
if(n==0) {
#define N 1<<3
void main() {
int i,l,j,n,p; int d; /*int a[N]; int b[N],c[N]; int temp=0; a[0]=temp; cout<<a[0]<<" "; for(i=1;i<N;i++)//倒序测试 {
a[i]=reorder(temp,3); temp=a[i];
} void demanchester(int m,int n,FILE *file)
{ if(m==1&&n==0) fwrite("1",sizeof(char),1,file); else fwrite("0",sizeof(char),1,file);
} void manchstream(FILE *filein,FILE *fileout) {
fclose(fs);
fclose(fmanchester); fclose(fcmi); fclose(fami); fclose(fdeami); fclose(fdecmi); fclose(fdemanchester); } Ami函数部分: #include "ami.h"
void ami(int n,FILE *file) {
if(n==0) fwrite("0",sizeof(char),1,file); else {
t++;Baidu Nhomakorabeaif(t%2==1)
fwrite("2",sizeof(char),1,file); else fwrite("1",sizeof(char),1,file); } } void deami(int n,FILE *file) { if(n==0) fwrite("0",sizeof(char),1,file); if(n==1) fwrite("1",sizeof(char),1,file); if(n==2) fwrite("1",sizeof(char),1,file); } void amistream(FILE *filein,FILE *fileout) { long fstr; int i,k;
fwrite("01",sizeof(char),2,file); } else {
cmi_t++; if(cmi_t%2==0)
fwrite("11",sizeof(char),2,file); else
fwrite("00",sizeof(char),2,file); } } void decmi(int m,int n,FILE *file) { if((m+n)==2||(m+n)==0)
实验结果截图及代码: 1. 基带传输截图及主要代码:
2.主要代码 主函数: #include "cmi.h" #include "hdb3.h" void main() { FILE
*fs,*fami,*fmanchester,*fcmi,*fhdb3,*fdeami,*fdecmi,*fdemanchester;
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); k=atoi(&ch); memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); l=atoi(&ch); decmi(k,l,fileout); } }
char ch; fseek(filein,0,SEEK_END); fstr=ftell(filein); fseek(filein,0,SEEK_SET); for(i=0;i<fstr;i++) {
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); k=atoi(&ch); ami(k,fileout); }
fwrite("1",sizeof(char),1,file); if((m+n)==1)
fwrite("0",sizeof(char),1,file); } void cmistream(FILE *filein,FILE *fileout) {
long fstr; int i,k; char ch; fseek(filein,0,SEEK_END); fstr=ftell(filein); fseek(filein,0,SEEK_SET); for(i=0;i<fstr;i++) {
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); k=atoi(&ch);
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); l=atoi(&ch); demanchester(k,l,fileout); }
}
2. DIF_FFT截图及主要代码:
DIF_FFT结果截图 2.主要代码: 主函数:
#include <iostream.h> #include <memory.h> #include "bichange.h" #include "reorder.h" #include "wchange.h" #include "bfchange.h" #include "linecal.h"
} 倒序主要代码:
#include "reorder.h"
int reorder(int n,int m) {
int temp,re; temp=bichange(n,m); temp++; re=bichange(temp,m); return re; } int bichange(int n,int m) { int sum=0; int i; int a,b; for(i=1;i<m;i++) {
} void demanchstream(FILE *filein,FILE *fileout) {
long fstr; int i,k,l; char ch; fseek(filein,0,SEEK_END); fstr=ftell(filein); fseek(filein,0,SEEK_SET); for(i=0;i<fstr/2;i++) {
cout<<a[i]<<" "; }
cds x,y,z,w; x.i=1;x.j=0; y.i=1;y.j=0; z.i=0;z.j=8; wchange(0,8,&w.i,&w.j);//蝴蝶交换测试 bfchange(&x,&y,w);
memset(b,0,8); memset(c,0,8);*/ cds A[N]; cds temp; for(i=0;i<N;i++) {
Manchester函数部分: #include "manchester.h" void manchester(int n,FILE *file) { if(n==0) { fwrite("0",sizeof(char),1,file); fwrite("1",sizeof(char),1,file); } else { fwrite("1",sizeof(char),1,file); fwrite("0",sizeof(char),1,file); }
temp1.i=x->i+(y->i)*w.i-(y->j)*w.j; temp1.j=x->j+(y->i)*w.j+(y->j)*w.i;
temp2.i=x->i-(y->i)*w.i+(y->j)*w.j; temp2.j=x->j-(y->i)*w.j-(y->j)*w.i; x->i=temp1.i; x->j=temp1.j; y->i=temp2.i; y->j=temp2.j; cout<<x->i<<x->j<<endl; cout<<y->i<<y->j<<endl;
A[i].i=A[i].j=1; } for(l=1;l<=3;l++) { for(i=0;i<(1<<(3-l));i++) {
d=i*(1<<l); for(j=0;j<(1<<(l-1));j++) {
p=j; wchange(p,N,&temp.i,&temp.j); bfchange(&A[d],&A[d+(1<<(l-1))],temp); } } }
amistream(fs,fami); fseek(fami,0,SEEK_SET); deamistream(fami,fdeami); fseek(fs,0,SEEK_SET); cmistream(fs,fcmi); fseek(fcmi,0,SEEK_SET); decmistream(fcmi,fdecmi); fseek(fs,0,SEEK_SET); manchstream(fs,fmanchester); fseek(fmanchester,0,SEEK_SET); demanchstream(fmanchester,fdemanchester);
long fstr; int i,k; char ch; fseek(filein,0,SEEK_END); fstr=ftell(filein); fseek(filein,0,SEEK_SET); for(i=0;i<fstr;i++) {
memset(&ch,NULL,sizeof(char)); fread(&ch,1,1,filein); k=atoi(&ch); manchester(k,fileout); }
相关文档
最新文档