Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can you please take a look at my code below for both and let me know if i\'m on

ID: 2292828 • Letter: C

Question

can you please take a look at my code below for both and let me know if i'm on the right track on solving this matlab cod

Communication Lab practice Carrier Synchronizers

Simulate the time domain operation of generation of coherent demodulation carrier using (1) a squaring loop and (2) Costas loop. Refer to the two block diagrams in Fig. 4.29 and Fig. 4.30. Use a major lab report format to write the report.

Assume a DSBSC received signal with Hz. Assume is a square wave with unit amplitude and period of 2. Assume initially the local carrier has a frequency error of 0.2 Hz.

Plot some intermediate outputs to illustrate the operation of the carrier tracking loops. Remember to plot them clearly in order to read the details of the waveforms.

Squaring loop

Design the loop by picking the right bandwidth of the BPF and the PLL parameters.

Plot as a function of time the phase error between the incoming carrier and the local carrier.

Demodulate the signal to obtain . Plot the demodulated as compared with the transmitted . Do you observe any 180 degrees phase ambiguity?

clc

clear

close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ts = 0.006; % sampling time

% use ustep function to define the message signal

t = -1:ts:5;

m_sig = heaviside(t)-2*heaviside(t-1) + 2*heaviside(t-2) - 2*heaviside(t-3) + heaviside(t-4);

Lm_sig = length(m_sig);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% modulation with 30 Hz signal

fc = 30;                    % carrier freq.

st = m_sig.*cos(2*pi*fc*t); % DSB-SC signal % st_err = m_sig.*cos(2*pi*(fc+0.2)*t)*2; % % DSB-SC signal carrier frequency error of 0.2 Hz

% squaring the signal

xt = st.^2;

% passing through the fir BPF fitler

a = 0.5;

b = fir1(48, [(4*fc-1)*ts, (4*fc+1)*ts]); % parameters of BPF

xt_bpf = filter(b, a, xt);                % an ideal BPF with bandwidth 1 Hz

% demodualted signal

B_m = 1; % Bandwidth of the signal is B_m Hz.

h1 = fir1(40, [B_m*ts]);

s_dem = st.*cos(2*pi*(fc+0.2)*t)*2;

s_rec = filter(h1, 1, s_dem); % Using an ideal LPF with bandwidth 1 Hz

% data in frequency domain

Lfft = length(t);

Lfft = 2^ceil(log2(Lfft)+1);

freqs = (-Lfft/2 : Lfft/ 2 - 1)/(Lfft*ts);

M_fre = fftshift(fft(m_sig ,Lfft)); % applying fft

St_fre = fftshift(fft(st ,Lfft)); % applying fft

Xt_fre = fftshift(fft(xt ,Lfft)); % applying fft

XtBPF_fre = fftshift(fft(xt_bpf ,Lfft)); % applying fft

Srec_fre = fftshift(fft(s_rec ,Lfft)); % applying fft

% phase error

wc = 2*pi*fc; % w0 - wc = 0.2*2*pi

w0 = 0.4*pi + wc;

phi0 = 2*pi/180;% in radians

theta_e = (w0 - wc).*(1 - exp(-t)) + phi0.*exp(-t);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% plotting results

figure, subplot(2,1,1)

td1 = plot(t, m_sig);

axis([-1 5 -2 2]);

set(td1, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('{it m}({it t})');

title('message signal (time)');

subplot(2,1,2)

fd1 = plot(freqs, abs(M_fre));

axis([-80 80 0 500]);

set(fd1, 'Linewidth' ,1.5);

xlabel('{it f} (Hz)'); ylabel('{it M}({it f})');

title('message signal (spectrum)');

figure, subplot(2,1,1)

td2 = plot(t, st);

axis([-1 5 -2 2]);

set(td2, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('{it s}({it t})');

title('modulated signal (time)');

subplot(2,1,2)

fd2 = plot(freqs, abs(St_fre));

axis([-80 80 0 500]);

set(fd2, 'Linewidth' ,1.5);

xlabel('{it f} (Hz)'); ylabel('{it S}({it f})');

title('squared modulated signal (spectrum)');

figure, subplot(2,1,1)

td3 = plot(t, xt);

axis([-1 5 -2 2]);

set(td3, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('{it x}({it t})');

title('modulated signal (time)');

subplot(2,1,2)

fd3 = plot(freqs, abs(St_fre));

axis([-80 80 0 500]);

set(fd3, 'Linewidth' ,1.5);

xlabel('{it f} (Hz)'); ylabel('{it X}({it f})');

title('squared modulated signal (spectrum)');

figure, subplot(2,1,1)

td4 = plot(t, xt);

axis([-1 5 -2 2]);

set(td4, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('{it x_{BPF}({it t})}');

title('modulated signal from Band pass filter (time)');

subplot(2,1,2)

fd4 = plot(freqs, abs(Xt_fre));

axis([-80 80 0 500]);

set(fd4, 'Linewidth' ,1.5);

xlabel('{it f} (Hz)'); ylabel('{it X_{BPF}({it f})}');

title('squared modulated signal Band pass filter (spectrum)');

figure, subplot(2,1,1)

td4 = plot(t, s_rec);

axis([-1 5 -2 2]);

set(td4, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('{it m_{demod}({it t})}');

title('demodulated signal (time)');

subplot(2,1,2)

fd4 = plot(freqs, abs(Srec_fre));

axis([-80 80 0 500]);

set(fd4, 'Linewidth' ,1.5);

xlabel('{it f} (Hz)'); ylabel('{it M_{demod}}({it f})');

title('demodulated signal (spectrum)');

figure, plot(t, theta_e)

xlabel('t'); ylabel(' heta_e(t)')

title('Part 1: Phase error heta_e(t) with frequency error of 0.2 Hz')

grid on

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Costas loop

Design the loop by picking the right bandwidth of the LPF’s and the PLL parameters.

Plot as a function of time the phase error between the incoming carrier and the local carrier.

Demodulate the signal to obtain . Plot the demodulated as compared with the transmitted . Do you observe any 180 degrees phase ambiguity?

clc

clear

close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ts = 0.006; % sampling time

% use ustep function to define the message signal

t = -1:ts:5;

m_sig = ustep(t)-2*ustep(t-1) + 2*ustep(t-2) - 2*ustep(t-3) + ustep(t-4);

Lm_sig = length(m_sig);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% modulation with 30 Hz signal

fc = 30;                    % carrier freq.

st = m_sig.*cos(2*pi*fc*t); % DSB-SC signal % st_err = m_sig.*cos(2*pi*(fc+0.2)*t)*2; % % DSB-SC signal carrier frequency error of 0.2 Hz

theta_0 = 0.1*pi;           % phase offset

% phase error

wc = 2*pi*fc; % w0 - wc = 0.2*2*pi

w0 = 0.4*pi + wc;

phi0 = 2*pi/180;% in radians

theta_e = (w0 - wc).*(1 - exp(-t)) + phi0.*exp(-t);

theta_i = theta_e + theta_0;

% demodualted signal

B_m = 1; % Bandwidth of the signal is B_m Hz.

h = fir1(40, [B_m*ts]);

s_dem = st.*cos(2*pi*(fc+0.2)*t)*2;

s_rec = filter(h, 1, s_dem); % Using an ideal LPF with bandwidth 1 Hz

Lfft = length(t);

Lfft = 2^ceil(log2(Lfft)+1);

freqs = (-Lfft/2 : Lfft/ 2 - 1)/(Lfft*ts);

Srec_fre = fftshift(fft(s_rec ,Lfft)); % applying fft

% phase error

wc = 2*pi*fc; % w0 - wc = 0.2*2*pi

w0 = 0.4*pi + wc;

phi0 = 2*pi/180;% in radians

theta_e = (w0 - wc).*(1 - exp(-t)) + phi0.*exp(-t);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% plotting results

figure

td1 = plot(t, 2.*cos(wc.*t + theta_0));

axis([-1 5 -3 3]);

set(td1, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('2 cos(omega_ct + heta_0)');

title('Plot for t vs 2 cos(omega_ct + heta_0)');

figure

td2 = plot(t, 2.*sin(wc.*t + theta_0));

axis([-1 5 -3 3]);

set(td2, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('2 sin(omega_ct + heta_0)');

title('Plot for t vs 2 sin(omega_ct + heta_0)');

figure

td3 = plot(t, m_sig.*cos(theta_e));

axis([-1 5 -3 3]);

set(td3, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('m(t)( heta_e)');

title('Plot for t vs m(t) cos( heta_e)');

figure

td4 = plot(t, m_sig.*sin(theta_e));

axis([-1 5 -3 3]);

set(td4, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('m(t)( heta_e)');

title('Plot for t vs m(t) sin( heta_e)');

figure

td5 = plot(t, 0.5*m_sig.*m_sig.*sin(2.*theta_e));

axis([-1 5 -3 3]);

set(td5, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('m(t)( heta_e)');

title('Plot for t vs 1/2 m^2(t) sin(2 heta_e)');

figure, subplot(2,1,1)

td4 = plot(t, s_rec);

axis([-1 5 -2 2]);

set(td4, 'Linewidth' ,1.5);

xlabel('{it t} (sec)');

ylabel('{it m_{demod}({it t})}');

title('demodulated signal (time)');

subplot(2,1,2)

fd4 = plot(freqs, abs(Srec_fre));

axis([-80 80 0 500]);

set(fd4, 'Linewidth' ,1.5);

xlabel('{it f} (Hz)'); ylabel('{it M_{demod}}({it f})');

title('demodulated signal (spectrum)');

figure, plot(t, theta_e)

xlabel('t'); ylabel(' heta_e(t)')

title('Part 2: Phase error heta_e(t) with frequency error of 0.2 Hz')

grid on

Explanation / Answer

I have checked in Matlab , DSBSC receive signal is correct with plots

But in costas loop

Error in (line 15)

ustep is undefined function or variable

m_sig = ustep(t)-2*ustep(t-1) +
2*ustep(t-2) - 2*ustep(t-3) +
ustep(t-4);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote