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 CenterFile Exchange에서 Discrete 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