Manual STFT to obtain spectrogram of an audio signal

12 次查看(过去 30 天)
Hi, Im trying to obtain the notes that are on an audio signal by using the spectrogram to know the frequencies on it, but i dont know why this code plots me an empty graph. Can sombody help me please.
[x,fs]= audioread("estrellita.mp3");
dt = 1/44100;
t=0:dt:(117204*dt)-dt;
S = zeros(501,117);
windowlength = 1e3;
k = 1;
for jj = 1:117
y = x(k:k+windowlength-1)';
ydft = fft(y).*gausswin(1e3);
S(:,jj) = ydft(1:501);
k = k+windowlength;
end
F = 0:44100/1000:44100/2;
T = 0:(1e3*dt):(117000*dt)-(1e3*dt);
surf(T,F,20*log10(abs(S)),'EdgeColor','none')
axis xy; axis tight; colormap(jet); view(0,90);
xlabel('Time');
ylabel('Frequency (Hz)');
set(gca,'YDir','Normal')
xlabel('Time (secs)')
ylabel('Freq (Hz)')
title('Short-time Fourier Transform spectrum')

回答(1 个)

UMAIR RASOOL
UMAIR RASOOL 2020-8-1
close all
clear all
clc
[y,Fs]=audioread('black_hole.mp3');
Y=fft(y,Fs);
L= (1:length(Y))*Fs/length(Y);
plot(L,abs(Y))
xlabel('Frequency');
ylabel('Amplitude');
title('(Magnitude Spectrum')
windowSize = 256;
windowOverlap = [];
freqRange = 0:Fs;
spectrogram(y(:,1), windowSize, windowOverlap, freqRange, Fs, 'xaxis');

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by