您的位置:首页 > 大数据 > 物联网

【物联网感知技术】:RFID编码的实现

2015-09-18 14:03 489 查看
背景知识

关于各种编码的问题: RFID编码有很多种吧,这里选取部分来写

反向不归零码 遇到1保持,遇到0变化

差动码 遇到1变化,遇到0保持

曼彻斯特编码

在半个比特(bit)周期时的下降沿表示二进制“1”,半个比特周期时的上升沿表示二进制“0”

 也被称作分相编码(Split-Phase Coding) 助记为:1下降沿 0上升沿

单极性归零码 在曼彻斯特码的基础上 ,0变作保持

米勒码 在曼彻斯特码的基础上,遇见1就变,遇到0不动



做题及实现思路

反向不归零码 和 差动码 都是画: ~~ 或者 __ ~~代表上面那条横线 __代表下面那条横线

曼彻斯特码 单极性归零码 米勒码 都是 画 ~|_ _|~类似于这种

基本构件知道了,我们只需要按照一定的编程规则就把这些构件联系起来就可以了~ (建议自己动脑想想,我给出了代码,可以参考)

代码

///////////////////////////////////////  图的转换

#include <iostream>
#include <string>
using namespace std;
string s;
void OriginPic(string s){ //原图
//	cout<<"原图"<<endl<<endl;
	cout<<"_";
	if(s[0]-'0'==1) cout<<"|~~";   //关于char型转换为数字的技巧
	else cout<<"__";
	for(int i=1;i<s.length();i++){
		if(s[i]==s[i-1]){
			if(s[i-1]-'0'==1){
				cout<<"~~";
			}
			else  cout<<"__";
		}
		if(s[i]!=s[i-1]){
			if(s[i-1]-'0'==1) cout<<"|__";
			else cout<<"|~~";
		}
	}	
}
void Fanxiang(string s){  //反向不归零码
	string temp,k="~~",t="__";
	cout<<"~";
	if(s[0]-'0'==1){ cout<<k;temp = k; }
	if(s[0]-'0'==0){cout<<"|"<<t;temp=t;}
	for(int i=1;i<s.length();i++){
		if(s[i]-'0'==1) cout<<temp;
		if(s[i]-'0'==0){
			cout<<"|";
			if(temp==k){ cout<<t; temp =t;}
			else {cout<<k; temp = k;}
		}
	}
}
void Manche(string s){  //曼彻斯特码
	string k="~|_",t="_|~";
	cout<<"-";
	if(s[0]-'0'==1) cout<<k;  //初始化
	else cout<<t;
	for(int i=1;i<s.length();i++){
		if(s[i]==s[i-1]){
			cout<<"|";
			if(s[i]-'0'==1) cout<<k;
			else cout<<t;
		}
		else{
			if(s[i]-'0'==1) cout<<k;
			else cout<<t;
		}
	}
}
void unipolar(string s){  //单极性归零编码 ,比满切斯特编码又简单了一些
	string k="~|_",t="__";
	cout<<"-";
	if(s[0]-'0'==1) cout<<k;
	else cout<<t;
	for(int i=1;i<s.length();i++){
		if(s[i]-'0'==1) cout<<"|"<<k;
		else cout<<t;
	}
}
void miler(string s){              //米勒编码有问题
	string k="~|_",t="_|~",m="__",temp;  //temp用来记录状态
	cout<<"-";
	if(s[0]-'0'==0){ cout<<m; temp=m;}
	else {cout<<k; temp=k;}
	for(int i=1;i<s.length();i++){
		if(s[i-1]-'0'==0 && s[i]-'0'==1){
			cout<<t;
			temp =t;
		}
		if(s[i-1]-'0'==0 && s[i]-'0'==0){
			cout<<m;
		}
		if(s[i-1]-'0'==1 && s[i]-'0'==1){
			if(temp==k){
				cout<<t;
				temp =t;
			}
			else{
				cout<<k;
				temp = k;
			}
		}
		if(s[i-1]-'0'==1 && s[i]-'0'==0){
				if(temp==t){
					cout<<"~~";  //保持不变
				}
				else{
					cout<<m;
				}
		}
	}
}
void chadong(string s){  //差动码
	string temp,k="~~",t="__";
	cout<<"~";        // 差动码默认初次是高电平
	if(s[0]-'0'==1){cout<<"|"<<t;temp=t;}
	else {cout<<k;temp = k;}
	for(int i=1;i<s.length();i++){
		if(s[i]-'0'==1){
			if(temp==k){
				cout<<"|"<<t;
				temp =t;
			}
			else {
				cout<<"|"<<k;
				temp = k;
			}
		}
		else{
			cout<<temp;
		}
	}

}
void main(){  //每个0用两个下划线表示,每个1用两个~~表示
	cin>>s;
	cout<<endl<<"原图为:"<<endl;
	OriginPic(s);
	cout<<endl<<endl<<"反向不归0码为:"<<endl;
	Fanxiang(s);
	cout<<endl<<endl<<"曼彻斯特码为:"<<endl;
	Manche(s);
	cout<<endl<<endl<<"单极性归零码为:"<<endl;
	unipolar(s);
	cout<<endl<<endl<<"米勒码为:"<<endl;
	miler(s);
	cout<<endl<<endl<<"差动码为:"<<endl;
	chadong(s);
	cout<<endl;
	system("pause");
}








内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: