0% found this document useful (0 votes)
57 views27 pages

Noise Removal & Signal Processing Lab

Uploaded by

MEGHANA BONTHU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views27 pages

Noise Removal & Signal Processing Lab

Uploaded by

MEGHANA BONTHU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

VNRVJIET Sheet No……………..

Name of the Experiment


Name of the Laboratory:
SPCA Lab Experiment No. Date

INDEX

1. Removal of various types of Noise from signals acquired by sensors.


2. Removal of noise from Image data for further Image processing.
3. Design of FIR adaptive filter as an Equalization filter
4. Develop OFDM standard complaint waveforms using FFT and other blocks
5. Digital modulation and demodulation in AWGN and other channel setting.
6. Compress images using different standards such as JPEG, JPEG 2000 and SPIHT and EZW codes
7. Compress video signals using standards H261, H263 and MPEG4 and H264 CODECS
8. Evaluate different performance aspects required for lossy and lossless Compression methods.
9. Perform Automatic gain and frequency control for an Audio signal.
10. Audio compression algorithms (Using Sub band coding and Linear predictive code)
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

1. Removal of various types of Noise from signals acquired by sensors.

Aim: To verify removal of noise by Moving Mean / Average.

Software used: MATLAB, Python.

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)

# Moving Average Filter


WindowSize = 3
FilteredSignal = np.convolve(Signal, np.ones(WindowSize), 'valid') / WindowSize

# 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

% "handel" is a sample audio file present in Matlab


load handel
y = y(1:256);

%sound(y)%function to hear the audio file


subplot(2,2,1)
plot(y)
title('Audio File With Noise');
ysmm = movmean(y, 3, 'endpoints', 'discard' );
subplot(2,2,1)
plot(ysmm)
title('Audio File After Filtering');

Output Graphs:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

2.Removal of noise from Image data for further Image processing.

Aim: To remove the noise (salt pepper noise) from Image data using averaging filter and median
filters.

Software used: MATLAB.

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)

# Salt and Pepper Noise


ImageSP = skimage.util.random_noise(Image, 's&p')
ImageSPF = filters.median(ImageSP)

plt.figure('Salt and Pepper Noise')


plt.subplot(1,2,1) io.imshow(ImageSP)
plt.title('Noisy Image')
plt.subplot(1,2,2)
io.imshow(ImageSPF) plt.title('Filtered
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:

% Read the original image


a = imread('eight.tiff');
figure(1), imshow(a);
title('Original Image');

% Add salt & pepper noise


j = imnoise(a, 'salt & pepper', 0.02);
figure(2), imshow(j);
title('Noisy Image');

% Define an averaging filter


h = fspecial('average', [3 3]);

% Apply the filter to remove noise


if size(j, 3) == 3 % Check if the image is RGB
k = cat(3, imfilter(j(:, :, 1), h), imfilter(j(:, :, 2), h), imfilter(j(:, :, 3), h));
else
k = imfilter(j, h); % For grayscale image
end

% Display the filtered image


figure(3), imshow(k);
title('Filtered Image');
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

3.Design of FIR adaptive filter as an Equalization filter


Aim: To design an FIR adaptive filter as an equalization filter
Software Used: Python
Matlab Program:
fs = 44100; % Sample rate
worN = logspace(log10(20), log10(20^3.3), 1000); % Frequencies to plot

% 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);

% Combined frequency response


H_combined = abs(freqz(blpf, alp, worN, fs)) .* ...
abs(freqz(bls, als, worN, fs)) .* ...
abs(freqz(bnotch, anotch, worN, fs));
% Plot the combined response
figure; semilogx(worN, 20 * log10(H_combined), 'k');
title('Adaptive Equalization Filter'); xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)'); grid on;

% Helper function for low-shelf filter


function [b, a] = shelf(f0, Q, G, fs)
A = sqrt(G); w0 = 2 * pi * f0 / fs; alpha = sin(w0) / (2 * Q);
b = [(A * (1 - cos(w0))) / 2, A * (1 - cos(w0)), (A * (1 - cos(w0))) / 2];
a = [1 + alpha, -2 * cos(w0), 1 - alpha];
end

Output Graph:
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

4. Develop OFDM standard complaint waveforms using FFT and other


blocks
Aim: Develop OFDM standard complaint waveforms using FFT and other blocks.
Software used: MATLAB
Theory:
In telecommunications, orthogonal frequency-division multiplexing (OFDM) is a type of digital
transmission and a method of encoding digital data on multiple carrier frequencies. OFDM has
developed into a popular scheme for wideband digital communication, used in applications such as
digital television and audio broadcasting, In OFDM, multiple closely
spaced orthogonal subcarrier signals with overlapping spectra are transmitted to carry data in
parallel. Demodulation is based on fast Fourier transform algorithms. Each subcarrier (signal) is
modulated with a conventional modulation scheme (such as quadrature amplitude
modulation or phase-shift keying) at a low symbol rate. This maintains total data rates like
conventional single-carrier modulation schemes in the same bandwidth.

Program:
fsMHz = 20; % sampling frequency
fcMHz = 1.5625; % signal frequency N =
128; % fft size

% generating the time domain signal


x1T = exp(j*2*pi*fcMHz*[0:N-1]/fsMHz); x1F
= fft(x1T,N); % 128 pt FFT
figure;
plot([-N/2:N/2-1]*fsMHz/N,fftshift(abs(x1F))) ; % sub-carriers from [-128:127]
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of complex sinusoidal signal');

% 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()

% comparing the signals


diff = x2T – x1T;

err = diff*diff’/length(diff)

% impulse response of a sinc() filter


hT = sinc([-20:20]/3); % consider sample at 30MHz sampling; hF =
fft(hT,1024); % 128 pt FFT
figure;
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

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

5.Digital modulation and demodulation in AWGN and other channel


setting.

Aim: To plot the waveforms for the QPSK signal subjected to AWGN using MATLAB.

Software used: 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)

% Initialize BER array


BER = zeros(1, 20);

% Loop over different SNR values


for SNR = 1:20
% Modulate, add noise, demodulate, and calculate errors
TxSignal = pskmod(signal, 4, pi/4);
RxSignal = awgn(TxSignal, SNR, 'measured');
RxSymbols = pskdemod(RxSignal, 4, pi/4);
BER(SNR) = sum(signal ~= RxSymbols) / length(signal);
end

% Plot BER vs. SNR


semilogy(1:20, BER, 'o-');
xlabel('SNR (dB)');
ylabel('BER');
title('BER vs. SNR for 4-PSK Modulation');
grid on;
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

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

Software used: MATLAB

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;

% Parameters for video creation


numFrames = 50; % Number of frames
frameHeight = 240; % Height of video frames
frameWidth = 320; % Width of video frames
frameRate = 10; % Frames per second

% Generate random video frames


randomVideo = randi([0, 255], frameHeight, frameWidth, numFrames, 'uint8'); % Random frames

% File names for the videos


originalFileName = 'random_video.avi';
compressedFileName = 'random_video_mjpeg.avi';

% Create and save the original uncompressed video


disp('Creating random video...');
vWriter = VideoWriter(originalFileName, 'Uncompressed AVI'); % Uncompressed AVI format
vWriter.FrameRate = frameRate; % Set frame rate
open(vWriter);
for i = 1:numFrames
writeVideo(vWriter, randomVideo(:, :, i)); % Write each frame
end
close(vWriter);
disp('Original video created successfully.');

% Compress the video using Motion JPEG AVI


VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

disp('Compressing video using Motion JPEG AVI...');


vWriterCompressed = VideoWriter(compressedFileName, 'Motion JPEG AVI'); % MJPEG
compression
vWriterCompressed.FrameRate = frameRate; % Same frame rate
open(vWriterCompressed);
for i = 1:numFrames
writeVideo(vWriterCompressed, randomVideo(:, :, i)); % Write each frame
end
close(vWriterCompressed);
disp('Video compression completed.');

% Display video information


disp('Video Information:');
infoOriginal = VideoReader(originalFileName); % Read the original video
disp(['Original Video: ', num2str(infoOriginal.Width), 'x', num2str(infoOriginal.Height), ...
', FPS: ', num2str(infoOriginal.FrameRate)]);

infoCompressed = VideoReader(compressedFileName); % Read the compressed video


disp(['Compressed Video: ', num2str(infoCompressed.Width), 'x', num2str(infoCompressed.Height), ...
', FPS: ', num2str(infoCompressed.FrameRate)]);

% Play both videos


disp('Playing videos...');
videoFiles = {originalFileName, compressedFileName};
videoTitles = {'Original Video', 'Compressed Video'};

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:

8.Evaluate different performance aspects required for lossy and lossless


VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

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);

bytes_in_memory_plot = numel(rgb_plot) info


= imfinfo(url);
bytes_on_disk_plot = info.FileSize
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

compression_ratio = bytes_in_memory_plot / bytes_on_disk_plot


imwrite(rgb,'peppers.jpg');
info = imfinfo('peppers.jpg');
bytes_on_disk_peppers_jpg = info.FileSize
compression_ratio_peppers_jpg = bytes_in_memory_peppers / ...
bytes_on_disk_peppers_jpg
imshow('peppers.jpg')
subplot(1,2,1)
imshow('peppers.png')
%limits = [232 276 215 248];
%axis(limits)
title('Original')
subplot(1,2,2)
imshow('peppers.jpg')
%axis(limits) title('JPEG
compressed')
imwrite(rgb_plot,'plot_screen_shot.jpg')
rgb_plot_compressed = imread('plot_screen_shot.jpg');
subplot(2,2,1)
imshow(rgb_plot)
title('Original image') limits =
[80 105 210 230];
axis(limits);
subplot(2,2,2)
imshow(rgb_plot_compressed)
title('JPEG compressed image')
axis(limits);

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

Original image jpeg compressed image

9.Perform Automatic gain and frequency control for an Audio signal.


VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

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

plot(t, xin, '-b', 'DisplayName', 'Input Signal (xin)'); hold on;


plot(t, yout, '-r', 'DisplayName', 'Output Signal (yout)');
grid on; zoom on;
xlabel('Time (s)');
ylabel('Amplitude');
legend;
title('AGC Input and Output');
subplot(2, 1, 2);
plot(t, gainAGC(1:end-1), '-k', 'DisplayName', 'Gain of AGC');
grid on; zoom on;
xlabel('Time (s)');
ylabel('Gain');
legend;
title('Gain of AGC');

OUTPUT:

10.Audio compression algorithms (Using Sub band coding and Linear


predictive code)
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

Aim: To Perform Audio compression using sub band coding


Software used: MATLAB

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:

close all; clear all;


num=36000;
[x,fs] = audioread('C:\Users\vnrvjiet\Downloads\eee.wav');
x=x(:,1)';

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);

%Time domain plots of signal and filters


figure(1);
subplot(311);
plot(x);axis([0 lnx min(x) max(x)]);ylabel('speech');
title('Speech and filters in time domain'); subplot(312);
stem(lp);axis([0 length(lp) (min(lp)+0.1) (max(lp)+0.1)]);
ylabel('lp');
subplot(313);
stem(hp);axis([0 length(hp) min(hp)+0.1 max(hp)+0.1]);
ylabel('hp');
pause

%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');

subplot(326), plot(freq/pi, abs(Yh), 'y');ylabel('|Yh|');axis([0 pi/pi min(abs(Yh))


max(abs(Yh))]);legend('High band after filtering');
pause
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

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 finally decimating to get the four bands b0


=s0(1:2:length(s0));
b1=s1(1:2:length(s1));
b2 =s2(1:2:length(s2));
b3=s3(1:2:length(s3));

%freq plots of decimated signals(four bands)


figure(3);
title('Four bands in freq domain');
subplot(411);
plot(freq/pi,abs(fftshift(fft(b0,lnx))));ylabel('|B0|');axis([0 pi/pi min(abs(fft(b0)))
max(abs(fft(b0)))]);title('Four bands in freq domain');
subplot(412);
plot(freq/pi,abs(fftshift(fft(b1,lnx))));ylabel('|B1|');axis([0 pi/pi min(abs(fft(b0)))
max(abs(fft(b1)))]);
subplot(413);
plot(freq/pi,abs(fftshift(fft(b2,lnx))));ylabel('|B2|');axis([0 pi/pi min(abs(fft(b2)))
max(abs(fft(b2)))]);
subplot(414);
plot(freq/pi,abs(fftshift(fft(b3,lnx))));ylabel('|B3|');axis([0 pi/pi min(abs(fft(b3)))
max(abs(fft(b3)))]);
pause;

% 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;

%Passing through reconstruction filters


% making a low pass filter with cutoff at 1/L and gain L
reconst_fil=L*fir1(len-1,1/L);

% finding the freq response of the filter


sb0=conv(reconst_fil,Ss0);
sb1=conv(reconst_fil,Ss1);
sb2=conv(reconst_fil,Ss2);
sb3=conv(reconst_fil,Ss3);
Slow=sb0-sb1;
Shigh=sb2-sb3;
subl=zeros(1,length(Slow)*2);
subh=zeros(1,length(Shigh)*2);
subl(L:L:end)=Slow;
subh(L:L:end)=Shigh;
subll=conv(reconst_fil,subl);
subhh=conv(reconst_fil,subh);
sub=subll-subhh;

%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);

ot(freq/pi,abs(fftshift(fft(subhh,lnx))));ylabel('|High band|');axis([0 pi/pi min(abs(fft(subhh)))


max(abs(fft(subhh)))]);
subplot(313);
plot(freq/pi,abs(fftshift(fft(sub,lnx))));ylabel('|Band|');axis([0 pi/pi min(abs(fft(sub)))
VNRVJIET Sheet No……………..
Name of the Experiment
Name of the Laboratory:
SPCA Lab Experiment No. Date

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

You might also like