我正在尝试写一个调制函数,参考下面的函数。我不是电气工程师,对信号处理不太了解。
private final int SAMPLES_PER_SYMBOL = 150
private final float NFREQ = 1/15
private float[] bytes2signal(byte[] buf) {
float[] signal = new float[buf.length * 8 * SAMPLES_PER_SYMBOL * 2] // 8 bits/byte, 2 floats/sample
int p = 0
for (int i = 0; i < buf.length; i++) {
for (int j = 0; j < 8; j++) {
int bit = (buf[i] >> j) & 0x01
float f = bit == 1 ? -NFREQ : NFREQ
for (int k = 0; k < SAMPLES_PER_SYMBOL; k++) {
signal[p++] = (float)Math.cos(2 * Math.PI * f * k)
signal[p++] = (float)Math.sin(2 * Math.PI * f * k)
}
}
}
return signal
}但是我的缓冲信号实际上有非二进制数据(这是扩展信号),即我的buf数组的第一个元素是-1,0,0,-1,0,1,1,0。
如何使用此调制功能对扩展信号进行调制?我对for循环中正在发生的事情并不感到困惑。
为了更好地理解这一点,我已经静态地转换了数据,请参阅下面。
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World");
//JAVA BYTE ARRAY DECLARATION
byte Bytesdata[];
//MEMORY ALLOCATION FOR JAVA BYTE ARRAY
Bytesdata = new byte[4];
//ASSIGNING ELEMENTS TO JAVA BYTE ARRAY
Bytesdata[0] = 20;
Bytesdata[1] = 10;
Bytesdata[2] = 30;
Bytesdata[3] = 5;
//BYTE ARRAY OUTPUT
int sourcestation = 2;
int[][] wtable = new int[][]{
{ 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, -1, 1, -1, -1, 1, 1, -1},
{ -1, -1, 1, -1, 1, -1, -1, 1},
{ 1, -1, 1, -1, -1, 1, 1, -1},
{ 1, 1, -1, 1, -1, 1, -1, -1},
{ 1, -1, 1, -1, -1, 1, 1, -1},
{ -1, -1, 1, -1, -1, -1, 1, 1},
{ 1, -1, 1, 1, -1, -1, 1, 1},
};
int[][] results = new int[wtable.length][wtable[0].length];
int pos = 0;
System.out.println(Bytesdata.length);
for (int i = 0; i < Bytesdata.length; i++) {
System.out.println(Bytesdata[i]);
System.out.println("Binary is " + (Integer.toBinaryString(Bytesdata[i])) );
System.out.println("Byte is " + getByte(Bytesdata[i]));
int j = 0;
while (j < wtable.length) {
System.out.println("j: "+j);
results[i][j] = wtable[sourcestation][j] * getBit(Bytesdata, pos);
System.out.println("wtable["+sourcestation+"]["+j+"]: "+wtable[sourcestation][j]);
System.out.println("Position: "+pos);
System.out.println("Data Bit: "+getBit(Bytesdata, pos));
System.out.println("Result: "+results[i][j]);
System.out.println("---------------------------");
j+=1;
pos+=1;
}
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
System.out.print(results[i][j]+", ");
}
System.out.print("\n");
}
final int HDRSIZE = 5;
final int SAMPLES_PER_SYMBOL = 150;
final float NFREQ = 1/15;
float[] signal = new float[Bytesdata.length * 8 * SAMPLES_PER_SYMBOL * 2];
int p = 0;
for (int i = 0; i < Bytesdata.length; i++) {
for (int j = 0; j < 8; j++) {
int bit = (Bytesdata[i] >> j) & 0x01;
float f = bit == 1 ? -NFREQ : NFREQ;
for (int k = 0; k < SAMPLES_PER_SYMBOL; k++) {
signal[p++] = (float)Math.cos(2 * Math.PI * f * k);
signal[p++] = (float)Math.sin(2 * Math.PI * f * k);
}
}
}
System.out.println(signal);
// System.out.println("Binary is " + (Integer.toBinaryString(signal)));
}
private static int getBit(byte[] data, int pos) {
int posByte = pos/8;
int posBit = pos%8;
byte valByte = data[posByte];
int valInt = valByte>>(8-(posBit+1)) & 0x0001;
return valInt;
}
private static String getByte(Byte b){
String temp = Integer.toBinaryString(b);
while(temp.length() < 8){
temp = "0" + temp;
}
return temp;
}
}我认为我的输出似乎是正确的。
Hello World
4
20
Binary is 10100
Byte is 00010100
j: 0
wtable[2][0]: -1
Position: 0
Data Bit: 0
Result: 0
---------------------------
j: 1
wtable[2][1]: -1
Position: 1
Data Bit: 0
Result: 0
---------------------------
j: 2
wtable[2][2]: 1
Position: 2
Data Bit: 0
Result: 0
---------------------------
j: 3
wtable[2][3]: -1
Position: 3
Data Bit: 1
Result: -1
---------------------------
j: 4
wtable[2][4]: 1
Position: 4
Data Bit: 0
Result: 0
---------------------------
j: 5
wtable[2][5]: -1
Position: 5
Data Bit: 1
Result: -1
---------------------------
j: 6
wtable[2][6]: -1
Position: 6
Data Bit: 0
Result: 0
---------------------------
j: 7
wtable[2][7]: 1
Position: 7
Data Bit: 0
Result: 0
---------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
10
Binary is 1010
Byte is 00001010
j: 0
wtable[2][0]: -1
Position: 8
Data Bit: 0
Result: 0
---------------------------
j: 1
wtable[2][1]: -1
Position: 9
Data Bit: 0
Result: 0
---------------------------
j: 2
wtable[2][2]: 1
Position: 10
Data Bit: 0
Result: 0
---------------------------
j: 3
wtable[2][3]: -1
Position: 11
Data Bit: 0
Result: 0
---------------------------
j: 4
wtable[2][4]: 1
Position: 12
Data Bit: 1
Result: 1
---------------------------
j: 5
wtable[2][5]: -1
Position: 13
Data Bit: 0
Result: 0
---------------------------
j: 6
wtable[2][6]: -1
Position: 14
Data Bit: 1
Result: -1
---------------------------
j: 7
wtable[2][7]: 1
Position: 15
Data Bit: 0
Result: 0
---------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
30
Binary is 11110
Byte is 00011110
j: 0
wtable[2][0]: -1
Position: 16
Data Bit: 0
Result: 0
---------------------------
j: 1
wtable[2][1]: -1
Position: 17
Data Bit: 0
Result: 0
---------------------------
j: 2
wtable[2][2]: 1
Position: 18
Data Bit: 0
Result: 0
---------------------------
j: 3
wtable[2][3]: -1
Position: 19
Data Bit: 1
Result: -1
---------------------------
j: 4
wtable[2][4]: 1
Position: 20
Data Bit: 1
Result: 1
---------------------------
j: 5
wtable[2][5]: -1
Position: 21
Data Bit: 1
Result: -1
---------------------------
j: 6
wtable[2][6]: -1
Position: 22
Data Bit: 1
Result: -1
---------------------------
j: 7
wtable[2][7]: 1
Position: 23
Data Bit: 0
Result: 0
---------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
5
Binary is 101
Byte is 00000101
j: 0
wtable[2][0]: -1
Position: 24
Data Bit: 0
Result: 0
---------------------------
j: 1
wtable[2][1]: -1
Position: 25
Data Bit: 0
Result: 0
---------------------------
j: 2
wtable[2][2]: 1
Position: 26
Data Bit: 0
Result: 0
---------------------------
j: 3
wtable[2][3]: -1
Position: 27
Data Bit: 0
Result: 0
---------------------------
j: 4
wtable[2][4]: 1
Position: 28
Data Bit: 0
Result: 0
---------------------------
j: 5
wtable[2][5]: -1
Position: 29
Data Bit: 1
Result: -1
---------------------------
j: 6
wtable[2][6]: -1
Position: 30
Data Bit: 0
Result: 0
---------------------------
j: 7
wtable[2][7]: 1
Position: 31
Data Bit: 1
Result: 1
---------------------------
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
0, 0, 0, -1, 0, -1, 0, 0,
0, 0, 0, 0, 1, 0, -1, 0,
0, 0, 0, -1, 1, -1, -1, 0,
0, 0, 0, 0, 0, -1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
[F@6d06d69c在原有的modulation函数中,有基于1 or 0的决策。我怎样才能调节我的信号?
0, 0, 0, -1, 0, -1, 0, 0,
0, 0, 0, 0, 1, 0, -1, 0,
0, 0, 0, -1, 1, -1, -1, 0,
0, 0, 0, 0, 0, -1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 我做错什么了吗?如何动态地为element-by-element进行乘法?
发布于 2021-01-07 19:39:26
这里为bytes2signal()编写的代码片段接受二进制数据(位0和1),并使用两个不同的频率对它们进行编码(NFREQ表示位0,-NFREQ表示位1)。这种调制被称为二进制频移键控(BFSK),是从比特到频率的映射。
如果您愿意,FSK可以处理非二进制数据(例如,对于某些频率( f2、f3和f4),可以将2位映射到一个频率:00 => f1、01 => f2、10 => f3和11 => f4 )。在您的示例中,您似乎有一个从字母表{0、1、-1}中提取的输入数据序列,因此您可以轻松地将每个值映射到3个频率中的一个(例如-1 => -FREQ、0 => 0、+1 => +FREQ)。
然而,我不清楚这是否真的是你的意愿。你提到了“扩展信号”,所以我猜你是想做扩频通信?
如果是这样的话,对于BFSK来说,做扩频的“标准”方法是跳过频率,仍然根据位数0和1选择两个频率中的一个,但随着时间的变化而改变哪两个频率。这被称为跳频BFSK (FH).如果您采用这种方法,则输入序列仍然是二进制的;您所更改的只是将-NFREQ和FREQ替换为一个循环时间的频率查找表中的两个频率。
进行扩频通信的另一种常见方法是使用扩频码将每个比特扩展为一个比特序列(例如0 => 1001和1 => 1010),并要求这些序列是正交的。然后,“扩展”比特以更高的信令速率被调制(在上面的例子中,通过增加SAMPLES_PER_SYMBOL 4倍,通过增加NFREQ 4来适应增加的带宽)。这被称为直接序列扩频(DSSS),通常用于码分多址等系统。但是,请注意,“扩展”位序列仍然是二进制的(并且没有像在您的问题中那样有3个级别{-1、0、+1} )。
但请注意,DSSS更常用于二进制相移键控(BPSK),而不是BFSK。
https://stackoverflow.com/questions/65570141
复制相似问题