MATLAB: How to compute the mean amplitude of each frequency across trials

across trialsamplitudefftfrequencymean

This is probably so easy but I can't get it. After doing a fourier transform (the data matrix is trials x time so I think I do a fft in the column dimension), I first compute (for each trial) the amplitude of each frequency based on the Fourier transformed data, what I've done so far is below. It gives me a 1×450 vector.
Data=fft(data,[],2);
Dataamp = abs(Data)/n;
Dataamp = 2*Dataamp(1:n_cutoff); % scales the amps and cuts off at Nyquist
Dataamp(1) = Dataamp(1)/2; % not to scale the first term
But I now need to calculate (and later plot) the mean amplitude of each frequency across trials and would have thought I need to get the mean across each row, as in a column vector, but besides using the mean function (which only gives a single value as Dataamp is now a vector and I need multiple values) I don't know how else to think about it / go about it? i.e. what am I doing wrong?

Best Answer

Hi Becky,
I assume you have trials changing down, time changing across (each row is a trial as a function of time). The first two lines are good, but on then since you want to still preserve the rows, take a look at
Dataamp = 2*Dataamp(:,1:n_cutoff) % scales the amps and cuts off at Nyquist
Dataamp(:,1) = Dataamp(:,1)/2; % not to scale the first term
Meanamp = mean(Dataamp);
which produces a row vector of mean(abs(amplitude)).
If n is odd this is all right but if n is even I don't believe you want to double the nyquist term, so you should test for n even and if so then do
Dataamp(:,n_cutoff) = Dataamp(:,n_cutoff)/2; % not nyquist either