Carrier Recovery Using a Second Order Costas Loop



Comments



Description

DSP Implementation of CommunicationSystems ECPE 4654 Experiment 5 Carrier Recovery Using a Second Order Costas Loop April 1, 2002 Xuan Chi 2 Introduction Phase-lock loops (PLLs) have been one of the basic building blocks in modern communication systems. They have been widely used in communications, multimedia and many other applications. The theory and mathematical models used to describe PLLs come in two types: linear and non-linear. Non-linear theory is often complicated and difficult to deal with in real-world designs. There are many kinds of Phase Lock Loops; the Costas Loop, which is named by J. P. Costas, a pioneer in synchronous communications, is chosen for this experiment. The reason is that the implementation is quite simple and the structure is very powerful and useful in many situations. Objective The objective of experiment 5 is to learn about the Costas Loop and how it works. To do this, we will design and implement a Costas Loop to recover a carrier modulate AM and BPSK signal. Theory A. Hilbert Transform: Theoretically, a Hilbert transform imparts a -π/2 phase shift of the input signal without modifying the magnitude of the input signal. A Hilbert transformer is a filter that implements a Hilbert transform. The transformer is defined by the frequency response given in (1) and illustrated in Figure 1. ¹ ' ¹ < > − · − · 0 .... 0 ... ) sgn( ) ( ω ω ω ω j j j H H 1 ) ( · ω H H Figure 1. Hilbert Transform Frequency Response. It is undefined at ω=0, although generally treated as 0 ) 0 ( · · ω H H .For notational purposes we will denote the Hilbert transform as H{} and the output of the Hilbert transform of the signal x(t), H{x(t)}, as ) (t x ) . 0 ω 0 ω j -j H H (ω) 3 When a baseband message signal, m(t), is transmitted on a carrier of frequency , c ω the following relationship also holds { } ) 2 / cos( ) ( ) cos( ) ( π θ ω θ ω − + · + Η t t m t t m c c This can be quickly verified by utilizing the relationships 2 π j e j · and 2 π j e j − · − . Thus in the frequency domain the output of a Hibert transform is given by ( ) ( ) ( ) ( ) 2 2 2 2 1 1 ( ) ( ) 2 2 1 1 ( ) ( ) 2 2 1 1 ( ) ( ) 2 2 c c c c c c j j j j j j j j jM e jM e M e e M e e M e M e ω θ ω θ π π ω θ ω θ π π ω θ ω θ ω ω ω ω ω ω + − + − + − + ¸ _ ¸ _ + − − + − ¸ , ¸ , · − + · + · + In order to implement a Hilbert transform, we need to express it in the time domain. The impulse response of an ideal Hilbert transform can be found as follows. ( ) ( ) ( ) 0 0 2 1 2 1 2 2sin / 2 , 0 0, 0 j n H H j n j n h n H e je je n n n n π ω π π ω ω π ω π π π π − − · ¸ _ · − ¸ , ¹ ≠ ¹ · ' ¹ · ¹ ∫ ∫ ∫ Thus an ideal Hilbert transform’s impulse response is seen to be • infinite in duration • noncausal (as the output depends on future values of n) • antisymmetric (equal in magnitude and opposite in sign) • nonzero for only odd values of n Because of the infinite duration, it is not possible to directly implement a Hilbert transform. However, it can be closely approximated by windowing the impulse response and implementing the filter using a linear phase FIR with an antisymmetric impulse response. Any of a number of different windowing methods are appropriate. Additionally, because the impulse response is antisymmetric, the frequency response must be 0 at ω=0 for even and odd order filters, and 0 at ω = π for an odd order filter, thus it will also not be possible to implement the Hilbert transform as an all pass filter. However, if the signal to be phase shifted is known -to be limited to a range of frequencies, then the filter can still be appropriately designed. 4 One method to implement a Hilbert Transformer is ( ) ( ) 2 2 0.54 0.46cos , [0, 1], 1 0, [1, 1], H n n N n even h n n N n N n odd π π γ ¹ 1 ¸ _ − ∈ − ¹ 1 · − − ¸ , ' ¸ ] ¹ ∈ − ¹ where 2 N γ 1 · 1 ¸ ] and 1 ¸ ] indicates the floor function. Another method for designing the transformer is to use the Remez algorithm with the Chebyshev approximation criterion can be employed. B. Analytic Signal (Pre-envelope) An analytic signal is defined as the original signal plus j times the original signal’s Hilbert transform. Given a signal x(t), its analytic signal, x + (t) can be constructed as ˆ ( ) ( ) ( ) x t x t jx t + · + In the frequency domain, the construction of an analytic signal has the effect of eliminating the original signal’s negative frequency components and doubling the positive frequency components. This can also be thought of as folding the negative frequency components into the positive frequency components about ω = 0. This result can be formally expressed as ( ) ( ) ( ) ( ) ( ) 2 0 2 0 0 0 0 X X X u X ω ω ω ω ω ω ω + > ¹ ¹ · · · ' ¹ < ¹ C. Complex Envelope The complex envelope is formed by multiplying the pre-envelope by the complex exponential, t j e 0 ω − . This has the effect of translating the pre-envelope -ω 0 in the frequency domain. If ω 0 is chosen as the center frequency of the pre-envelope, then the resulting complex envelope will be translated to baseband. Mathematically, the complex envelope, ( ) x t % , of a signal, x(t), is defined as ( ) ( ) 0 j t x t x t e ω − + · % In the frequency domain this is ( ) ( ) ( ) 0 0 2 X X X ω ω ω ω ω + · + · + % 5 Thus with a properly chosen ω 0 , the formation of the complex envelope can be used to demodulate a signal modulated onto a carrier. D. AM Example Consider the reception of an AM signal, x(t), with a message signal, m(t), modulated onto a carrier with amplitude A c and frequency ω c , and a phase offset θ 1 (t). This signal can be expressed as ( ) ( ) 1 ( ) cos ( ) c c x t A m t t t ω θ · + or ( ) ( ) ( ) ( ) ( ) 1 1 ( ) ( ) 1 2 c c j t t j t t c x t A m t e e ω θ ω θ + − + 1 · + 1 ¸ ] Its Hilbert transform is equal to ( ) ( ) ( ) ( ) ( ) 1 ] 1 ¸ + · − + − − + 2 / 2 / 1 1 2 1 ˆ π θ ω π θ ω t j t j c c c e e t m A t x Its analytic signal is then just ( ) ( ) ( ) 1 θ ω + + · t j c c e t m A t x ω -ω c ω c ω -ω c ω c ω ω c ω ω c 6 Suppose the analytic signal is multiplied by ( ) 2 θ ω + − t j c e , where ω c is the receiver's estimate of the carrier frequency and θ 2 is its estimate of the carrier phase. Presuming the carrier frequency is correctly estimated, the complex envelope is given by ( ) ( ) ( ) ( ) ( ) ( ) t t j t t j c c c e e t m A t x 2 1 ~ θ ω θ ω + − + · ( ) ( ) ( ) ( ) ( ) t t j c e t m A t x 2 1 ~ θ θ − · Thus the AM signal is translated to baseband. However, in this expression the message signal is multiplied by a complex exponential. Using the substitutions ∆θ(t) = θ 1 (t) - θ 2 (t) and e j∆θ(t) = cos(∆θ(t)) + j sin(∆θ(t)) , the complex envelope can be expressed as ( ) ( ) ( ) ( ) ( ) ) ( sin ) ( cos ~ t t m jA t t m A t x c c θ θ ∆ + ∆ · Thus if the receiver’s phase estimate exactly matches the carrier’s phase, then the real portion of the complex envelope will be the demodulated message signal multiplied by A c . So presuming the receiver perfectly estimates the phase, the complex envelope can be used to demodulate a message signal transmitted on a carrier. E. Costas Loop A Costas loop is a type of Phase Lock Loop (PLL) that attempts to transform a carrier modulated message signal into its complex envelope representation in order to recover the message signal. A Costas loop transforms the received signal into its pre-envelope representation. This pre-envelope signal is then multiplied by a complex exponential that using an estimate of the carrier signal’s frequency and phase to form the complex envelope. If the frequency and phase of carrier were estimated accurately, the real components of the complex envelope represent the message signal. A block diagram of a second order Costas Loop is shown below in Figure 5. ωω 7 , _ ¸ ¸ + · ξ ξ ξ α 4 1 2 2 S L T B ; 2 4 1 2 , _ ¸ ¸ + · ξ ξ β S L T B ; ] [ / 2 0 2 2 rad N E T B S S L · θ σ ; ξ=0.707 ; ] [ 2 . 1 symbols T B t S L acq · The Costas Loop Filter The Costas Loop filter is used to determine certain loop parameters. In order to determine these, we need a linearized model. The input of the loop is the Hilbert Transformed signal. This is implemented using a simple FIR filter. The figure below is model for the Linearized Loop Filter. where { } ) ( 1 2 2 s c nT m A E k · for AM demodulation scheme where { } E denotes the expectation operator and c A k · 1 for the case of BPSK. z -1 α 1 1 z β − − ( ) j e − ⋅ -j sgn(ω) x(nT S ) ω c T S m(t) φ(nT S ) ( ) ( ) 2 θ ω φ + − − · S c S nT j nT j e e q(nT S ) ( ) S nT xˆ ( ) ( ) ( ) { } 2 1 c S j nT S S c nT x nT e ω θ − + + · Re ( ) ( ) ( ) { } 2 2 c S j nT S S c nT x nT e ω θ − + + · I m z -1 α 1 1 z β − − ( ) j e − ⋅ -j sgn(ω) x(nT S ) ω c T S m(t) φ(nT S ) ( ) ( ) 2 θ ω φ + − − · S c S nT j nT j e e q(nT S ) ( ) S nT xˆ ( ) ( ) ( ) { } 2 1 c S j nT S S c nT x nT e ω θ − + + · Re ( ) ( ) ( ) { } 2 2 c S j nT S S c nT x nT e ω θ − + + · I m z -1 k 1 α 1 1 z β − − θ 2 (n) - z -1 k 1 α 1 1 z β − − θ 2 (n) - 8 The transform function for the loop is { } 1 1 1 1 1 1 1 ) 1 ( ) ( 2 1 ) 1 ( ) ( − − − − + + − − + − + · z k z k z k k z H α β α β α α α β , where L B is the loop bandwidth and , _ ¸ ¸ + · ξ ξ ξ α 4 1 2 2 1 S L T B k , 2 1 4 1 2 , _ ¸ ¸ + · ξ ξ β S L T B k where ξ is the loop damping factor. It is set 0.707 for this experiment. (3dB). Experimental Procedure, Design, and Results 1. Matlab Procedure A. Hilbert transformer Design We used the Hamming windows method and the remez method to design this part. % order of the filter, have to be even for linear phase order = 32; For Hamming window to get an FIR filter approximating the Hilbert transform filter: N = order + 1; M = floor(N/2); h = zeros(1, N); for n = 0:N-1 if mod(n-M, 2) == 1 h(n+1) = 2/pi/(n - M)*(0.54 - 0.46*cos(2*pi*n/(N-1))); end end Remez method to get a linear phase FIR filter approximated the Hilbert transform filter: N=33; f = 0.1:0.001:0.901; a = ones(length(f)); b = remez(order, f, a, 'hilbert'); here for each part we calculated the group delay of the FIR filter: code is : [gd,f] = grpdelay(b,1,512,'whole',fs); groupdelay=gd(10) 9 The results are: Groupdelay = 16 H = 0.00032135137635 -0.00419833016827 0.00029473706789 -0.00928426633519 0.00044116303941 -0.01883061296928 0.00052237631816 -0.03439039682080 0.00054705825564 -0.05954005287178 0.00050104413726 -0.10302466436234 0.00038379079799 -0.19682220874362 0.00020832280911 -0.63135112186835 0 0.63135112186835 -0.00020832280911 0.19682220874362 -0.00038379079799 0.10302466436234 -0.00050104413726 0.05954005287178 -0.00054705825564 0.03439039682080 -0.00052237631816 0.01883061296928 -0.00044116303941 0.00928426633519 -0.00029473706789 0.00419833016827 -0.00032135137635 To verify the Hilbert transform filter, input a sine wave of 2kHz. The result is a cosine wave which is imparted a 90 degree phase. 10 B. Analytic Signal Generation To construct an analytic signal, we need to pass the original signal through a Hilbert Transformer. We then multiply this signal by j and add it to the original signal. This creates the analytic signal. The analytic signal removes all negative parts of the original signal and increases the amplitude of the positive portion of the original signal. The code is as follows: hilbert_output = filter(b, 1, input); %groupdelay should be accounted for generating a analytic signal analytic = input(1:len-groupdelay) + j*hilbert_output(groupdelay+1:len); The result is: 11 C. Costas Loop Filter Design for an AM signal: The AM signal’s frequency is 200 Hz and the sample frequency is 16000 Hz, amplitude is 1 V. For the AM part: Fs = 16000; fm = 200; t_span = 0.5; t = 0:1/Fs:t_span; Am = 1; m = Am*sin(2*pi*fm*t); The waveform is: Next we calculate values for k1, beta and alpha and set the value of BL. For k1, we can use the equation which is given before. For BL, we used several values to test which is best and we decided to use 1000 Hz. The unit step input response is: 12 From these graphs, you can see that the waveform meets specs. After beta and alpha are calculated, we can determine the response of the loop: BL = 1000; % Arbitrarily set zeta = 0.707; % Set in Specs k1 = mean(abs((Ac*m).^2)) alpha = 2*zeta*2*BL/(zeta+1/4/zeta)/Fs/k1 beta = ((2*BL/(zeta+1/4/zeta)/Fs))^2/k1 ratio=alpha/beta Hnum = [ k1*(beta+alpha) -k1*alpha]; Hden = [1 -(2-k1*(alpha+beta)) (1-k1*alpha)]; LF = filter(Hnum, Hden, [zeros(1,100) ones(1,2000)]); k1 = 0.4999 alpha = 0.3333 beta = 0.02778 alpha/beta = 12 BL = 1000 Hz D. Costas Loop Design For BPSK: The BPSK signal is found by the same technique used in Experiment 2. BPSK signal generation: 13 Costas loop unit step time response: Costas loop frequency response: k1 = 0.1 alpha = 0.16665 beta = 0.01389 alpha/beta = 12 BL = 1000 Hz E. Costas Loop MATLAB Implementation for an AM Signal: For this part, we input the am signal( f=200, fc=2000) into the Hilbert filter, make AM signal group delay then combine them, time the phase obtained from the loop. The real part is the demodulate output signal. The detail implementation step is: 14 m=Am*cos(2*pi*fm*t);---- AM signal generator theta=1; input = Ac*sin(2*pi*fc*t+theta).*m; %Input is a modulated signal hilbert_output = filter(b, 1, input);---after Hilbert filter %Initialization out = []; phi = []; phi(1) = 0; temp_out1=0; temp_pre_out1=0; temp_out2=0; temp_out3=0; %Simulation for I=1:len-groupdelay phi(I)= temp_out3; phase(I) = exp(-i*phi(I)); c1(I) = real(analytic(I)*phase(I)); c2(I) = imag(analytic(I)*phase(I)); out(I)= sign(c1(I)); q(I) = sign(c1(I))*c2(I); temp_out1=temp_pre_out1+q(I)*beta; temp_out2=alpha*q(I)+ temp_out1; temp_out3=2*pi*fc/fs+phi(I)+temp_out2; temp_pre_out1=temp_out1; end; Theta is the carrier offset phase: if the offset is from 0 to pi, the loop tracks in the same phase with the modulated original signal; if the offset is from pi to 2pi, there will be 180 degree phase shift relative to the original signal. Set the carrier frequency 1900Hz, 100Hz less than the carrier frequency fc, the loop can still keep track with the input. The result is: 15 F. Costas Loop MATLAB Implementation for a BPSK Signal: Change the MATLAB loop in the following places: out(I)= sign(c1(I)); q(I) = sign(c1(I))*c2(I); The results are below: From this picture, we can see the BPSK’s bit is [-1 -1 1 1 -1…], the carrier’s frequency is 2000Hz, Fs=16000 (there are 8 *, at 1, so it is 2000*8=16000). The modulated signal is 1 sample bit delay than original signal; the reason is the loop time less than or equal to the sampling rate. 16 2. C Implementation Procedure B. Costas Loop Demodulation of an externally Generated AM Signal #define SAMPLING_RATE 8000 #define fc 2000 #define N 33 #define grpdelay 16 float h[N]={0.00032135137635, -0.00419833016827, 0.00029473706789, -0.00928426633519, 0.00044116303941, -0.01883061296928, 0.00052237631816, -0.03439039682080, 0.00054705825564, -0.05954005287178, 0.00050104413726, -0.10302466436234, 0.00038379079799, -0.19682220874362, 0.00020832280911, -0.63135112186835, 0, 0.63135112186835, -0.00020832280911, 0.19682220874362,- 0.00038379079799, 0.10302466436234, -0.00050104413726, 0.05954005287178, -0.00054705825564, 0.03439039682080,- 0.00052237631816, 0.01883061296928, -0.00044116303941, 0.00928426633519, -0.00029473706789, 0.00419833016827,- 0.00032135137635}; float x[N],buffer_x[grpdelay]; float beta = 0.0277840, alpha = 0.3333414;//Costas Loop filter parameters int oldest=0,oldest2=0; int counter=0; //acount for the groupdelay for Hilbert transform filter float phi=0, temp_out1=0,temp_pre_out1=0; float hilbert_output, c1, c2, q, y; // Tell compiler where fir_conv function is extern float conv_fcn(float *filter_coeffs, float *data_array,int pointer,int order); /*----------------------------------------------------- INTERRUPT SERVICE ROTINES -------------------------------------------------------*/ interrupt void rcvISR(void) { int new_sample; /* MCBSP0_DRR is the hardware register where received samples are stored */ new_sample = MCBSP0_DRR; // Updating data array with new sample // Scale the input 17 x[oldest] = ((float)new_sample)*4.0e-9; // Increment oldest oldest++; if (oldest==N) oldest=0; hilbert_output = conv_fcn(h,x,oldest,N); if (counter >= grpdelay) {// analytic = buffer_x[oldest] + j*hilbert_output; // phase = cos(phi) +j*(-sin(phi)); //start processing c1 = buffer_x[oldest2]*cos(phi)+ hilbert_output*sin(phi); c2 = -buffer_x[oldest2]*sin(phi) + cos(phi)*hilbert_output; y = c1; q = c1 *c2; temp_out1 = temp_pre_out1 + q*beta; phi = 2*3.1415926*fc/SAMPLING_RATE + phi +alpha*q + temp_out1; if (phi > 6.283185307) phi = phi-6.283185307; temp_pre_out1 = temp_out1; buffer_x[oldest2] = ((float)new_sample)*4.0e-9; // Increment oldest oldest2++; if (oldest2==grpdelay) oldest2=0; //end of processing } if (counter < grpdelay) buffer_x[counter++] = ((float)new_sample)*4.0e-9; // Scale the output MCBSP0_DXR = (int) (y*1.5e9); } The result is as follows: 18 Pull in range: fc_mod = 2000Hz fc_max = 3300Hz fc_min = 400Hz Fc_mod – fc_min = 1600Hz fc_max – fc_mod = 1300Hz E. A. Costas Loop Demodulation of an externally Generated BPSK Signal Modify the code you created in the BPSK experiment so that it outputs a BPSK signal on a 2000 Hz carrier sampled at a rate of 8000 Hz. One BPSK symbol should correspond to four complete carrier periods (16 samples per symbol). Implement this BPSK transmitter on one station, station A. Using available BNC cables, connect the output generated by station A to both an oscilloscope and another station, station B. BPSK signal generation: // Function lfsr int lfsr(s) { // Local Variables int x; // Output bit of pn code int h; // Connection Polynomial int y; // Value of s AND h int a; // Value of bit 3 of y int b; // Value of bit 1 of y h = 37; // Define connection polynomial // Bitwise AND s and h and set equal to y y = s & h; // Get values of bit 3 and bit 1 by masking out everything but the bit you want a = (y & 4) >> 2; b = y & 1; // Bitwise XOR a and b x = a ^ b; // Return the value of x return x; } // Interrupt Service Routines interrupt void rcvISR(void) { int new_sample; float input,output; new_sample = MCBSP0_DRR; input = (float) new_sample; if (i< (counter-1)) 19 { i++; output = m_new*input; } else { i = 0; // Call lfsr function if (i % 45 == 0) { m = lfsr(s); if (m==0) { m_new = -1; } else { m_new = m; } //Create new x for new state vector x_new = m << 4; //Create new state vector s = s >> 1; s = s|x_new; output = m_new*input; } } MCBSP0_DXR = (int)output } Demodulation Part: 20 The code is: /*----------------------------------------------------- INTERRUPT SERVICE ROUTINES -------------------------------------------------------*/ interrupt void rcvISR(void) { int new_sample; /* MCBSP0_DRR is the hardware register where received samples are stored */ new_sample = MCBSP0_DRR; // Updating data array with new sample x[oldest] = ((float)new_sample)*4.0e-9; // Increment oldest oldest++; if (oldest==N) oldest=0; hilbert_output = conv_fcn(h,x,oldest,N); if (counter >= grpdelay) {// analytic = buffer_x[0] + j*hilbert_output; // phase = cos(phi) +j*(-sin(phi)); //start processing c1 = buffer_x[oldest2]*cos(phi)+ hilbert_output*sin(phi); c2 = -buffer_x[oldest2]*sin(phi) + cos(phi)*hilbert_output; y = c1; if (c1>=0) y=1; else y = -1; q = y *c2; temp_out1 = temp_pre_out1 + q*beta; phi = 2*3.1415926*fc/SAMPLING_RATE + phi +alpha*q + temp_out1; if (phi > 6.283185307) 21 phi = phi-6.283185307; temp_pre_out1 = temp_out1; buffer_x[oldest2] = ((float)new_sample)*4.0e-9; // Increment oldest oldest2++; if (oldest2==grpdelay) oldest2=0; //end of processing } if (counter < grpdelay) buffer_x[counter++] = ((float)new_sample)*4.0e-9; MCBSP0_DXR = (int) (y*6e8); } Questions 1. What is the advantage of storing a function into internal program memory? What types of functions make for attractive candidates for storing in internal program memory? The advantage of storing a function in program memory is if you have code that is very time sensitive. By having the function on program memory, it will be able to be accessed faster and produce the results faster. Only the functions that are most frequently used should be placed in program memory. 2. Qualitatively, how are acquisition time and tracking influenced by the value of the loop bandwidth of a phase lock loop? Since the loop bandwidth is inversely proportional to acquisition time, as the loop bandwidth increases, the acquisition time decreases but since the tracking (variance of phase estimate) is proportional to the loop bandwidth, a large loop bandwidth means large error. Hence there is a trade-off. 3. How does your measured pull-in range in Part B relate to your designed loop bandwidths, B L ? Loop bandwidth is the frequency range over the span we could operate the Costas loop correctly. The pull-in range is the maximum change in frequency that the loop can tolerate once the phase is locked without having too much errors. The relationship is that the greater the loop bandwidth, the greater the pull-in range. Conclusion 22 The Costas Loop is one type of Phase Lock Loop used for carrier recovery. The Costas Loop tracks the phase change of the incoming signal in order to demodulate the signal. For this experiment, we simulated the Costas Loop in MATLAB for the case of an AM signal and for a BPSK signal. We also implemented the Costas Loop in C on the C6701 for the AM and BPSK signals. Our results were consistent with the required specifications given to us for the experiment. The performance is dependent on loop parameters Zeta, Alpha, Beta and the loop bandwidth. References Nezami, Mohamed K. “DSP-Based Carrier Acquisition andTracking for Burst TDMA Mobile Land and Satellite Receivers” Applied Microwave and Wireless, September 2001 Proakis, John G. Digital Communications McGraw Hill 4 th edition, 2001. Proakis. John G, and Dimitris G. Manolakis. Digital Signal Processing 3 rd edition 1996. Tretter, Steven A. Communication System Design Using DSP Algorithms Plenum Press, 1995. 23 VALIDATION SHEET Show your code and your results for the following to the TA and have them initial in the appropriate position. Correct Operation Maximum Frequency Deviation Cycles B. AM Demodulation C. AM Demodulation E. BPSK Demodulation 24 Extra Credit For the QPSK: we generate the QPSK (1.5 0.5 -0.5 1.5) signal by the Binary Bit. Use one binary bit plus one, plus another binary bit time 2, then use the result minus 1.5, then we get the Q bits(-1.5 -0.5 0.5 1.5) The code for matlab is here: x=(ones(1,length(x))+x)/2; data=[]; for I=1:length(x) qpsk_1=2*x(1,I); data=[data,qpsk_1]; qpsk_2=2*x(1,I)+1; qpsk_3=qpsk_2-1.5 data=[data,qpsk_2]; end; for the loop , we use the rule mentioned by the exp5 which jody gave us. The code is here: for I=1:len-groupdelay phi(I)= temp_out3; phase(I) = exp(-i*phi(I)); if c1(I) = real(analytic(I)*phase(I)); c2(I) = imag(analytic(I)*phase(I)); out(I)= sign(c1(I)); q(I) = sign(c1(I))*c2(I)-c1*sign(c2(I)); temp_out1=temp_pre_out1+q(I)*beta; temp_out2=alpha*q(I)+ temp_out1; temp_out3=2*pi*fc/fs+phi(I)+temp_out2; temp_pre_out1=temp_out1; end; the result is here: 25 Maybe you will feel this QPSK looks ugly and it doesn’t like QPSK, the key reason is the sample frequency is lower, I use the sample frequency 16k to replot this get the result is below: Introduction Phase-lock loops (PLLs) have been one of the basic building blocks in modern communication systems. They have been widely used in communications, multimedia and many other applications. The theory and mathematical models used to describe PLLs come in two types: linear and non-linear. Non-linear theory is often complicated and difficult to deal with in real-world designs. There are many kinds of Phase Lock Loops; the Costas Loop, which is named by J. P. Costas, a pioneer in synchronous communications, is chosen for this experiment. The reason is that the implementation is quite simple and the structure is very powerful and useful in many situations. Objective The objective of experiment 5 is to learn about the Costas Loop and how it works. To do this, we will design and implement a Costas Loop to recover a carrier modulate AM and BPSK signal. Theory A. Hilbert Transform: Theoretically, a Hilbert transform imparts a -π/2 phase shift of the input signal without modifying the magnitude of the input signal. A Hilbert transformer is a filter that implements a Hilbert transform. The transformer is defined by the frequency response given in (1) and illustrated in Figure 1. H  − j ... ω > 0 ( ω ) = − j sgn( ω ) =   j .... ω < 0 H H (ω ) = 1 H j HH(ω) 0 ω -j Figure 1. Hilbert Transform Frequency Response. It is undefined at ω=0, although generally treated as H H (ω = 0) = 0 .For notational purposes we will denote the Hilbert transform as H{} and the output of the Hilbert ) transform of the signal x(t), H{x(t)}, as x (t ) . 2 However. is transmitted on a carrier of frequency ωc . However. Thus in 1 1 = − jM (ω ) e j (ωc +θ ) + jM (ω ) e− j (ωc +θ ) 2 2 π π j 1 j (ωc +θ ) − j 2 1 = M (ω ) e e + M (ω ) e− j(ωc +θ ) e 2 2 2 1 j ωc +θ − 2  1 − j ωc +θ − 2    = M (ω ) e  + M (ω ) e  2 2  π  π In order to implement a Hilbert transform. 3 . the following relationship also holds Η{m(t ) cos(ω c t + θ )} = m(t ) cos(ω c t + θ − π / 2) This can be quickly verified by utilizing the relationships j = e and − j = e the frequency domain the output of a Hibert transform is given by 2 j π −j π 2 . n=0  Thus an ideal Hilbert transform’ impulse response is seen to be s • • • • infinite in duration noncausal (as the output depends on future values of n) antisymmetric (equal in magnitude and opposite in sign) nonzero for only odd values of n Because of the infinite duration. it is not possible to directly implement a Hilbert transform. m(t). the frequency response must be 0 at ω=0 for even and odd order filters. n≠ 0 = πn 0. Additionally. then the filter can still be appropriately designed. thus it will also not be possible to implement the Hilbert transform as an all pass filter. Any of a number of different windowing methods are appropriate. because the impulse response is antisymmetric. if the signal to be phase shifted is known -to be limited to a range of frequencies. The impulse response of an ideal Hilbert transform can be found as follows. it can be closely approximated by windowing the impulse response and implementing the filter using a linear phase FIR with an antisymmetric impulse response. we need to express it in the time domain.When a baseband message signal. and 0 at ω = π for an odd order filter. hH ( n ) = = 1 2π π −π ∫ H (ω ) e H jω n 1  0 jω n π jω n   je − ∫ je  2π  −∫ π 0  2  2sin (π n / 2 )  . e− jω 0 t . n even hH ( n ) =  π ( n − γ )   N − 1   0. Mathematically. n ∈ [1.54 − 0. n ∈ [0. N − 1]. is defined as % % x ( t ) = x+ ( t ) e− jω0t In the frequency domain this is % X (ω ) = X + (ω + ω0 ) = 2 X (ω + ω0 ) 4 . its analytic signal. of a signal. x(t ) . then the resulting complex envelope will be translated to baseband. x+(t) can be constructed as ˆ x+ (t ) = x (t ) + jx(t ) In the frequency domain. This result can be formally expressed as  2 X (ω ) ω > 0  X + (ω ) = 2 X (ω ) u (ω ) =  X ( 0 ) ω=0 0 ω<0  C.   2   Another method for designing the transformer is to use the Remez algorithm with the Chebyshev approximation criterion can be employed. B. n odd  where γ =  N  and   indicates the floor function. If ω 0 is chosen as the center frequency of the pre-envelope. Analytic Signal (Pre-envelope) An analytic signal is defined as the original signal plus j times the original signal’ s Hilbert transform. This has the effect of translating the pre-envelope -ω 0 in the frequency domain. N − 1].One method to implement a Hilbert Transformer is  2   2π n   0. the complex envelope. x(t).46cos     . This can also be thought of as folding the negative frequency components into the positive frequency components about ω = 0. Given a signal x(t). the construction of an analytic signal has the effect of eliminating the original signal’ negative frequency components and doubling the positive frequency s components. Complex Envelope The complex envelope is formed by multiplying the pre-envelope by the complex exponential. the formation of the complex envelope can be used to demodulate a signal modulated onto a carrier. x(t). and a phase offset θ1(t). with a message signal. modulated onto a carrier with amplitude Ac and frequency ω c. D. AM Example Consider the reception of an AM signal. m(t).Thus with a properly chosen ω 0. This signal can be expressed as x (t ) = Ac m( t ) cos ( ω c t + θ 1 (t ) ) or 1  x ( t ) = Ac m( t )  e j (ωct +θ1 ( t )) + e − j (ωc t +θ1 (t ) )  2   ( ) -ωc ωc ω Its Hilbert transform is equal to 1  ˆ x (t ) = Ac m(t ) e j (ω ct +θ1 −π / 2) + e − j (ωct +θ1 −π / 2 )  2  ( ) Its analytic signal is then just x+ (t ) = Ac m(t )e j (ω ct +θ1 ) ωc ω 5 . in this expression the message signal is multiplied by a complex exponential. where ω c is the receiver's estimate of the carrier frequency and θ2 is its estimate of the carrier phase. A Costas loop transforms the received signal into its pre-envelope representation. A block diagram of a second order Costas Loop is shown below in Figure 5. 6 .θ2(t) and ej∆θ(t) = cos(∆θ(t)) + j sin(∆θ(t)) .Suppose the analytic signal is multiplied by e− j (ωc t +θ 2 ) . then the real s s portion of the complex envelope will be the demodulated message signal multiplied by Ac. Costas Loop A Costas loop is a type of Phase Lock Loop (PLL) that attempts to transform a carrier modulated message signal into its complex envelope representation in order to recover the message signal. the complex envelope can be used to demodulate a message signal transmitted on a carrier. E. the complex envelope is given by ~(t ) = A m (t )e j (ωc t +θ1 (t ))e − j (ωct +θ 2 (t )) x c ~ x (t ) = Ac m (t )e j (θ 1 (t )−θ 2 (t )) ω Thus the AM signal is translated to baseband. So presuming the receiver perfectly estimates the phase. This pre-envelope signal is then multiplied by a complex exponential that using an estimate of the carrier signal’ frequency and phase to form the complex envelope. the complex envelope can be expressed as ~(t ) = A m (t ) cos(∆ θ (t )) + jA m (t ) sin(∆θ (t )) x c c Thus if the receiver’ phase estimate exactly matches the carrier’ phase. s If the frequency and phase of carrier were estimated accurately. the real components of the complex envelope represent the message signal. Using the substitutions ∆θ(t) = θ1(t) . Presuming the carrier frequency is correctly estimated. However. 2 [rad 2 ] . In order to determine these. tacq = [symbols] ES / N0 BLTS The Costas Loop Filter The Costas Loop filter is used to determine certain loop parameters. ξ=0. θ2(n) k1 β 1 − z −1 z-1 α where k1 = E Ac2 m 2 ( nTs ) for AM demodulation scheme where E{ } denotes the expectation operator and k1 = Ac for the case of BPSK. The input of the loop is the Hilbert Transformed signal. The figure below is model for the Linearized Loop Filter. This is implemented using a simple FIR filter.707 . { } 7 . σ θ2 = B L TS 1.x(nTS) c1 ( nTS ) = Re x+ ( nTS ) e { − j (ωc nTS + θ2 ) } q(nTS ) m(t) -j sgn(ω) ˆ x(nTS ) c2 ( nTS ) = I m x+ ( nTS ) e − j φ ( nTS ) { − j ( ω c nTS + θ 2 ) } e =e − j (ω cnTS +θ 2 ) e − j ( ⋅) β 1 − z −1 φ(nTS) z-1 ωcTS α   2B T α = 2ξ  L S  1  ξ + 4ξ       . we need a linearized model. β =  2 B L TS   1   ξ + 4ξ         2 2 . It is set 0.46*cos(2*pi*n/(N-1))). (3dB). f. end end Remez method to get a linear phase FIR filter approximated the Hilbert transform filter: N=33. Matlab Procedure A.1:0. f = 0. zeros(1. Design. Hilbert transformer Design We used the Hamming windows method and the remez method to design this part. % order of the filter.901.001:0. and Results 1.1. have to be even for linear phase order = 32. here for each part we calculated the group delay of the FIR filter: code is : [gd.   2B T αk1 = 2ξ  L S  1  ξ + 4ξ  2 Experimental Procedure. n = 0:N-1 if mod(n-M. a = ones(length(f)). groupdelay=gd(10) 8 .707 for this experiment.0. N).512. b = remez(order.fs). 'hilbert').M)*(0. For Hamming window to get an FIR filter approximating the Hilbert transform filter: N = M = h = for order + 1. a. βk =  2BL TS  1   1    ξ + 4ξ     where ξ is the loop damping factor.f] = grpdelay(b. floor(N/2).'whole'.The transform function for the loop is α z −1 ) α+β H (z) = . 1 − {2 − k1 (α + β )}z −1 + (1 − k 1 α ) z −1 where B L is the loop bandwidth and k1 β + k 1α (1 −        .54 . 2) == 1 h(n+1) = 2/pi/(n . The result is a cosine wave which is imparted a 90 degree phase.63135112186835 -0.03439039682080 -0.10302466436234 0.00054705825564 0.05954005287178 0.00032135137635 To verify the Hilbert transform filter.00419833016827 0. 9 .10302466436234 -0.00052237631816 0.00029473706789 -0.00038379079799 -0.00032135137635 -0.00038379079799 0.00054705825564 -0.00928426633519 0.00029473706789 0.00928426633519 -0.The results are: Groupdelay = 16 H = 0.01883061296928 -0.01883061296928 0.19682220874362 0.00044116303941 0.00052237631816 -0. input a sine wave of 2kHz.05954005287178 -0.63135112186835 0 0.19682220874362 -0.00050104413726 0.00050104413726 -0.00020832280911 0.00044116303941 -0.00020832280911 -0.00419833016827 -0.03439039682080 0. input).B. This creates the analytic signal. The analytic signal removes all negative parts of the original signal and increases the amplitude of the positive portion of the original signal. we need to pass the original signal through a Hilbert Transformer. The result is: 10 . We then multiply this signal by j and add it to the original signal. %groupdelay should be accounted for generating a analytic signal analytic = input(1:len-groupdelay) + j*hilbert_output(groupdelay+1:len). Analytic Signal Generation To construct an analytic signal. 1. The code is as follows: hilbert_output = filter(b. C. Costas Loop Filter Design for an AM signal: The AM signal’ frequency is 200 Hz and the sample frequency is 16000 Hz. beta and alpha and set the value of BL. we can use the equation which is given before. For the AM part: Fs = 16000. t_span = 0. The waveform is: Next we calculate values for k1. For k1.5. For BL. we used several values to test which is best and we decided to use 1000 Hz. s amplitude is 1 V. t = 0:1/Fs:t_span. Am = 1. The unit step input response is: 11 . fm = 200. m = Am*sin(2*pi*fm*t). BPSK signal generation: 12 . Hden.100) ones(1. we can determine the response of the loop: BL = 1000. Hden = [1 -(2-k1*(alpha+beta)) (1-k1*alpha)]. % Set in Specs k1 = mean(abs((Ac*m). % Arbitrarily set zeta = 0.2000)]).3333 beta = 0. Costas Loop Design For BPSK: The BPSK signal is found by the same technique used in Experiment 2.02778 alpha/beta = 12 BL = 1000 Hz D. After beta and alpha are calculated. [zeros(1.^2)) alpha = 2*zeta*2*BL/(zeta+1/4/zeta)/Fs/k1 beta = ((2*BL/(zeta+1/4/zeta)/Fs))^2/k1 ratio=alpha/beta Hnum = [ k1*(beta+alpha) -k1*alpha].707. you can see that the waveform meets specs.4999 alpha = 0. k1 = 0.From these graphs. LF = filter(Hnum. make AM signal group delay then combine them.01389 alpha/beta = 12 BL = 1000 Hz E. The detail implementation step is: 13 .1 alpha = 0. time the phase obtained from the loop. The real part is the demodulate output signal. fc=2000) into the Hilbert filter. Costas Loop MATLAB Implementation for an AM Signal: For this part.Costas loop unit step time response: Costas loop frequency response: k1 = 0. we input the am signal( f=200.16665 beta = 0. ---. The result is: 14 . end. c1(I) = real(analytic(I)*phase(I)). out(I)= sign(c1(I)). temp_out3=2*pi*fc/fs+phi(I)+temp_out2.---after Hilbert filter %Initialization out = []. input = Ac*sin(2*pi*fc*t+theta). the loop can still keep track with the input. phase(I) = exp(-i*phi(I)). temp_out1=temp_pre_out1+q(I)*beta. phi(1) = 0.AM signal generator theta=1. Set the carrier frequency 1900Hz. 1. q(I) = sign(c1(I))*c2(I). temp_pre_out1=temp_out1. the loop tracks in the same phase with the modulated original signal.m=Am*cos(2*pi*fm*t). Theta is the carrier offset phase: if the offset is from 0 to pi. there will be 180 degree phase shift relative to the original signal. phi = []. temp_out3=0.*m. temp_pre_out1=0. c2(I) = imag(analytic(I)*phase(I)). input). temp_out2=alpha*q(I)+ temp_out1. temp_out1=0. temp_out2=0. 100Hz less than the carrier frequency fc. %Input is a modulated signal hilbert_output = filter(b. if the offset is from pi to 2pi. %Simulation for I=1:len-groupdelay phi(I)= temp_out3. 15 . The results are below: From this picture. Fs=16000 (there are 8 *. at 1. so it is 2000*8=16000). the carrier’ s s frequency is 2000Hz. The modulated signal is 1 sample bit delay than original signal. the reason is the loop time less than or equal to the sampling rate.F. Costas Loop MATLAB Implementation for a BPSK Signal: Change the MATLAB loop in the following places: out(I)= sign(c1(I)). q(I) = sign(c1(I))*c2(I). we can see the BPSK’ bit is [-1 -1 1 1 -1… ]. alpha = 0. 0. 0.00419833016827. 0.int order). -0. y.05954005287178. float x[N]. 0. float beta = 0. 0. // Tell compiler where fir_conv function is extern float conv_fcn(float *filter_coeffs. 0. 0.10302466436234. -0. 0.00419833016827.03439039682080. int counter=0. c1. C Implementation Procedure B. //acount for the groupdelay for Hilbert transform filter float phi=0. 0.00044116303941.00032135137635}.00032135137635. /*----------------------------------------------------INTERRUPT SERVICE ROTINES -------------------------------------------------------*/ interrupt void rcvISR(void) { int new_sample.00050104413726.19682220874362. 0. -0. 0. -0. c2.00038379079799.3333414.00052237631816.63135112186835.int pointer.0277840. Costas Loop Demodulation of an externally Generated AM Signal #define #define #define #define SAMPLING_RATE 8000 fc 2000 N 33 grpdelay 16 float h[N]={0.03439039682080.2. -0.01883061296928. -0. -0. float hilbert_output. float *data_array.00020832280911.buffer_x[grpdelay].00029473706789.10302466436234. -0. 0.0.63135112186835. -0.00050104413726.05954005287178.00038379079799.00054705825564.19682220874362. 0. -0.00054705825564.//Costas Loop filter parameters int oldest=0.00020832280911.0. 0. /* MCBSP0_DRR is the hardware register where received samples are stored */ new_sample = MCBSP0_DRR.00928426633519. 0. -0. q.00029473706789.00044116303941.oldest2=0.00928426633519. // Updating data array with new sample // Scale the input 16 .01883061296928.temp_pre_out1=0. -0. 0.0.00052237631816. -0. temp_out1=0. 0e-9.0e-9.283185307.oldest.5e9). if (oldest==N) oldest=0. buffer_x[oldest2] = ((float)new_sample)*4.x[oldest] = ((float)new_sample)*4. if (counter >= grpdelay) {// analytic = buffer_x[oldest] + j*hilbert_output. } The result is as follows: 17 . //start processing c1 = buffer_x[oldest2]*cos(phi)+ hilbert_output*sin(phi).0e-9.x.283185307) phi = phi-6. //end of processing } if (counter < grpdelay) buffer_x[counter++] = ((float)new_sample)*4.N).1415926*fc/SAMPLING_RATE + phi +alpha*q + temp_out1. c2 = -buffer_x[oldest2]*sin(phi) + cos(phi)*hilbert_output. q = c1 *c2. if (oldest2==grpdelay) oldest2=0. hilbert_output = conv_fcn(h. // Increment oldest oldest++. y = c1. temp_pre_out1 = temp_out1. phi = 2*3. if (phi > 6. temp_out1 = temp_pre_out1 + q*beta. // phase = cos(phi) +j*(-sin(phi)). // Scale the output MCBSP0_DXR = (int) (y*1. // Increment oldest oldest2++. new_sample = MCBSP0_DRR. input = (float) new_sample. // Return the value of x return x. BPSK signal generation: // Function lfsr int lfsr(s) { // Local Variables int x. if (i< (counter-1)) 18 . Using available BNC cables. station B. int y. // Get values of bit 3 and bit 1 by masking out everything but the bit you want a = (y & 4) >> 2. // Bitwise XOR a and b x = a ^ b. station A. A. polynomial // // // // // Output bit of pn code Connection Polynomial Value of s AND h Value of bit 3 of y Value of bit 1 of y // Define connection // Bitwise AND s and h and set equal to y y = s & h. float input. connect the output generated by station A to both an oscilloscope and another station. int h. One BPSK symbol should correspond to four complete carrier periods (16 samples per symbol).output. int b. int a. b = y & 1. h = 37.Pull in range: fc_mod = 2000Hz fc_max = 3300Hz fc_min = 400Hz Fc_mod –fc_min = 1600Hz fc_max –fc_mod = 1300Hz E. Implement this BPSK transmitter on one station. Costas Loop Demodulation of an externally Generated BPSK Signal Modify the code you created in the BPSK experiment so that it outputs a BPSK signal on a 2000 Hz carrier sampled at a rate of 8000 Hz. } // Interrupt Service Routines interrupt void rcvISR(void) { int new_sample. s = s|x_new. } //Create new x for new state vector x_new = m << 4. } else { i = 0. } } MCBSP0_DXR = (int)output } Demodulation Part: 19 . output = m_new*input. } else { m_new = m. if (m==0) { m_new = -1.{ i++. // Call lfsr function if (i % 45 == 0) { m = lfsr(s). //Create new state vector s = s >> 1. output = m_new*input. else y = -1. // Updating data array with new sample x[oldest] = ((float)new_sample)*4. // phase = cos(phi) +j*(-sin(phi)). temp_out1 = temp_pre_out1 + q*beta.oldest. if (oldest==N) oldest=0. hilbert_output = conv_fcn(h.The code is: /*----------------------------------------------------INTERRUPT SERVICE ROUTINES -------------------------------------------------------*/ interrupt void rcvISR(void) { int new_sample.283185307) 20 . if (counter >= grpdelay) {// analytic = buffer_x[0] + j*hilbert_output.0e-9. /* MCBSP0_DRR is the hardware register where received samples are stored */ new_sample = MCBSP0_DRR. c2 = -buffer_x[oldest2]*sin(phi) + cos(phi)*hilbert_output. q = y *c2. y = c1.x.1415926*fc/SAMPLING_RATE + phi +alpha*q + temp_out1. //start processing c1 = buffer_x[oldest2]*cos(phi)+ hilbert_output*sin(phi). phi = 2*3.N). if (c1>=0) y=1. // Increment oldest oldest++. if (phi > 6. as the loop bandwidth increases. //end of processing } if (counter < grpdelay) buffer_x[counter++] = ((float)new_sample)*4. a large loop bandwidth means large error. buffer_x[oldest2] = ((float)new_sample)*4.0e-9. the acquisition time decreases but since the tracking (variance of phase estimate) is proportional to the loop bandwidth. Hence there is a trade-off. temp_pre_out1 = temp_out1. it will be able to be accessed faster and produce the results faster. // Increment oldest oldest2++. By having the function on program memory. 2.0e-9. the greater the pull-in range.283185307. how are acquisition time and tracking influenced by the value of the loop bandwidth of a phase lock loop? Since the loop bandwidth is inversely proportional to acquisition time. How does your measured pull-in range in Part B relate to your designed loop bandwidths. The pull-in range is the maximum change in frequency that the loop can tolerate once the phase is locked without having too much errors. BL? Loop bandwidth is the frequency range over the span we could operate the Costas loop correctly. Only the functions that are most frequently used should be placed in program memory. if (oldest2==grpdelay) oldest2=0. The relationship is that the greater the loop bandwidth. Conclusion 21 . MCBSP0_DXR = (int) (y*6e8). } Questions 1. 3. What is the advantage of storing a function into internal program memory? What types of functions make for attractive candidates for storing in internal program memory? The advantage of storing a function in program memory is if you have code that is very time sensitive.phi = phi-6. Qualitatively. John G. For this experiment. Proakis. 2001. John G. 22 . Digital Communications McGraw Hill 4th edition. Communication System Design Using DSP Algorithms Plenum Press. The performance is dependent on loop parameters Zeta. Tretter. we simulated the Costas Loop in MATLAB for the case of an AM signal and for a BPSK signal. and Dimitris G. Beta and the loop bandwidth. September 2001 Proakis. Mohamed K. “ DSP-Based Carrier Acquisition andTracking for Burst TDMA Mobile Land and Satellite Receivers” Applied Microwave and Wireless. Alpha. Digital Signal Processing 3rd edition 1996. Steven A.The Costas Loop is one type of Phase Lock Loop used for carrier recovery. References Nezami. 1995. We also implemented the Costas Loop in C on the C6701 for the AM and BPSK signals. The Costas Loop tracks the phase change of the incoming signal in order to demodulate the signal. Our results were consistent with the required specifications given to us for the experiment. Manolakis. AM Demodulation E. AM Demodulation C.VALIDATION SHEET Show your code and your results for the following to the TA and have them initial in the appropriate position. BPSK Demodulation Maximum Frequency Deviation Cycles 23 . Correct Operation B. temp_out2=alpha*q(I)+ temp_out1.5 0. phase(I) = exp(-i*phi(I)).5 0. then we get the Q bits(-1. for the loop .5 1.Extra Credit For the QPSK: we generate the QPSK (1. c2(I) = imag(analytic(I)*phase(I)). for I=1:length(x) qpsk_1=2*x(1. end. then use the result minus 1.5 data=[data. temp_out3=2*pi*fc/fs+phi(I)+temp_out2.5 1.qpsk_2].5 -0. qpsk_2=2*x(1. temp_out1=temp_pre_out1+q(I)*beta. temp_pre_out1=temp_out1. out(I)= sign(c1(I)).5. we use the rule mentioned by the exp5 which jody gave us. data=[data. The code is here: for I=1:len-groupdelay phi(I)= temp_out3.I).qpsk_1]. data=[]. end. plus another binary bit time 2. if c1(I) = real(analytic(I)*phase(I)).I)+1.5) signal by the Binary Bit.5 -0.5) The code for matlab is here: x=(ones(1. q(I) = sign(c1(I))*c2(I)-c1*sign(c2(I)). qpsk_3=qpsk_2-1. Use one binary bit plus one. the result is here: 24 .length(x))+x)/2. the key reason is the t sample frequency is lower.Maybe you will feel this QPSK looks ugly and it doesn’ like QPSK. I use the sample frequency 16k to replot this get the result is below: 25 .
Copyright © 2024 DOKUMEN.SITE Inc.