Hi Monserrat,
I understand that you want to create a spectrograms for a set of signals and then average them in MATLAB.
You could follow these steps:
- You'll need to initialize variables to store the cumulative spectrogram data for each channel.
- Loop through each trial and channel, calculate the spectrogram for each signal, and add it to the cumulative spectrogram for the corresponding channel.
- After accumulating the spectrogram data, average it by the number of trials for each channel.
Here's a sample code to demonstrate this:
[numTrials, numChannels] = size(data);
cumulativeSpectrograms = cell(1, numChannels);
cumulativeSpectrograms{chan} = [];
signal = data{trial, chan};
[S, F, T, P] = spectrogram(signal, windowSize, noverlap, nfft, 'yaxis');
cumulativeSpectrograms{chan} = zeros(size(P));
cumulativeSpectrograms{chan} = cumulativeSpectrograms{chan} + P;
cumulativeSpectrograms{chan} = cumulativeSpectrograms{chan} / numTrials;
Adjust the 'windowSize', 'noverlap', and 'nfft' parameters based on the sampling rate of your signals and the frequency resolution you desire.
If your signals have different lengths, you may need to pad them to the same length before averaging the spectrograms.