1

我正在尝试编写一个调制函数,参考下面的函数。我不是电气工程师,对信号处理了解不多。

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

4

1 回答 1

0

bytes2signal()您在此处的代码片段采用二进制数据(位01),并使用两个不同的频率(NFREQ用于位0-NFREQ1)对它们进行编码。这种调制称为二进制频移键控 (BFSK),是从比特到频率的映射。

如果您愿意,FSK 可以处理非二进制数据(例如,您可以将 2 位映射到一个频率:00=> f101=> f210=>f311=> f4,对于某些频率f1f2f3f4)。在您的示例中,您似乎有一个从字母表 { 01-1} 中提取的输入数据序列,因此您可以轻松地将每个值映射到 3 个频率之一(例如-1=> -FREQ0=> 0+1=> +FREQ)。

但是,我不清楚这是否真的是您想要的。您提到“扩频信号”,所以我猜您正在寻找扩频通信?

如果是这样,对于 BFSK,进行扩频的“标准”方法是跳频,仍然根据位 0 和 1 选择两个频率之一,但根据时间改变这两个频率。这称为跳频 BFSK (FH-BFSK)。如果采用这种方法,输入序列仍然是二进制的;您所做的只是用一个循环时间的频率查找表中的两个频率替换-NFREQ和替换。FREQ

进行扩频通信的另一种常见方法是使用扩频码将每个比特扩展为比特序列(例如0=>10011=> 1010),并要求序列是正交的。然后以更高的信号速率调制“扩展”位(在上面的示例中,增加SAMPLES_PER_SYMBOL4 倍,并增加NFREQ4 倍以适应增加的带宽)。这称为直接序列扩频 (DSSS),通常用于CDMA等系统。但是,请注意“扩展”位序列仍然是二进制的(并且没有 3 级 { -1, 0, +1} 就像您在问题中所说的那样)。

请注意,DSSS 更常用于二进制相移键控 (BPSK),而不是 BFSK。

于 2021-01-07T19:39:26.750 回答