I am trying to implement a 2nd order PLL for my OQPSK receiver simulation(in Matlab)

But I think there is a flaw in my documentation though I am not sure.

the Block diagram:

Code:

```
eta[n] --->(Phase Detector)--e[n]-->(filter 1)---c[n]--->(filter 2)---->phi[n]
| |
------------------( e^j )<---------------------
```

Code:

```
filter 1 = KL*( 1 + alpha * z^-1 ) / ( 1 -z^-1 )
filter 2 = mu * z^-1 / ( 1 -z^-1 )
```

Which seems to make sense but I don't think the example code follows this block diagram

EXAMPLE CODE:

Code:

```
Ts = 1/fs2;
mu = Ts;
BL = 10; %loop bandwidth
zeta = .707; %damping factor
wn = 2*BL/(zeta+1/(4*zeta)); %natural frequency
KL = wn^2*Ts+2*zeta*wn; %filter constant
alpha = -2*zeta/(2*zeta+wn*Ts); %filter constant
c1 = 0; e1 = 0; %these denote c[n-1] and e[n-1] respectively
phi = zeros(size(eta)); %empty vector the same size as input eta
eta = -eta;
for n = 2:length(eta)
e = eta(n-1)*conj( exp(j*phi(n-1)) ); %phase detector
c = KL*mu*(e + alpha * e1) + c1; %filter 1 ?
phi(n) = c+phi(n-1); %filter 2 ?
c1 = c;
e1 = e;
end
```

So I don't think the variables c or phi are properly calculated to the block diagram. Can anyone fresh on Z transforms please confirm or reject my suspicions.

Thanks

-Nick-