# Confusion regarding frequency spectrum in MATLAB

I am trying to observe frequency spectrum of an audio (mp3) file on MATLAB. The file'abc.mp3' is a 14 second music clip

My MATLAB code is below:

clear, clc, close all;
N = length(y);              % Length of vector y, number of samples
Y = fft(y,N);               % Fourier transform of y
F = ((0:1/N:1-1/N)*fs);     % Frequency vector
w = 2*pi*F;                 % Angular frequency vector
magnitudeY = abs(Y);        % Magnitude of the FFT
phaseY = unwrap(angle(Y));  % Phase of the FFT
plot(F, magnitudeY);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
xlabel('Frequency, Hz');
ylabel('Magnitude, dB');
title('Magnitude spectrum of sound wave in frequency');


When i run above script, i see the attached plot in output but i am confused because the maximum frequency component appears to abe around 8000 hz while the output of '''audioread''' command (fs) is around 44100 hz, why this difference?

According to my observation and understanding of MATLAB plot in question, i think maximum frequency is approximately somewhere around 8600 Hz?Is my assumption correct?

• Could you explain what you think is wrong? I don't understand. There doesn't seem to be anything wrong with audio going only up to 8000 Hz, especially if it's coming out of a decoder for a psyacoustically optimized audio compression? Jun 8, 2022 at 14:19
• There is no plot attached and we don't have access to the file bca.mp3. So we can't really see what you are seeing. Jun 8, 2022 at 15:48

The $$fs$$ you are getting from audioread is the sampling rate and has nothing to do with the actual frequency content of the signal you are analyzing other than the maximum frequency would be $$fs/2$$.

Note - because you're plotting the FFT magnitude directly (not using fftshift you'll see the content from 0 -> 22.05 kHz duplicated in the range 22.05 kHz -> 44.1 kHz.

Sampling at 44.1 kHz is used for CDs and several other formats. It is quite common. The human ear cannot really detect frequencies above 20 KHz.

There doesn't seem to be anything wrong in what you are doing, just in what your interpretation of what fs represents.

• " the maximum frequency would be fs/2" please elaborate, isn't it possible that maximum frequency is greater than fs/2?? Jun 9, 2022 at 10:01
• Please also elaborate"Note - because you're plotting the FFT magnitude directly (not using fftshift you'll see the content from 0 -> 22.05 kHz duplicated in the range 22.05 kHz -> 44.1 kHz." I have also updated my question and added more detail specially added the output plot Jun 9, 2022 at 10:08
• @engr. When sampling at a frequency of $f_s$, the Nyquist-Shannon sampling theorem states that to be able to reconstruct the sampled signal perfectly, no frequency component above $f_s/2$ can appear. Otherwise, aliasing occurs. Think about sampling a sinewave: you need to sample at least twice per period of the sinewave, otherwise you'll just get, for example, a single constant value if you sample precisely once per period.
– Peter K.
Jun 9, 2022 at 13:43
• According to my observation and understanding of MATLAB plot in question, i think maximum frequency is approximately somewhere around 8600 Hz?Is my assumption correct? Jun 14, 2022 at 15:02
• From the plot you provided, yes that looks correct. It's hard to see exactly where the frequency content drops off. Jun 14, 2022 at 18:26