Filtering in Digital Communications
Filtering in Digital Communications
AY 2023-24
Department of ECE
Digital Communication (22EC2208) AY 2023-24
Module-3: Filtering the Communication Signals
The main aim of this module is to study and gain the knowledge of filtering the communication
signals in both time domain and frequency domain.
Skilling Objectives:
3.1 Introduction:
Linear and time invariant LTI systems are particularly important classes of systems has
significant signal processing applications. These systems satisfy both the linearity and time-
invariant properties which is desired properties for real time applications. The processing of
signals in time domain through continuous time (or Discrete time) systems are usually referred
to as convolution or filtering operation.
The processing of signals using convolution leads to computationally intensive for long data
records. On the other hand, processing operations in the frequency domain are much faster
because of two reasons:
(i) by taking advantages of property of FT: i.e., convolution of two signals in time domain leads
to multiplication in the frequency domain, which is simple operation than convolution,
(ii) faster algorithms are available for computing FT due to technological development.
The filtering techniques used in this project are illustrated briefly in the following figure.
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
is known as convolution integral equation. This operation is also known as filtering the signals in
the signal processing community.
Worked Examples (WE): The analytical solutions and corresponding Matlab scripts written for
following examples are provided to understand and gain programming skills.
Consider a rectangular pulse having unit width, unit height and centered at origin is applied
% Define signal x(t) a rectangular pulse having unit height and unit width
% centered at origin.
w = 1; % Width of the pulse centered at origin
x = rectpuls(t, w);
y = (0.002)*conv(x,h);
t2 = -2:0.001:10; % Time index for y(t)
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
figure();set(gca,'fontsize',14);
subplot(3,1,1);plot(t, x,'m','LineWidth',3);
set(gca,'fontsize',14);
xlabel('time ----->','FontSize',14);
ylabel('Amplitude ----->','FontSize',14);
title('x(t)','FontSize',16); axis([-1 3 -0.2 1.2]);
xline(0,'k','LineWidth',2);yline(0,'k','LineWidth',2);
subplot(3,1,2);plot(t, h,'b','LineWidth',3);
set(gca,'fontsize',14);
xlabel('time ----->','FontSize',14);
ylabel('Amplitude ----->','FontSize',14);
title('h(t)','FontSize',16);axis([-1 3 -0.2 1.2]);
xline(0,'k','LineWidth',2);yline(0,'k','LineWidth',2);
subplot(3,1,3);plot(t2, y/0.002,'r','LineWidth',3);
set(gca,'fontsize',14);
xlabel('time ----->','FontSize',14);
ylabel('Amplitude ----->','FontSize',14);
title('y(t)=x(t)*h(t)','FontSize',16);axis([-1 3 -0.2 1.2]);
xline(0,'k','LineWidth',2);yline(0,'k','LineWidth',2);
3.2.1: Practice problems (PP) on convolution: Students are instructed to work out the
analytical solutions for the following problems, develop Matlab codes, simulate and verify the
results.
Task1: Determine analytically the convolution of the following signals, and verify your answers
subplot(3,1,2);
plot(t, h);
xlabel('t');
ylabel('h(t)');
title('Signal h(t) = u(t) - u(t-1)');
subplot(3,1,3);
plot(t_conv, y);
xlabel('t');
ylabel('y(t)');
title('Convolution of x(t) and h(t)');
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
Task2: An LTI system consists of two sub-systems and in cascaded as shown below.
and .
plot(t_conv, h);
xlabel('t');
ylabel('h(t)');
title('Resultant Impulse Response h(t) of the Cascaded System');
3.3 Noise: Electrical noise is defined as undesirable electrical energy that falls within the pass
band of the signal. For example, in the transmission of RF signal, any unwanted electrical signals
that fall within the audio frequency band of 0 Hz to 15 kHz will interfere with the music and therefore
be considered as noise.
Let denote a noisy signal. Then the values of noisy signal are unpredictable and only a
probability can be associated to them, . The most common type of noise found in
a communication system is Gaussian with PDF
.
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
where is the average noise power per unit band width of white noise measured in watt / Hz,
and the factor ½ has been included to indicate the half of the power is associated with the
positive frequency and remaining half of with the negative frequencies as shown in the figure
Fig.2.
WE3.2: Develop Matlab script to generate and plot an additive white Gaussian noise (AWGN)
and its power spectral density with mean zero and variance 0.01.
Zero mean
var = 0.01
var = 0.0100
sigma = sqrt(var)
sigma = 0.1000
var_dB = 10*log(var)
var_dB = -46.0517
X = 10000×1
-0.1809
0.1060
0.1755
-0.0477
0.0563
-0.0095
-0.2099
-0.0882
-0.1495
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
0.0907
⋮
% X = sigma*randn(size(t))
sound(X,Fs);
figure();
stem(X,'m','fill','LineWidth',2);
% title('White noise');
title(['White noise : \mu_x=',num2str(mu),' \sigma^2=',num2str(sigma^2)])
xlabel('Samples'); ylabel('Sample values');
axis([0 25 -0.5 0.5]);
% Frequency axis
% N = length(t);
f = (-N/2:1:N/2-1)*Fs/N;
plot(f,abs(Xf)/max(abs(Xf)),'b','LineWidth',2);
title('Spectrum of White Noise');
axis([-1000 1000 -0.01 1]);grid on
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
xlabel('Frequency --->');ylabel('Magnitude--->');
[pxx,f] = pwelch(X,[],[],[],Fs);
plot(f/1000,pow2db(pxx),'m','LineWidth',1);
axis([0 5 -120 -40]); grid
title('PSD of AWGN Noise');
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
Task3: Develop Matlab script to generate and plot an additive white Gaussian noise (AWGN)
and its power spectral density with the following specifications:
% Define parameters
Fs = 1000; % Sampling frequency (Hz)
T = 1; % Duration of the signal (seconds)
t = 0:1/Fs:T-1/Fs; % Time vector
% Define variances
variances = [0.05, 0.5, 1];
% Plot AWGN
subplot(3, 2, 2*i-1);
plot(t, noise);
xlabel('Time (s)');
ylabel('Amplitude');
title(['AWGN with Variance = ', num2str(variances(i))]);
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
3.4. Filtering the communication signals: The signals are usually corrupted by
unwanted noise and undesired frequency components while acquisition. Hence it is desired to
filter or suppress the undesired signal components and noise. Filtering the signals can be done
both in time domain and frequency domain.
3.4.1: Time domain filtering: Convolution operation discussed in section 3.2 is also referred
to as filtering in time domain. Another time domain filter is known as average filtering is
illustrated below,
3.4.1(a) Averaging filter: The averaging filter is used in smoothing random variations in data.
Average Filter:
By taking the average of the signal for n-point values, the noise will reduce. The
following Matlab code is used with n= 3.
ya = zeros(size(x));
for n=3:length(xn) % 3 point averaging filter
ya(n)=sum(xn(n-2:n))/3; %y[n] is the filtered signal
end
Now plot the signal and observe the denoised signal. The following Matlab code
is used to plot the signals.
figure();
subplot(3,1,1); plot(t,x,'r','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
title('Original Signal'); xlabel('Time ----->');
ylabel('Amplitude---->');
subplot(3,1,2); plot(t,xn,'b','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
subplot(3,1,3); plot(t,1.2*ya,'m','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
hold on; plot(t,x,'k--','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
legend('Denoised', 'Original');
title('Denoised Signal'); xlabel('Time ----->'); ylabel('Amplitude---->');
Task4: Now change to n = 5, 7, 9, . . . 21 point average filter. For example, 7 point averaging
filter the modified code is given below. Find the phase difference for each case and tabulate.
Comment on the results.
for n=7:length(xn) % 7 point average filter
ya(n)=sum(xn(n-6:n))/7; %y[n] is the filtered signal
end
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
Task5: Now change the variance for various values and observe the results. Comment on the
results.
3.4.1(b) Filtering using Convolution: We will solve the problem of denosing using
convolution algorithm:
Plot the reconstructed signal y(t) and compare with the original signal.
figure();
subplot(3,1,1); plot(t,x,'r','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
title('Original Signal'); xlabel('Time ----->');
ylabel('Amplitude---->');
subplot(3,1,2); plot(t,xn,'b','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
title('Noisy Signal'); xlabel('Time ----->');
ylabel('Amplitude---->');
subplot(3,1,3); plot(t,real(yc),'m','LineWidth',1.5);
axis([-0.005 0.005 -4.2 4.2]);
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
obtain .
% System function
H = (2/N)*fftshift(fft(h)); % System function
% Inverse FT of 'Y'
yf = ifft(ifftshift(Y));
yf = real(yf);
yf = yf / max(yf);
figure();
subplot(3,1,1); plot(t,x,'r','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
title('Original Signal'); xlabel('Time ----->');
ylabel('Amplitude---->');
subplot(3,1,2); plot(t,xn,'b','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
title('Noisy Signal'); xlabel('Time ----->');
ylabel('Amplitude---->');
subplot(3,1,3); plot(t,real(yf),'m','LineWidth',1.5);
axis([-0.005 0.005 -1.2 1.2]);
title('Frequency domain filrered signal');
xlabel('Time ----->'); ylabel('Amplitude---->');
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
figure();
plot(t,x,'r','LineWidth',1.5); hold on
plot(t,real(ya),'b','LineWidth',1.5); hold on
plot(t,real(yc)/4,'g.-','LineWidth',1.5); hold on
plot(t,real(yf),'k--','LineWidth',1.5); hold on
axis([-0.005 0.005 -1.2 1.2]);
legend('Original', 'Average','Convolution', 'FFT');
hold off
Task6: Now change the variance for various values and observe the results. Comment on the
results.
3.6 Filtering effects on communication signals:
The filters are broadly classified as low pass filter (LPF), high pass filter (HPF), band pass filter
(BPF) and band rejection filter (BRF). The following example illustrates the effectiveness of various
filters on a speech signal.
WE3.6: Load a speech signal ‘speech.wav’. Plot this signal and its spectrum. From the spectrum
find the highest frequency.
% data = load('mclips.mat');
% sound(data);
3.5 (a) Low Pass Filter(LPF): Choose a cut off frequency of 2200 Hz. Then use the
following commands for LPF.
%================== LPF================
% Choose cut-off frequency ___ Hz.
Fc1 = 2200; % Cut-off frequency in Hz.
[b, a] = butter(12, (2/Fs)*Fc1);
y_lpf = filter(b,a, data);
Task7: Plot the original speech and low pass filtered speech signal and their spectrum.
Conclude your observations.
3.6 (b) High Pass Filter (HPF): Choose a cut off frequency of 1200 Hz. Then use
the following commands for HPF.
Task8: Plot the original speech and high pass filtered speech signal and their spectrum.
Conclude your observations.
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
4.5 (c) Band Pass Filter(BPF): Choose a cut off frequencies 1200 Hz and 2200 Hz. Then
use the following commands for BPF.
Task9: Plot the original speech and band-pass filtered speech signal and their spectrum.
Conclude your observations.
4.5 (d) Band rejection Filter(BPF): Choose a cut off frequencies 1500 Hz and 1600 Hz. Then
use the following commands for BPF.
Task10: Plot the original speech and band rejection filtered speech signal and their spectrum.
Conclude your observations.
3.7. Project Assignments: Students are instructed to work out the following Project
Assignment tasks.
3.7.1 Project Assignment1: Filtering the undesired frequency component and noise.
application. Unfortunately, the signal is corrupted by the power line signal while
acquisition. Now it is desired to remove the power line signal.
Task PA1 Time domain filtering: Perform both time domain filtering (averaging filtering and
convolution operation) techniques.
Noiseless case: Consider the signal is not degraded further by noise.
Task PA1.1 Averaging filter: Perform the N-point averaging filter, for N = 7, 15, 27 and
observe the results. Whether the undesired signal component is suppressed or not? Comment
on each case.
Task PA1.2 Convolution operation: Since the desired signal frequency is 5 Hz, select the
Find the length of the signal , and correspondingly define the time index for display
the signal.
Perform the convolution operation by typing the following command
y = conv(s, h, ‘same’);
Find the length of the signal and compare with the results above step and
comment.
Task PA1.3 Noisy case: Suppose the signal is degraded further by additive white
Gaussian noise (AWGN) with variance . Let the noisy signal is referred to as
.
3.7.2 Frequency domain filtering: As mentioned earlier the convolution operation is
computationally intensive for long data. By the convolution theorem of FT, the convolution of
two signals in the time domain leads to multiplication in the frequency domain. By taking the
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
advantages of this property, undesired signals and noise can be filtered in the frequency
domain.
Task PA2.1 (a) Noiseless case: Again, consider the signal is not degraded further by noise.
Perform the inverse FT to obtain . Plot the signal and its spectrum.
Observe the plot of the signal . Is it a desired signal? Overlap the 5 Hz original
1. Speech signal: The speech signal has frequency components in the audio frequency
range 20 Hz to 20 kHz of the electromagnetic spectrum. This is the reason for perceiving
the information present in the speech signal by human ears. Since sound signals are
represented as vectors in MATLAB, you can do any mathematical operation on the sound
signals that you could do on elements in a vector. In other words, you can create your own
sounds with MATLAB scripts and functions.
To record data from an audio input device (such as a microphone connected to your system)
for processing in MATLAB:
record returns immediate control to the calling function or the command prompt even as
recording proceeds. Specify the length of the recording in seconds, or end the recording
Digital Coomunication 22EC2208, KLEF Deemed to be University, A.P., India. AY 2023-24
with the stop method. Optionally, call the pause and resume methods. The recording is
performed asynchronously.
record blocking retains control until the recording is complete. Specify the length of the
recording in seconds. The recording is performed synchronously.
(c) Create a numeric array corresponding to the signal data using the getaudiodata
method.
(d) The recorded data can be listened with play or sound command
(e) Recorded real time speech signal can be saved with save command in different formats
and also load and display to obsever basic parameters of the signals.