From 8b53aa27344f8e497e88de8db478345f56199a38 Mon Sep 17 00:00:00 2001 From: "paul.ewing" Date: Mon, 18 Mar 2024 09:38:17 +0100 Subject: [PATCH] added spectrogram --- spectrogram.m | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spectrogram.m diff --git a/spectrogram.m b/spectrogram.m new file mode 100644 index 0000000..5829c03 --- /dev/null +++ b/spectrogram.m @@ -0,0 +1,36 @@ +function spectrogram(signal, samplingFreq, step_size, window_size) +%%%%%%%%%%%%%%%%%%%%%%% +%function spectrogram(signal, samplingFreq, step_size, window_size) +% ex.: spectrogram(signal, 300, 50, 1000) +% +% Task: Plot the spectrogram of a given signal +% +% Inputs: +% -signal: temporal signal to analyse +% -samplingFreq: sampling frequency of the temporal signal +% -step_size: how often the power spectrum will be computed in ms +% -window_size: size of the analysing window in ms +% +% Ouput: None +% +% author: Guillaume Gibert (guillaume.gibert@ecam.fr) +% date: 14/03/2023 +%%%%%%%%%%%%%%%%%%%%%%% + +figure; + subplot(2,1,1); +t=0:1/samplingFreq:length(signal)/samplingFreq-1/samplingFreq; +plot(t, signal'); +xlim([0 length(signal)/samplingFreq-1/samplingFreq]); +ylabel('Amplitude (norm. unit)'); + + subplot(2,1,2); +step = fix(step_size*samplingFreq/1000); % one spectral slice every step_size ms +window = fix(window_size*samplingFreq/1000); % window_size ms data window + + +[S, f, t] = specgram(signal); +specgram(signal, 2^nextpow2(window), samplingFreq, window, window-step); +xlabel('Time (s)'); +ylabel('Frequency (Hz)'); +title('hello'); \ No newline at end of file