Hi Maria,
To perform spectral analysis on spike trains in MATLAB, you can start by creating a time series that represents your spike trains and then compute their spectra using the Fast Fourier Transform (FFT).
1. You can define spike times and creating a time vector for analysis.Then you can create the spike trains as impulses at the specified times and combine them.
R1 = 0.2;
R2 = 0.7;
Fs = 1000;
t = 0:1/Fs:1;
spikeTrain1 = zeros(size(t));
spikeTrain2 = zeros(size(t));
[~, idx1] = min(abs(t - R1));
[~, idx2] = min(abs(t - R2));
spikeTrain1(idx1) = 1;
spikeTrain2(idx2) = 1;
combinedSpikeTrain = spikeTrain1 + spikeTrain2;
2. Then you can use the Fast Fourier Transform (FFT) to compute the frequency spectrum and create a frequency vector.
% Compute the FFT of the combined spike train
n = length(combinedSpikeTrain);
Y = fft(combinedSpikeTrain);
P2 = abs(Y/n);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(n/2))/n;
You can refer to the following documentation to learn more about the 'fft' function in MATLAB:
Happy Coding!