ASP Lab Report (1)
ASP Lab Report (1)
SOFTWARE USED
This experiment uses MATLAB, a powerful tool for numerical computation and
visualization. Key MATLAB functions include audioread for loading audio files,
uigetfile for file selection, fft for spectral analysis, and subplot, plot, and drawnow
for visualization. These tools enable real-time simulation of audio processing
tasks in a controlled environment.
1
CODE
function real_time_audio_processing()
% Select audio file
[file, path] = uigetfile({'*.wav;*.mp3', 'Audio Files (*.wav, *.mp3)'});
if isequal(file, 0)
disp('No file selected.');
return;
end
% Parameters
frameDuration = 0.1; % seconds
frameSize = round(Fs * frameDuration);
totalSamples = length(data);
numFrames = floor(totalSamples / frameSize);
% Create figure
figure('Name','Uploaded Audio Processing');
2
t = (0:frameSize-1) / Fs;
% FFT
NFFT = 2^nextpow2(length(frame));
Y = fft(frame, NFFT);
f = Fs/2 * linspace(0, 1, NFFT/2 + 1);
mag = abs(Y(1:NFFT/2 + 1));
drawnow;
pause(frameDuration); % mimic real-time feel
end
3
EXPLAINATION OF CODE
The MATLAB code utilizes several key functions and constructs essential for
real-time audio processing simulation. The function keyword defines a reusable
function called real_time_audio_processing. The uigetfile function is used to
open a file browser window allowing the user to select an audio file with .wav or
.mp3 extensions. Once selected, the file is read using audioread, which loads both
the audio data and its sampling frequency, Fs. If the audio file has two channels
(stereo), it is converted to mono using mean(data, 2). Frame parameters are set
using frameDuration, and the frame size is calculated by multiplying with Fs. The
number of frames is computed using floor(totalSamples/frameSize) to ensure
integer segmentation.
Within a for loop, each frame is extracted and its time vector calculated. The Fast
Fourier Transform (FFT) is performed using fft, and the result is processed to
obtain frequency and magnitude data. nextpow2 optimizes the FFT length, and
linspace generates a frequency vector. The subplot function creates side-by-side
plots of the time-domain waveform and frequency-domain spectrum for each
frame. Functions like xlabel, ylabel, title, xlim, and ylim are used for plot
customization. drawnow ensures the plots are updated in real time, while
pause(frameDuration) provides a delay to simulate real-time playback. Together,
these components demonstrate an interactive and intuitive real-time audio
processing tool.
4
FLOWCHART
5
OUTPUT
The simulation displays two subplots: the upper subplot shows the signal
amplitude over time, and the lower subplot displays the frequency spectrum of
each frame. Users can observe how the signal's amplitude and frequency content
evolve over time. This dynamic visualization helps in detecting changes such as
pitch variations, noise, or silence in the audio stream. It is a simple yet effective
demonstration of real-time signal behavior.
6
ADVANTAGES
One of the main advantages of using MATLAB for real-time audio processing is
its rich library of built-in functions and toolboxes that simplify complex
operations like signal visualization, Fourier analysis, and file I/O. The high-level
syntax allows rapid prototyping of signal processing algorithms without worrying
about low-level memory management or threading. The simulation can be easily
adapted for various types of audio inputs, making it a flexible tool for educational,
research, and prototyping purposes. The dynamic plotting of time and frequency
domains provides immediate visual feedback, which enhances understanding and
aids in debugging.
Another key benefit is MATLAB’s interactive environment. Real-time plotting
with drawnow and pause functions creates an illusion of live processing, which
is excellent for demonstrations. Additionally, the system is extensible: users can
integrate filtering, speech detection, or even machine learning models to build
more advanced applications. MATLAB’s compatibility with audio formats like
.wav and .mp3 ensures broad usability.
LIMITATION
7
CONCLUSION