找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1667|回复: 2
打印 上一主题 下一主题
收起左侧

请问DSP中普通软件锁相环如何编写?

[复制链接]
跳转到指定楼层
楼主
请问DSP中普通软件锁相环如何编写?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:155507 发表于 2022-8-18 19:33 | 只看该作者
源代码在单个文件中预先提供,并对其操作进行了完整描述。 编译后,程序将运行锁相环的模拟,生成一个数据文件,该文件可以使用 Gnuplot 或 Octave 绘制。

  1. // simulate a phase-locked loop
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <complex.h>
  5. #include <math.h>

  6. int main() {
  7.     // parameters
  8.     float        phase_offset     = 0.00f;  // carrier phase offset
  9.     float        frequency_offset = 0.30f;  // carrier frequency offset
  10.     float        wn               = 0.01f;  // pll bandwidth
  11.     float        zeta             = 0.707f; // pll damping factor
  12.     float        K                = 1000;   // pll loop gain
  13.     unsigned int n                = 400;    // number of samples

  14.     // generate loop filter parameters (active PI design)
  15.     float t1 = K/(wn*wn);   // tau_1
  16.     float t2 = 2*zeta/wn;   // tau_2

  17.     // feed-forward coefficients (numerator)
  18.     float b0 = (4*K/t1)*(1.+t2/2.0f);
  19.     float b1 = (8*K/t1);
  20.     float b2 = (4*K/t1)*(1.-t2/2.0f);

  21.     // feed-back coefficients (denominator)
  22.     //    a0 =  1.0  is implied
  23.     float a1 = -2.0f;
  24.     float a2 =  1.0f;

  25.     // print filter coefficients (as comments)
  26.     printf("#  b = [b0:%12.8f, b1:%12.8f, b2:%12.8f]\n", b0, b1, b2);
  27.     printf("#  a = [a0:%12.8f, a1:%12.8f, a2:%12.8f]\n", 1., a1, a2);

  28.     // filter buffer
  29.     float v0=0.0f, v1=0.0f, v2=0.0f;
  30.    
  31.     // initialize states
  32.     float phi     = phase_offset;   // input signal's initial phase
  33.     float phi_hat = 0.0f;           // PLL's initial phase
  34.    
  35.     // run basic simulation
  36.     unsigned int i;
  37.     float complex x, y;
  38.     printf("# %6s %12s %12s %12s %12s %12s\n",
  39.             "index", "real(x)", "imag(x)", "real(y)", "imag(y)", "error");
  40.     for (i=0; i<n; i++) {
  41.         // compute input sinusoid and update phase
  42.         x = cosf(phi) + _Complex_I*sinf(phi);
  43.         phi += frequency_offset;

  44.         // compute PLL output from phase estimate
  45.         y = cosf(phi_hat) + _Complex_I*sinf(phi_hat);

  46.         // compute error estimate
  47.         float delta_phi = cargf( x * conjf(y) );

  48.         // print results to standard output
  49.         printf("  %6u %12.8f %12.8f %12.8f %12.8f %12.8f\n",
  50.             i, crealf(x), cimagf(x), crealf(y), cimagf(y), delta_phi);

  51.         // push result through loop filter, updating phase estimate
  52.         v2 = v1;  // shift center register to upper register
  53.         v1 = v0;  // shift lower register to center register
  54.         v0 = delta_phi - v1*a1 - v2*a2; // compute new lower register

  55.         // compute new output
  56.         phi_hat = v0*b0 + v1*b1 + v2*b2;
  57.     }
  58.     return 0;
  59. }
复制代码

liquid_pll_example.zip

3.18 KB, 下载次数: 10

9_sithamparanathan.pdf

321.58 KB, 下载次数: 8

abineau_dpll_analysis.pdf

557.39 KB, 下载次数: 8

回复

使用道具 举报

板凳
ID:123289 发表于 2022-8-19 11:31 | 只看该作者
需带有锁相环的芯片,才行。依芯片手册操作。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表