Communication System Matlab
Communication System Matlab
Communication System Matlab
Task # 01: Generate a square wave of a frequency of your own choice in kHz range and plot it
on Matlab.
Matlab code:
Graph:
1.5
0.5
Amplitude
-0.5
-1
-1.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Seconds
0.5
Amplitude
-0.5
-1
-1.5
0 0.005 0.01 0.015
Seconds
As it can be seen in the above graph that it is an ideal square wave of amplitude equals 1, time
period is 1mS and zero centric. In-built function of Matlab was used to generate square of
frequency 1 kHz.
Task # 02: Represent the above generated square wave using compact Fourier series and show
its amplitude and phase response.
A common engineering analysis technique is the partitioning of complex problems into simpler
ones. The simpler problems are then solved, and the total solution becomes the sum of the
simpler solutions Three requirements must be satisfied for such a solution to be both valid and
useful.
1. First, we must be able to express the problem as a number of simpler problems.
2. Next, the problem must be linear, such that the solution for the sum of functions is equal to the
sum of the solutions when we consider only one function at a time.
3. The third requirement is that the contributions of the simpler solutions to the total solution
must become negligible after we consider only a few terms; otherwise, the advantage may be lost
if a very large number of simple solutions is required.
The Fourier analysis provides one of the most powerful and important set of tools and insights
for analyzing, designing and understanding signals and LTI systems. In Fourier analysis a signal
is decomposed into its constituent sinusoids, i.e. frequencies, the amplitudes of various
frequencies form the frequency spectrum of the signal. In an inverse Fourier transform operation
the signal can be synthesized by adding up its constituent frequencies.
Fourier series is an approximation of a non-sinusoidal periodic function with a (sum of)
sinusoids. With reasonable accuracy, a periodic signal can be expressed by a sinusoid. This
approximate response would be the sinusoidal steady-state response of a linear system.
The following properties make the sinusoids the ideal choice as the elementary building block
basis functions for signal analysis and synthesis:
Orthogonality; two sinusoidal functions of different frequencies have the following orthogonal
property
For harmonically related sinusoids the integration can be taken over one period. Similar
equations can be derived for the product of cosines, or sine and cosine, of different frequencies.
Orthogonality implies that the sinusoidal basis functions are independent and can be processed
independently.
1. Sinusoidal functions are infinitely differentiable. This is important, as most signal analysis,
synthesis and manipulation methods require the signals to be differentiable.
2. Sine and cosine signals of the same frequency have only a phase difference of π/2 or
equivalently a relative time delay of a quarter of one period i.e. T0/4 . The Fourier expression of
compact trigonometric fourier series is given by the following equations:
Matlab code for magnitude and phase response:
clear; % clear all variables
clf; % clear all figures
figure(1)
yt = c0*ones(size(t)); % initialize yt to c0
xlabel('w (rad/s)')
ylabel('|ck|')
title(strcat('Magnitude Spectrum with N = ',num2str(N),' harmonics'));
grid on;
subplot(2,1,2)
stem(0,angle(c0)*180/pi); % plot angle of c0 at kwo = 0
hold;
for k = 1:2:N, % loop over odd series index k
ck = 2/(1i*k*pi); % Fourier Series Coefficient
stem(k*wo,angle(ck)*180/pi); % plot |ck| vs kwo
end
for k = 0:2:N-1, % loop over even series index k
ck = 0; % Fourier Series Coefficient
stem(k*wo,angle(ck)*180/pi); % plot |ck| vs kwo
end
xlabel('w (rad/s)')
ylabel('angle(ck) (degrees)')
title(strcat('Phase Spectrum with N = ',num2str(N),' harmonics'));
grid on;
k =
0 1 2 3 4 5
Ck =
0.5
y(t)
-0.5
-1
-1.5
0 0.5 1 1.5 2 2.5
t (seconds) -3
x 10
Magnitude plot & Phase plot:
Magnitude Spectrum with N =11 harmonics
0.8
0.6
|ck|
0.4
0.2
0
0 1 2 3 4 5 6 7
w (rad/s) 4
x 10
Phase Spectrum with N =11 harmonics
0
angle(ck) (degrees)
-50
-100
0 1 2 3 4 5 6 7
w (rad/s) 4
x 10
Task # 03:
Matlab code:
% 1kHz square wave
clc
close all;
clear all;
t = -0.002:0.000001:0.002;
y=0; % first signal
for k=1:2:100;
y=y+((1/k)*(4/pi)*sin(2*pi*k*1000*t));
figure(1)
plot(t,y);
hold on
end
figure(2)
subplot(1,2,1);
plot(t,y);
x= square(2*pi*1000*t); % second signal
subplot(1,2,2);
plot(t,x)
axis([-0.002 0.002 -1.5 1.5]);
xlabel('Seconds');
ylabel('Amplitude')
title('square wave')
E1=sum(x.*conj(x))*0.000001; % computing signal energies
E2=sum(y.*conj(y))*0.000001;
C=sum(x.*conj(x))*0.000001/(sqrt(E1*E2));
C1=sum(x.*conj(y))*0.000001/(sqrt(E1*E2))
Matlab plot:
1.5
0.5
-0.5
-1
-1.5
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
-3
x 10
square wave
1.5 1.5
1 1
0.5 0.5
Amplitude
0 0
-0.5 -0.5
-1 -1
-1.5 -1.5
-2 -1 0 1 2 -2 -1 0 1 2
-3 Seconds -3
x 10 x 10
C1 = 0.9977
Task # 04: Suggest an appropriate value of N considering that the square waves generated in
task 1 and 3 lie within 10 % difference.
The approach used to perform this task is calculation of total power of ideal square wave and
then comparing it with the sum of power of individual harmonics. The first four harmonics of
square wave contributes 90 % power of the total. So it has a 10% power less than the ideal
square wave.
The expression for Fourier series of the square wave is
∝ 4𝑉𝑠𝑖𝑛𝑤𝑜𝑡
𝑥(𝑡) = ∑ 𝑘=1
𝑘 𝑜𝑑𝑑
𝑘𝜋
The power of harmonics can be calculated as
∝ 4𝑉
𝑥(𝑡) = ∑ 𝑘=1 ([ ]^2)/2
𝑘 𝑜𝑑𝑑
𝑘𝜋
And the power of ideal square wave was calculated by formula
Matlab code:
% 1kHz square wave
clc
close all;
clear all;
t = -0.002:0.000001:0.002;
y=0; % first signal
for k=1:2:7;
y=y+((1/k)*(4/pi)*sin(2*pi*k*1000*t));
end
subplot(1,2,1);
plot(t,y);
x= square(2*pi*1000*t); % second signal
subplot(1,2,2);
plot(t,x)
axis([-0.002 0.002 -1.5 1.5]);
xlabel('Seconds');
ylabel('Amplitude')
title('square wave')
E1=sum(x.*conj(x))*0.000001; % computing signal energies
E2=sum(y.*conj(y))*0.000001;
C=sum(x.*conj(x))*0.000001/(sqrt(E1*E2));
C1=sum(x.*conj(y))*0.000001/(sqrt(E1*E2))
C1 =
0.9743
Figure:
square wave
1.5 1.5
1 1
0.5 0.5
Amplitude
0 0
-0.5 -0.5
-1 -1
-1.5 -1.5
-2 -1 0 1 2 -2 -1 0 1 2
-3 Seconds -3
x 10 x 10
In above plot, it is showed that the wave synthesized from Fourier series have the same
amplitude and frequency, the shape has a Gibb’s effect at the ends (turning point of wave)
because the number of harmonics are less, if they are increased ideally infinite, the wave will
look more ideal. If the number of harmonics is increased, the square wave generated will be
much better than before but at the cost of time i.e. latency has increased due to increase in
number of computations. It can be seen the above generated wave from its Fourier
components (up to 4 harmonics) has 90 % resemblance to original square wave.
Question # 02:
Task # 01:Generate a voice signal using windows sound card utility and display it in the Matlab
(both time and frequency domain response).
This task was performed by firstly recording of a 4 to 5 seconds sound by sound recorder of
windows which was save with .wma extension.
Matlab code:
% =============================
% Plotting signal in time domain
% =============================
figure(1);
subplot(2,1,1);
plot(t,m,'b');
title('Message Signal');
xlabel('t(sec)');
ylabel('m(t)');
axis([0.6 1.8 -0.07 0.07]);
grid on;
% ================================
% Plotting Freq Response of Signal
% ================================
figure(1);
subplot(2,1,2);
plot(f,mF,'b');
title('Freq Responce of Message Signal');
xlabel('f(Hz)');
ylabel('M(f)');
axis([0 12000 0 300]);
grid on;
Display in time and frequency domain:
Message Signal
0.05
m(t)
-0.05
200
M(f)
100
0
0 2000 4000 6000 8000 10000 12000
f(Hz)
It can be seen that the components of audio signal are band limited to 15 kHz which is the
maximum range of an audio signal. B (bandwidth) of this signal is 15 kHz but the significant
information lies up to 6000 Hz. The spectra is showing that the frequency components below
200Hz have also less significance. The major information and power of voice lies within 500 to
6000 Hz.
Task # 02: Generate a DSB-SC waveform using the above signal and an appropriate bandpass
carrier signal. Show the modulated signal both in time and frequency domains.
Matlab code:
(Generation of voice by windows Sound card utility
[m,fs]=audioread('C:\users\Soman\desktop\untitled.wma'); %read audio
file (Fs=samples per second)
%sound(m,fs);
m=m(:,1); % message signal (voice) in time domain
dt=1/fs; % seconds per sample
t=0:dt:(length(m)*dt)-dt; % Time specifications in second
N=length(m);
f=(10*fs)/N.*(0:N-1); % Frequency specifications in hertz
mF=fft(m,N); % Fourier Transform
mF=abs(mF); % message signal in frequency domain
figure(1);
subplot(2,1,1);
plot(t,dsbsc,'r');
title('DSBSC');
xlabel('t(sec)');
ylabel('DSBSC');
axis([0.6 1.8 -0.07 0.07]);
grid on;
% ================================
% Plotting Freq Response of Signal
% ================================
figure(1);
subplot(212);
plot(F,dsbsc_F,'r');
title('Freq Responce of DSBSC');
xlabel('f(Hz)');
ylabel('DSBSC(f)');
axis([0 65000 0 200]);
grid on;
0.05
DSBSC
-0.05
150
DSBSC(f)
100
50
0
0 1 2 3 4 5 6
f(Hz) 4
x 10
The above wave is a voice signal, so it is a mixture of frequencies with varying amplitude
carrying the information but now it has shifted to 60 kHz because of modulation.No carrier is
obtained in DSB-SC modulation as shown in the time plot and also spectra of signal.
Task # 03: Generate an Am waveform using the signal generated in task 1 and the carrier signal
from task 2. Show the modulated signal both in time and frequency domains.
Matlab code:
figure(1);
subplot(2,1,1);
plot(t,Am,'m');
title('AM');
xlabel('t(sec)');
ylabel('AM');
axis([0.6 1.6 -0.11 0.11]);
% ================================
% Plotting Freq Response of Signals
% ================================
subplot(212);
plot(F,Am_F,'m');
title('Freq Responce of AM');
xlabel('f(Hz)');
ylabel('AM(f)');
axis([0 65000 0 600]);
Time and frequency domain plot of amplitude modulated voice signal:
AM
0.1
0.05
AM
-0.05
-0.1
0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6
t(sec)
Freq Responce of AM
600
400
AM(f)
200
0
0 1 2 3 4 5 6
f(Hz) 4
x 10
Task # 04:Based on the results obtained from tasks 2 and 3 discuss if you achieved what
was expected.
In task 2, double sideband suppressed carrier was generated, so it contained less power because
carrier was suppressed there while in task 3, AM was generated having carrier, as a result more
energy contained in the signal and its spectrum. Amplitude modulation (AM) is similar to DSB
but has the advantage of permitting a simpler demodulator, the envelope detector.
In both tasks, after modulation the signal is not shifted to the specified carrier frequency, it may
be because I have taken the frequency axis by my own.
Task # 05:
Design a demodulator in Matlab (non-coherent) and show the demodulated signal in both
time and frequency domains. Based on your results do you think you will need an
amplification stage in the receiver?
Demodulator:
Type: Rectifier detector
The higher frequencies terms are eliminated by low pass filter and the output [A+m(t)]/π is
obtained, then the signal is amplified actually attenuated by a scalar π.
Matlab code:
(Generation of voice by windows Sound card utility
[m,fs]=audioread('C:\users\Soman\desktop\untitled.wma'); %read audio
file (Fs=samples per second)
%sound(m,fs);
m=m(:,1); % message signal (voice) in time domain
dt=1/fs; % seconds per sample
t=0:dt:(length(m)*dt)-dt; % Time specifications in second
N=length(m);
f=(10*fs)/N.*(0:N-1); % Frequency specifications in hertz
mF=fft(m,N); % Fourier Transform
mF=abs(mF); % message signal in frequency domain
% =============================
% designing lowpass filter
% =============================
% =============================
% Filtering the demodulated wave
% =============================
demod=filtfilt(Hd.Numerator,1,r);
demod_F=abs(fft(demod));
% =============================
% Plotting signals in time domain
% =============================
figure(1);
subplot(3,1,1);
plot(t,r);
title('rectified Signal');
xlabel('t(sec)');
ylabel('r(t)');
axis([0.6 1.8 0 0.12]);
grid on;
subplot(3,1,2);
plot(t,demod);
xlabel('time(sec)');
ylabel('Amplitude');
title('Time domain plot of demodulated voice signal');
axis([0.6 1.8 0 0.04]);
% ================================
% Plotting Freq Response of Signal
% ================================
figure(1);
subplot(313);
plot(f,demod_F);
title('Freq Responce of Recovered signal');
xlabel('f(Hz)');
ylabel('M(f)');
axis([0 12000 0 100]);
grid on;
rectified Signal
0.1
r(t)
0.05
0
0.6 0.8 1 1.2 1.4 1.6 1.8
t(sec)
Time domain plot of demodulated voice signal
0.04
Amplitude
0.02
0
0.6 0.8 1 1.2 1.4 1.6 1.8
time(sec)
Freq Responce of Recovered signal
100
M(f)
50
0
0 2000 4000 6000 8000 10000 12000
f(Hz)
When a low pass filter is applied to the demodulator, the term (A+m(t))/π is obtained, as it has a
dc offset of 1/π (amplitude of carrier divided by attenuation factor) and it is attenuated by a
factor π, so an amplification is required to make it original voice signal. Also a high pass filter is
required to get rid of dc offset. The cutoff frequency of the high pass filter should be
approximately 100 to 200 Hz. We will lose these frequency components of our voice signal but
that is not significant because a large number of information of voice signal lies within 500 to
3400 Hz range.
. Lowpass filter magnitude plot:
Magnitude Response (dB)
-10
-20
-30
Magnitude (dB)
-40
-50
-60
-70
-80
-90
-100
0 10 20 30 40 50 60
Frequency (kHz)