END SEM LAB PROJECT
SPECTRAL ANALYSIS OF MUSIC SIGNAL
GROUP MEMBERS:
AM.EN.U4ECE23113 - PAVAN SURYA AJAY
AM.EN.U4ECE23114 - GAURAV KARTHIKEYAN
AM.EN.U4ECE23115 - G.YAKSHITH REDDY
ABSTRACT:
In this project we're gonna do spectral analysis of a music signal.
Time-frequency analysis is an efficient tool for analysing an audio
signal due to its quasi stationary nature. The spectral analysis
gives important information about an audio signal such as pitch,
onset detection, feature extraction etc. Time-frequency analysis
combines both time and frequency domain analysis to provide
better understanding of an audio signal. By analysing a signal in
both domains simultaneously, we can track how the frequency
content of signal changes over time and how time varying
properties impact its spectral characteristics. In this paper a
comprehensive study on various methods for time-frequency
analysis for musical signals is presented.
INTRODUCTION:
Spectral analysis is the process of analyzing a signal or a time
series in terms of its frequency components or related quantities
such as energies, eigenvalues, etc.
Time–frequency analysis for music signals is one of the
applications of time–frequency analysis. Musical sound can be
1
more complicated than human vocal sound, occupying a wider
band of frequency. Music signals are time-varying signals; while
the classic Fourier transform is not sufficient to analyze them,
time–frequency analysis is an efficient tool for such use. Time–
frequency analysis is extended from the classic Fourier approach.
Short-time Fourier transform (STFT), Gabor transform (GT) and
Wigner distribution function (WDF) are famous time–frequency
methods, useful for analyzing music signals such as notes played
on a piano, a flute or a guitar.In our analysis we will use short time
fourier transform.
Short-time Fourier transform
Short-time Fourier transform is a basic type of time–
frequency analysis. If there is a continuous signal x(t), we
can compute the short-time Fourier transform by
where w(t) is a window function.
Window Function:
In signal processing,a window function (also known as an
apodization function or tapering function) is a
mathematical function that is zero-valued outside of some
chosen interval. Typically, windows functions are
symmetric around the middle of the interval, approach a
maximum in the middle, and taper away from the middle.
2
Mathematically, when another function or
waveform/data-sequence is "multiplied" by a window
function, the product is also zero-valued outside the
interval: all that is left is the part where they overlap, the
"view through the window".
Equivalently, and in actual practice, the segment of data
within the window is first isolated, and then only that data
is multiplied by the window function values. Thus,
Tapering, not segmentation, is the main purpose of
window functions.
Tapering:
Tapering in the context of signal processing refers to the
gradual reduction of the amplitude or intensity of a signal
over time.
In this way we can perform spectral analysis of music
signal.
METHODOLOGY:
⦁ Use the audioread function to load an audio file
(audio_file) into MATLAB. This function returns the
3
audio samples (y) and the sampling rate (Fs).
⦁ The audio file is stereo (two channels), convert it to
mono by taking the average of the two channels (y =
mean(y, 2)). This simplifies the analysis to a single
channel.
⦁ Define parameters for computing the spectrogram:
⦁ window: Specify the type of window function (here,
hamming(512)).
⦁ noverlap: Set the overlap between consecutive
windows (256 samples).
⦁ nfft: Define the FFT length (1024 samples).
⦁ Use the spectrogram function to compute the
spectrogram (S) along with frequency (F) and time (T)
vectors.
⦁ Convert the spectrogram magnitude (S) to decibels
(dB) using S_dB = 10 * log10(abs(S)). This enhances
visualization of the spectrogram's dynamic range.
⦁ Plot the spectrogram using imagesc(T, F, S_dB). This
function displays the spectrogram as an image with
time (T) on the x-axis, frequency (F) on the y-axis, and
color representing intensity (dB).
Results:
% Load audio file
audio_file = "C:\Users\user\Downloads\new-edm-music-beet-mr-sandeep-rock-141616.wav";
4
[y, Fs] = audioread(audio_file);
% Time vector
t = (0:length(y)-1) / Fs; % Time in seconds
% Plot the audio waveform
figure;
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Audio Waveform');
if size(y, 2) > 1
% Take the average of the two channels (you can modify this based on your needs)
y = mean(y, 2); % Convert stereo to mono by averaging channels
end
% Step 3: Compute spectrogram
window = hamming(512); % Window length
noverlap = 256; % Overlap between consecutive windows
nfft = 1024; % FFT length
[S, F, T] = spectrogram(y, window, noverlap, nfft, Fs);
% Step 4: Visualize spectrogram
S_dB = 10 * log10(abs(S));
figure;
imagesc(T, F, S_dB);
axis xy;
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Spectrogram of Audio Signal');
5
colorbar;
6
7
8
9
10
CONCLUSION:
In this project, we conducted a comprehensive analysis of a music
signal using spectrogram and frequency spectrum techniques. The
main objectives were to explore the frequency content of the
music, identify contributing instruments, and visualize their
spectral contributions over time.
Through the spectrogram analysis, we observed distinct patterns
11
in the frequency domain, corresponding to different segments of
the music. The spectrogram provided valuable insights into the
temporal evolution of the signal's frequency components,
highlighting dynamic changes and instrumental variations
throughout the duration of the track.
INFERENCE:
We observed frequency spectrum of drum and guitar, then
compared with a music signal. We observed that drum lies in
frequency range and guitar lies in high frequency range.
12