Question about adding frequency/phase offsets into code for a synchronous demodulator

18 views (last 30 days)
Hi. I was just wondering how would I add a frequency and phase offset into my current code. I want to compare the two, but understand that I can only run one at a time as they're part of the same command.
But basically I just want to be able to first run 4 lots of frequency offsets, then run 4 lots of phase offsets from 0 to 360 to compare the results, but I'm not exactly sure how to do so. Any help would be appreciated. I have left my full code below also.
I'm wanting to run the code at a modulation depth of infinity for the synchronous demodulator using a non-coherent local oscillator in the demodulator, which has the frequency/phase offsets to change, so I'm only going to be looking at/analyzing the demodulated signal.
% Synchronous Modulator/Demodulator
% MATLAB script for Illustrative Problem 3.5.
% script for DSB-AM synchronous demodulation. The message signal
% is +1 for 0 < t < t0/3, -2 for t0/3 < t < 2t0/3, and zero otherwise.
% message is also cosine at 20Hz with Vm=1;
% a is the modulation index and can be varied
close all
clear all
clc
%%echo on
t0=.75; % signal duration
ts=1/1500; % sampling interval
fm=50; % message signal frequency
fc=4; % carrier frequency
a=1; % Modulation index a = amplitude of message/ amplitude of carrier
fs=1/ts; % sampling frequency
t=[0:ts:t0]; % time vector
df=0.3; % desired frequency resolution
% message signal
m=[ones(1,t0/(3*ts)),-2*ones(1,t0/(3*ts)),zeros(1,t0/(3*ts)+1)];
m=cos(2*pi*fm.*t);
c=cos(2*pi*fc.*t); % carrier signal
u=m.*c; % modulated signal
m_n=m/max(abs(m)); % normalized message signal
u=(1+a*m_n).*c; % modulated signal
%received signal
y=u.*c; % mixing
%Local oscillator - change the frequency and phase of c by desired values
[M,m,df1]=fftseq(m,ts,df); % Fourier transform
M=M/fs; % scaling
[U,u,df1]=fftseq(u,ts,df); % Fourier transform
U=U/fs; % scaling
[Y,y,df1]=fftseq(y,ts,df); % Fourier transform
Y=Y/fs; % scaling
f_cutoff=150; % cutoff freq. of the filter
n_cutoff=floor(150/df1); % Design the filter.
f=[0:df1:df1*(length(y)-1)]-fs/2;
H=zeros(size(f));
H(1:n_cutoff)=2*ones(1,n_cutoff);
H(length(f)-n_cutoff+1:length(f))=2*ones(1,n_cutoff);
DEM=H.*Y; % spectrum of the filter output
dem=real(ifft(DEM))*fs; % filter output
% the effect of mixing.
figure(1);
subplot(3,1,1)
plot(m(1:length(t)))
title('Waveform of the Message Signal')
xlabel('Time')
subplot(3,1,2)
plot(u(1:length(t)))
title('Waveform of the Modulated Signal')
xlabel('Time')
subplot(3,1,3)
plot(y(1:length(t)))
title('Waveform of the Mixer Output')
xlabel('Time')
figure(2);
subplot(3,1,1)
plot(f,fftshift(abs(M)))
title('Spectrum of the Message Signal')
xlabel('Frequency')
subplot(3,1,2)
plot(f,fftshift(abs(U)))
title('Spectrum of the Modulated Signal')
xlabel('Frequency')
subplot(3,1,3)
plot(f,fftshift(abs(Y)))
title('Spectrum of the Mixer Output')
xlabel('Frequency')
% the effect of filtering on the mixer output.
figure(3);
subplot(3,1,1)
plot(f,fftshift(abs(Y)))
title('Spectrum of the Mixer Output')
xlabel('Frequency')
subplot(3,1,2)
plot(f,fftshift(abs(H)))
title('Lowpass Filter Characteristics')
xlabel('Frequency')
subplot(3,1,3)
plot(f,fftshift(abs(DEM)))
title('Spectrum of the Demodulator output')
xlabel('Frequency')
% to compare the spectra of the message and the received signal.
figure(4);
subplot(2,1,1)
plot(f,fftshift(abs(M)))
title('Spectrum of the Message Signal')
xlabel('Frequency')
subplot(2,1,2)
plot(f,fftshift(abs(DEM)))
title('Spectrum of the Demodulator Output')
xlabel('Frequency')
% the message and the demodulator output signals.
figure(5);
pfo = comm.PhaseFrequencyOffset('PhaseOffset',270);
subplot(2,1,1)
plot(t,m(1:length(t)))
title('The Message Signal')
xlabel('Time')
subplot(2,1,2)
plot(t,dem(1:length(t)))
title('The Demodulator Output')
xlabel('Time')
  2 Comments
Meck
Meck on 13 Jan 2021
For some reason the post got editted so ill say this as a answer reply to my post.
This post can be ignored as I didnt notice the phase/freq offset added into the demodulated graph. With it present all I need to do is change the name to frequency or phase along with the value to run and ill be set.

Sign in to comment.

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!