Frequency spectrum of a sound signal
23 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi guys, I would like to know some hints on how to plot frequency spectrum of magnitude and phase spectra of an audio signal in both omega and frequency as x-axis parameter (plot separately). Thanks. My code is as below and i'm not sure what's going on.
[y,fs] = audioread('test.wave');
N = length(y);
t = (0:N-1/fs);
n = (0:N-1);
y = y(:,1);
% spectral analysis
w = hanning(N, 'periodic');
[X, f] = periodogram(y, w, N, fs, 'power');
X = 20*log10(sqrt(X)*sqrt(2));
% plot the signal spectrum
figure(1);
subplot(2,1,1);
semilogx(f, X, 'r');
xlim([0 max(f)]);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
title('Amplitude spectrum of the signal');
xlabel('Frequency, Cycles/Second');
ylabel('Magnitude, dB');
subplot(2,1,2);
semilogx((2*pi*f), X, 'r');
xlim([0 max(2*pi*f)]);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
title('Amplitude spectrum of the signal');
xlabel('Angular Frequency, Radian/Sample');
ylabel('Magnitude, dB');
0 Commenti
Risposte (1)
Kaashyap Pappu
il 23 Ott 2019
Using a test sound file of my own, I was able to generate the plots attached. The function “audioread” works if the suffix of the sound file name is ‘.wav’ not ‘.wave’.
Hope this helps!
2 Commenti
Keira Duffy
il 20 Set 2021
When you do magnitudeY = abs(Y); you automatically assumed that it is in decibels but it is not. Dont you need to take the log10 to convert it?
Vedere anche
Categorie
Scopri di più su Vibration Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!