Code Martin Pyka on 18 May 2010 11:34 pm
Display the frequency domain of a signal
SPM has a nice feature to plot the frequency domain of a signal. You can use it, for example, when you click on “Review” and - after you selected an SPM.mat file - on “Design” - “Explore” - “Session 1″ - Regressor. The corresponding function can be found in spm_fMRI_design_show.m in line 90ff.
To call this plot directly from the Matlab console e.g. in order to visualize the frequency domain of extracted VOIs, I copied the code into a separate m-file function, which looks like this:
function fft_gui(signal, rt, HPF)
gX = abs(fft(signal)).^2;
gX = gX*diag(1./sum(gX));
q = size(gX,1);
Hz = [0:(q - 1)]/(q*rt);
q = 2:fix(q/2);
plot(Hz(q),gX(q,:))
patch([0 1 1 0]/HPF,[0 0 1 1]*max(max(gX)),[1 1 1]*.9);
xlabel(’Frequency (Hz)’)
ylabel(’relative spectral density’)
title(['Frequency domain',sprintf('\n'), ' {\bf',num2str(HPF),'}', ...
' second High-pass filter'],’Interpreter’,'Tex’);
grid on
axis tight
To display the frequency domain of a signal, just call this function with the appropriate RT and high-pass filter value, e.g.:
signal = (sin((1:100)*0.8)+sin((1:100)*1.4) + sin((1:100)*2))';
fft_gui(signal, 3, 128)