Noise Removal & Signal Processing Lab
Noise Removal & Signal Processing Lab
INDEX
Theory: Types of noise: Wind, Electrical Noise, Interference, Ground Loops, Rumble, Mechanical
Noises, Equipment Self Noise, Background Noise. One of the problems is having sharp disturbances
or noise while having a smooth conversation. Moving mean method is used to reduce or smoothen the
sharp disturbances in a audio file or a conversation. In this method, the sliding window technique is
used where the window will be moving, and we calculate the mean or average of the elements present
in that window.
Python Program:
# Importing Libraries
import numpy as np
import matplotlib.pyplot as plt
# Signal
Signal = np.random.uniform(10,40,50)
# Plots
plt.plot(Signal, label='Signal', color='cyan')
plt.plot(FilteredSignal,label='Filtered Signal', color='crimson')
plt.legend()
plt.xlabel('Time')
plt.ylabel('Magnitude')
plt.title('Denoising Sensor Data using Moving Average Filter')
plt.show()
MATLAB Program:
Clear
close all
clc
%To load your own Audio file
%[y,fs] = audioread('D.wav');
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
Output Graphs:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
Aim: To remove the noise (salt pepper noise) from Image data using averaging filter and median
filters.
Python Program:
# Importing Libraries
from skimage import io, data, color, filters
from skimage.morphology import disk import
skimage
import matplotlib.pyplot as plt
# Image
Image = color.rgb2gray(data.rocket())
plt.figure('Original Image')
io.imshow(Image)
# Speckle Noise
ImageS = skimage.util.random_noise(Image, 'speckle')
ImageSF = filters.rank.mean(ImageS, disk(2))
plt.figure('Speckle Noise')
lt.subplot(1,2,1)
io.imshow(ImageS)
plt.title('Noisy Image')
plt.subplot(1,2,2)
io.imshow(ImageSF)
plt.title('Filtered Image')
# Gaussian Noise
ImageG = skimage.util.random_noise(Image, 'gaussian')
ImageGF = filters.gaussian(ImageG)
plt.figure('Gaussian Noise')
plt.subplot(1,2,1)
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
io.imshow(ImageG)
plt.title('Noisy Image')
plt.subplot(1,2,2)
io.imshow(ImageGF)
plt.title('Filtered Image')
plt.show()
MATLAB program:
Filter the noise image with an averaging filter:
OUTPUT:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
% Low-pass filter (10 kHz cutoff), low-shelf filter (200 Hz, 2 dB), and notch filter (880 Hz)
[blpf, alp] = butter(2, 10000 / (fs / 2), 'low');
G_ls = 10^(2 / 20); [bls, als] = shelf(200, 1.4, G_ls, fs);
[bnotch, anotch] = iirnotch(880 / (fs / 2), 0.707);
Output Graph:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
Program:
fsMHz = 20; % sampling frequency
fcMHz = 1.5625; % signal frequency N =
128; % fft size
% generating the frequency domain signal with subcarrier indices [-N/2:-1 dc 1:N/2-1]
x2F = [zeros(1,N/2) 0 zeros(1,9) 1 zeros(1,N/2-10-1)]; % valid frequency on 10th subcarrier, rest all
zeros
x2T = N*ifft(fftshift(x2F)); % time domain signal using ifft()
err = diff*diff’/length(diff)
plot([-512:511]*30/1024,fftshift(abs(hF))) ;
xlabel('frequency, MHz') ylabel('amplitude')
title('frequency response of sinc filter');
Output:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
Aim: To plot the waveforms for the QPSK signal subjected to AWGN using MATLAB.
Theory: Quadrature Phase Shift Keying (QPSK) is a digital modulation technique. Quadrature Phase
Shift Keying (QPSK) is a form of Phase Shift Keying in which two bits are modulated at once,
selecting one of four possible carrier phase shifts (0, Π/2, Π, and 3Π/2). QPSK is performed by
changing the phase of the In-phase (I) carrier from 0° to 180° and the Quadrature- phase (Q) carrier
between 90° and 270°. Additive white Gaussian noise (AWGN) is a channel model in which the only
impairment to communication is a linear addition of wideband or white noise with a constant spectral
density (expressed as watts per hertz of bandwidth) and a Gaussian distribution of amplitude.
Program:
% Generate random 4-PSK signal
signal = randi([0 3], 1000, 1); % 1000 symbols (0, 1, 2, 3)
Output Graph:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
6.Compress images using different standards such as JPEG, JPEG 2000 and
SPIHT and EZW codes
Aim: To compress images using different standards such as JPEG, JPEG 2000 and SPIHT and EZW
codes
Theory:
Image compression reduces file size while maintaining acceptable quality, using methods
like JPEG, JPEG 2000, SPIHT, and EZW. JPEG is a popular lossy method, balancing quality and size,
while JPEG 2000 uses wavelets for better quality and supports lossless compression. SPIHT and EZW
are wavelet-based algorithms that efficiently compress images by exploiting redundancy, especially in
hierarchical structures. Compression performance is typically evaluated using metrics like PSNR, with
the choice of method depending on quality requirements and storage or transmission needs.
Program:
clc;
close all;
img = imread('cameraman.tif');
if size(img, 3) == 3
img = rgb2gray(img);
end
figure, imshow(img), title('Original Image');
imwrite(img, 'compressed_jpeg.jpg', 'Quality', 50);
jpeg_img = imread('compressed_jpeg.jpg');
figure, imshow(jpeg_img), title('JPEG Compressed Image');
imwrite(img, 'compressed_jpeg2000.jp2', 'CompressionRatio', 20);
jpeg2000_img = imread('compressed_jpeg2000.jp2');
figure, imshow(jpeg2000_img), title('JPEG 2000 Compressed Image');
wcompress('c', img, 'cameraman_spiht.wtc', 'spiht', 'maxloop', 10); % Compress using SPIHT
decompressed_spiht = wcompress('u', 'cameraman_spiht.wtc'); % Decompress
figure, imshow(uint8(decompressed_spiht)), title('SPIHT Compressed Image');
wcompress('c', img, 'cameraman_ezw.wtc', 'ezw', 'maxloop', 10); % Compress using EZW
decompressed_ezw = wcompress('u', 'cameraman_ezw.wtc'); % Decompress
figure, imshow(uint8(decompressed_ezw)), title('EZW Compressed Image');
original = double(img);
jpeg_psnr = psnr(double(jpeg_img), original);
jpeg2000_psnr = psnr(double(jpeg2000_img), original);
spiht_psnr = psnr(double(decompressed_spiht), original);
ezw_psnr = psnr(double(decompressed_ezw), original);
fprintf('PSNR Values:\n');
fprintf('JPEG: %.2f dB\n', jpeg_psnr);
fprintf('JPEG 2000: %.2f dB\n', jpeg2000_psnr);
fprintf('SPIHT: %.2f dB\n', spiht_psnr);
fprintf('EZW: %.2f dB\n', ezw_psnr);
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
OUTPUT:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
7. Compress video signals using standards H261, H263 and MPEG4 and
H264 CODECS
Aim: To Compress video signals using standards H261, H263 and MPEG4 and H264 CODECS
Software used: MATLAB
Theory:
Video compression is essential for reducing the size of video files while maintaining quality, enabling
efficient storage and transmission. Standards like H.261, H.263, MPEG-4, and H.264 are widely used
for video signal compression. H.261 is one of the earliest video compression standards, designed for
video conferencing over ISDN networks, supporting low bitrates. H.263 improved upon H.261 with
better compression efficiency and support for higher resolutions, making it suitable for video
conferencing and streaming. MPEG-4 introduced advanced features such as object-based compression
and interactivity, offering better quality at lower bitrates for a variety of multimedia
applications. H.264, also known as AVC (Advanced Video Coding), is a widely adopted standard due
to its high compression efficiency and excellent video quality, making it ideal for streaming,
broadcasting, and storage. These codecs achieve compression through techniques like motion
estimation, prediction, and transformation, significantly reducing file sizes without compromising user
experience.
Program:
clc;
clear;
close all;
for i = 1:length(videoFiles)
vReader = VideoReader(videoFiles{i}); % Read video file
figure('Name', videoTitles{i}); % Create a figure with the video title
while hasFrame(vReader) % Loop until all frames are read
frame = readFrame(vReader); % Read the next frame
imshow(frame, []); % Display the frame
title(videoTitles{i}); % Set the title for the figure
pause(1 / vReader.FrameRate); % Pause to maintain frame rate
end
end
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
OUTPUT:
compression methods.
Aim: Evaluate different performance aspects required for Lossy and Lossless Image Compression
Software used: MATLAB.
Theory: Digital files such as image files are often "compressed" to reduce their size and/or to
change various attributes, such as file type, dimensions, resolution, bit depth. Compression reduces
the size of a file, often without appreciable loss of information. It can be either lossless or lossy.
Lossless compression restores and rebuilds file data in its original form after the file is decompressed.
The file can be decompressed to its original quality without any loss of data. This compression method
is also known as reversible compression.
In lossy compression, the data in a file is removed and not restored to its original form after
decompression. Specifically, data is permanently removed, which is why this method is also
known as irreversible compression.
Program:
clc clear all
close all
rgb = imread('peppers.png');
imshow(rgb) imwrite(rgb,'mypeppers.tif')
imwrite(rgb, 'test_image.study_013', 'tif')
bytes_in_memory_peppers = numel(rgb)
imwrite(rgb,'mypeppers.png')
info = imfinfo('mypeppers.png');
bytes_on_disk_peppers_png = info.FileSize
compression_ratio = bytes_in_memory_peppers / bytes_on_disk_peppers_png
peppers2 = imread('mypeppers.png');
isequal(rgb, peppers2)
url = 'https://blogs.mathworks.com/images/steve/2012/plot_screen_shot.png';
rgb_plot = imread(url);
OUTPUT:
bytes_in_memory_peppers = 589824
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
bytes_on_disk_peppers_png = 287589
compression_ratio = 2.0509 ans
= logical
bytes_in_memory_plot = 336000
bytes_on_disk_plot = 3284
compression_ratio = 102.3143
bytes_on_disk_peppers_jpg = 23509
compression_ratio_peppers_jpg = 25.0893
Aim: To Perform Automatic gain and frequency control for an audio signal.
Software used: MATLAB.
Theory:
Automatic Gain Control: It is a closed loop feedback regulating circuit in an amplifier or chain of
amplifiers. It is a system that controls the increase in amplitude of an electrical signal from the original
input to the amplified output automatically.
Gain: Ratio of amplitude of output signal from an amplifier circuit to amplitude of input signal. AGC
circuits are basically designed for radio receiver circuits which receive highly varying signal
strength according to climatic conditions. They are used in audio amplifier circuits, audio ICs, signal
analysers etc. They apply high gain whenever the signals are week and as the signal strength
decreases, they automatically decrease their gain.
Program:
clc;
dt = 0.001; % Time step
t = 0:dt:20; % Time vector
A = 10; % Amplitude
f = 0.25; % Frequency
xin = A * sin(2 * pi * f .* t); % Sinusoidal input signal
L = round(10 * f * (1 / dt)); % Loop filter gain
powerTarget = 0.2; % Target power for AGC
yout = zeros(1, length(xin)); % Output signal
gainAGC = ones(1, length(xin) + 1); % AGC gain (extra element for
feedback)
for n = 1:length(t)
% Amplify current input sample
yout(n) = gainAGC(n) * xin(n);
% Adjust AGC gain with feedback
gainAGC(n + 1) = gainAGC(n) * (1 - (1 / L) * (yout(n)^2 -
powerTarget));
end
figure;
subplot(2, 1, 1);
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
OUTPUT:
Theory:
In signal processing, sub-band coding (SBC) is any form of transform coding that breaks a signal into
several different frequency bands, typically by using a fast Fourier transform, and encodes each one
independently. This decomposition is often the first step in data compression for audio and video
signals.
The basic idea of SBC is to enable a data reduction by discarding information about frequencies
which are masked. The result differs from the original signal, but if the discarded information is
chosen carefully, the difference will not be noticeable, or more importantly, objectionable.
First, a digital filter bank divides the input signal spectrum into some number of subbands. The
psychoacoustic model looks at the energy in each of these subbands, as well as in the original signal,
and computes masking thresholds using psychoacoustic information. Each of the subband samples is
quantized and encoded to keep the quantization noise below the dynamically computed masking
threshold. The final step is to format all these quantized samples into groups of data called frames, to
facilitate eventual playback by a decoder.
Decoding is much easier than encoding since no psychoacoustic model is involved. The frames are
unpacked, subband samples are decoded, and a frequency-time mapping reconstructs an output audio
signal.
Program:
lnx=length(x);
L = 2;
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
len = 25;
wc = 1/L; %cut-off frequency is pi/2.
freq=-pi:2*pi/(lnx-1):pi;% the frequency vector lp =
fir1(len-1, wc,'low');
hp = fir1(len-1, wc,'high');
yl=conv(x,lp); yh=conv(x,hp);
%plotting filter response of filters and the two speech bands(lower and upper) in freq domian
figure(2);
X=fftshift(fft(x,lnx));
Lp=fftshift(fft(lp,lnx));
Hp=fftshift(fft(hp,lnx));
YL=fftshift(fft(yl,lnx));
Yh=fftshift(fft(yh,lnx));
subplot(321), plot(freq/pi, abs(X));ylabel('|X|');axis([0 pi/pi min(abs(X)) max(abs(X))]);title('Freq
domain representation of speech and the two bands');
subplot(323), plot(freq/pi, abs(Lp),'g');ylabel('|Lp|');axis([0 pi/pi min(abs(Lp)) max(abs(Lp))]);
subplot(324), plot(freq/pi, abs(Hp), 'g');ylabel('|Hp|');axis([0 pi/pi min(abs(Hp)) max(abs(Hp))]);
subplot(325), plot(freq/pi, abs(YL), 'y');ylabel('|YL|');axis([0 pi/pi min(abs(YL))
max(abs(YL))]);legend('Low bandafter filtering');
ydl =yl(1:2:length(yl));
ydh=yh(1:2:length(yh));
s0=conv(ydl,lp);
s1=conv(ydl,hp);
s2=conv(ydh,lp);
s3=conv(ydh,hp);
% now synthesizing
L=2;
N1=length(b0);
Ss0=zeros(1,L*N1);
Ss1=zeros(1,L*N1);
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date
Ss2=zeros(1,L*N1);
Ss3=zeros(1,L*N1);
Ss0(L:L:end)=b0;
Ss1(L:L:end)=b1;
Ss2(L:L:end)=b2;
Ss3(L:L:end)=b3;
%Freq plots of final two bands and their merging into a single band
figure(4);
subplot(311);
plot(freq/pi,abs(fftshift(fft(subll,lnx))));ylabel('|low band|');axis([0 pi/pi min(abs(fft(subll)))
max(abs(fft(subll)))]);title('Final two bands in synthesis');
subplot(312);
max(abs(fft(sub)))]);
pause;
%Comparison
figure(5);
subplot(211),
plot(freq/pi, abs(X));ylabel('|X|');axis([0 pi/pi min(abs(X)) max(abs(X))]);title('Comparison');
legend('original band');
subplot(212);
plot(freq/pi,abs(fftshift(fft(sub,lnx))),'r');ylabel('|Band|');axis([0 pi/pi min(abs(fft(sub)))
max(abs(fft(sub)))]);
legend('Synthesized Band');
OUTPUT:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date