How to make the spectrum of two spikes?

4 ビュー (過去 30 日間)
Maria Amr
Maria Amr 2021 年 2 月 10 日
回答済み: Suraj Kumar 2025 年 7 月 7 日
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.

回答 (1 件)

Suraj Kumar
Suraj Kumar 2025 年 7 月 7 日
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!

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by