combine spectrogram result in one figure

3 visualizaciones (últimos 30 días)
nirwana
nirwana el 1 de Jun. de 2024
Respondida: Suraj Kumar el 6 de Ag. de 2024
I have 20 min signal and would like to combine its sepectogram become one spectrogram consecutively. my idea is put index of each S, P, T value and then joining together in one array then using imagesc. But I don't know if this flow is effective, since I have to combine for each 20 minutes into a month.
I write part of coding but I don't know how to looping index for spectogram result.
Please help me.
%% SPECTROGRAM
clc, close all, clear all
set(0,'DefaultFigureWindowStyle','docked')
datafold = uigetdir(pwd,'Select data Folder');
myfiles=dir([datafold '/*.DAT']);
N = length(myfiles) ; % total number of files
data = cell(N,1)
for i = 1:N
thisfile = myfiles(i).name ;
y = importdata(thisfile);
t=(0:length(y)-1)';
Nspec=512;
wspec=hamming(Nspec);
Noverlap=Nspec/2;
fs=100;
[Si,Fi,Ti,P]=spectrogram(y,wspec,Noverlap,Nspec,fs,'xaxis');
% nexttile
% imagesc(T/60,F,10*log10(P));
% axis xy;
% axesHandle.YLim = [0.1 10000];
% colormap default;
% cbar = colorbar;
% cbar.Label.String = {'Intensity in dB'};
% xlabel('Time (s)');
% ylabel('Freqwency(Hz)');
% title('Spectrogram with RemInsRes');
end

Respuestas (1)

Suraj Kumar
Suraj Kumar el 6 de Ag. de 2024
Hi Nirwana,
Based on my understanding, you want to combine the spectrogram results of multiple signal files into a single, continuous spectrogram plot by comprehensively looping through the spectrogram for individual files.
You can refer to the following steps along with the attached code snippets :
1. Initialize two empty arrays “combined_S” and “combined_T”, to store the concatenated spectrogram data and time indices from all files.
% Initialize empty arrays for concatenated results
combined_S = [];
combined_T = [];
2. Loop through the files and calculate the spectrogram of the current file. Then concatenate the power spectral density to “combined_S and time indices to “combined_T”.
% Calculate the spectrogram
[Si, Fi, Ti, Pi] = spectrogram(y, wspec, Noverlap, Nspec, fs, 'xaxis');
% Concatenate the results
combined_S = [combined_S, Pi];
if isempty(combined_T)
combined_T = Ti;
else
combined_T = [combined_T, Ti + combined_T(end)];
end
3. Then plot the combined spectrogram using “imagesc” function and further update the plot in each iteration of the loop to visualise the spectrogram built up gradually.
% Update the plot
imagesc(combined_T / 60, Fi, 10 * log10(combined_S));
axis xy;
drawnow;
See the output below for better understanding :
For more details on the “spectrogram” and “imagesc” function, kindly refer to the following documentations:
Happy Coding!

Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by