0
$\begingroup$

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;
[y,fs] = audioread('abc.mp3');
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? enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ 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? $\endgroup$ Jun 8, 2022 at 14:19
  • $\begingroup$ 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. $\endgroup$
    – Hilmar
    Jun 8, 2022 at 15:48

1 Answer 1

5
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ " the maximum frequency would be fs/2" please elaborate, isn't it possible that maximum frequency is greater than fs/2?? $\endgroup$
    – DSP_CS
    Jun 9, 2022 at 10:01
  • $\begingroup$ 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 $\endgroup$
    – DSP_CS
    Jun 9, 2022 at 10:08
  • 2
    $\begingroup$ @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. $\endgroup$
    – Peter K.
    Jun 9, 2022 at 13:43
  • $\begingroup$ 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? $\endgroup$
    – DSP_CS
    Jun 14, 2022 at 15:02
  • $\begingroup$ From the plot you provided, yes that looks correct. It's hard to see exactly where the frequency content drops off. $\endgroup$
    – David
    Jun 14, 2022 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.