Skip to content

Instantly share code, notes, and snippets.

@yichao0319
Last active April 1, 2022 16:37
Show Gist options
  • Save yichao0319/3d5ffd3d5c88a8a55910cf1d0da6f39f to your computer and use it in GitHub Desktop.
Save yichao0319/3d5ffd3d5c88a8a55910cf1d0da6f39f to your computer and use it in GitHub Desktop.
matlab:spectrogram
%% Spectrogram takes the STFT of the signal
win = floor(Fs/32);
noverlap = floor(win/4); % 75% overlap
Nfft = Fs;
% P matrix contains the power spectral density of each segment of the STFT
[S,F,T,P] = spectrogram(data, win, noverlap, Nfft, Fs);
fh = figure(1); clf;
imagesc(T, F, real(S));
colorbar;
ax = gca; ax.YAxis.Exponent = 0;
set(gca,'YDir','normal')
ylim([17500 18500]);
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Time-Frequency plot of a Audio signal');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment