close all
clear all
clc
t0=.75;
ts=1/1500;
fm=50;
fc=4;
a=1;
fs=1/ts;
t=[0:ts:t0];
df=0.3;
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);
u=m.*c;
m_n=m/max(abs(m));
u=(1+a*m_n).*c;
y=u.*c;
[M,m,df1]=fftseq(m,ts,df);
M=M/fs;
[U,u,df1]=fftseq(u,ts,df);
U=U/fs;
[Y,y,df1]=fftseq(y,ts,df);
Y=Y/fs;
f_cutoff=150;
n_cutoff=floor(150/df1);
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;
dem=real(ifft(DEM))*fs;
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')
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')
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')
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')