MULTIMEDIA
TECHNOLOGIES
LAB MATERIAL I
speech coder and decoder for
multimedia data transmission
2
AGENDA
Objective
Introduction
What You’ll Need
Step-by-Step Guide
Optional Enhancements
Key Tips
OBJECTIVE
Create A Basic Speech Coder And Decoder To Compress And
Reconstruct Speech For Multimedia Data Transmission.
INTRODUCTION
• Speech coding involves compressing audio signals for efficient
transmission, while decoding reconstructs the signal at the receiver.
In this guide, you’ll:
1. Record or load a speech signal.
2. Compress it using basic methods (e.g., quantization, downsampling).
3. Reconstruct the speech signal.
4. Evaluate the quality of the reconstructed signal.
5
WHAT YOU’LL NEED
• MATLAB installed on your computer.
• A microphone (optional, for recording audio).
• A basic understanding of signals (frequency, time,
sampling, etc.).
STEP-BY-STEP GUIDE 6
Step 1: Setup MATLAB
1. Open MATLAB.
2. Create a new script by clicking New
Script in the toolbar.
STEP-BY-STEP GUIDE 7
If you also want to run each code in every step separately you can do that
in matlab using sections.
For example if there is a portion of the code you want to run instead of the
entire code, separate that code section using %% syntax. Or by clicking on
section break button. st
1 code section
2nd code section
3rd code section
You can run each code section
separately by clicking on the
section you want to run and
click on the button ‘run section’
You can also break sections using this button instead of
8
STEP-BY-STEP GUIDE
Step 2: Record or Load Speech
• You can either record speech using a microphone or
load an existing audio file.
Option 1: Record Speech (using the code below)
Matlab code
% Step 2.1: Record a speech signal
Fs = 16000; % Sampling frequency (16 kHz)
recObj = audiorecorder(Fs, 16, 1); % 16-bit, mono
channel
disp('Start speaking...');
recordblocking(recObj, 5); % Record for 5 seconds
disp('Recording finished.');
speechSignal = getaudiodata(recObj);
% Step 2.2: Save the recorded audio (optional)
audiowrite('speech_input.wav', speechSignal, Fs);
9
STEP-BY-STEP GUIDE
Step 2: Record or Load Speech
• You can either record speech using a microphone or
load an existing audio file.
Option 2: Load Existing Speech (using the code below)
Matlab code
[speechSignal, Fs] = audioread('speech_input.wav'); % Load the file
Note: in place of speech_input.wav insert the media name of
the given file in the folder or your own choice of .wav file.
10
STEP-BY-STEP GUIDE
Step 3: Compress the Speech Signal
• Compression reduces the size of the signal.
Option: Downsampling
Matlab code
downSampleFactor = 2; % Downsample by a factor of 2
compressedSignal = downsample(speechSignal, downSampleFactor);
compressedFs = Fs / downSampleFactor;
11
STEP-BY-STEP GUIDE
Step 4: Decode (Reconstruct) the Speech Signal
• Reconstruction involves restoring the signal to its
original sample rate.
Matlab code
% Step 4.1: Upsample the compressed signal
reconstructedSignal = upsample(compressedSignal, downSam-
pleFactor);
% Step 4.2: Apply a low-pass filter to smoothen the signal
lpFilter = designfilt('lowpassfir', 'PassbandFrequency', 0.4,
...'StopbandFrequency', 0.5, 'DesignMethod', 'kaiserwin');
reconstructedSignal = filter(lpFilter, reconstructedSignal);
12
STEP-BY-STEP GUIDE
Step 5: Evaluate the Results
• Compare the original and reconstructed signals.
Option 1: Listen to the Signals
Matlab code
disp('Playing original signal...');
sound(speechSignal, Fs);
pause(length(speechSignal)/Fs + 1);
disp('Playing reconstructed signal...');
sound(reconstructedSignal, Fs);
STEP-BY-STEP GUIDE 13
Step 5: Evaluate the Results
• Compare the original and reconstructed signals.
Option 2: Plot the Signals
Matlab code
tOriginal = (0:length(speechSignal)-1) / Fs; % Time for orig-
inal signal
tReconstructed = (0:length(reconstructedSignal)-1) / Fs;
figure;
subplot(2, 1, 1);
plot(tOriginal, speechSignal);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2, 1, 2);
plot(tReconstructed, reconstructedSignal);
title('Reconstructed Signal');
xlabel('Time (s)');
ylabel('Amplitude');
14
STEP-BY-STEP GUIDE
Step 6: Save the Reconstructed Signal
Matlab code
audiowrite('reconstructed_speech.wav', reconstructedSignal,Fs);
15
OPTIONAL ENHANCEMENTS
1. Quantization: Further compress the signal by reducing the number of
bits per sample.
2. PESQ or SNR: Measure the quality of the reconstructed signal.
Quantization Example
Matlab code
nBits = 8; % Reduce to 8 bits
quantizedSignal = round(speechSignal * (2^(nBits - 1))) / (2^(nBits - 1));
16
KEY TIPS
1. Test with different sampling rates and downsampling factors.
2. Use MATLAB’s built-in functions (e.g., audiowrite, audioread) to
simplify tasks.
3. Save your script regularly to avoid losing progress.
THANK YOU