How to make the spectrum of two spikes?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone, I would appreciate if somebody direct me regarding the spectral analysis for spike trains as I am new in this field.
I have two spike trains , R1=0.2 and R2=o.7
I would like to plot the spectrum of the two and my instructor says the spectrum of a pair of spikes is a sinusoid. Any suggestions about how to write the code will be more than appreciated. Thank you.
0 commentaires
Réponses (1)
Suraj Kumar
le 7 Juil 2025
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!
0 commentaires
Voir également
Catégories
En savoir plus sur Discrete Fourier and Cosine Transforms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!