diff --git a/spectrogram.m b/spectrogram.m new file mode 100644 index 0000000..2e578ac --- /dev/null +++ b/spectrogram.m @@ -0,0 +1,38 @@ +function spectrogram(signal, samplingFreq, step_size, window_size) +%%%%%%%%%%%%%%%%%%%%%%% +%function spectrogram(signal, samplingFreq, step_size, window_size) +% ex.: spectrogram(signal, samplingFreq, step_size, window_size) +% +% 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 +fftn = 2^nextpow2(window); % next highest power of 2 +[S, f, t] = specgram(signal, fftn, samplingFreq, window, window-step); +S = abs(S(2:fftn*4000/samplingFreq,:)); % magnitude in range 0