How to compute the mean amplitude of each frequency across trials?
10 views (last 30 days)
Show older comments
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 1x450 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?
0 Comments
Accepted Answer
David Goodmanson
on 21 Mar 2018
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
3 Comments
David Goodmanson
on 22 Mar 2018
Hi Becky,
I'm assuming as before that you have trials changing down, time changing across. So a matrix that is, say, 100 x 400 has 100 trials, each trial being a row vector with 400 samples in time,is that correct? If so, a picture being worth 2^10 words:
time --->
tri- d d d d d d d d
als d d d d d d d d
| d d d d d d d d
| d d d d d d d d
\/ d d d d d d d d
When you take the fft along the rows as you did, you get
frequency --->
tri- d d d d d d d d
als d d d d d d d d
| d d d d d d d d
| d d d d d d d d
\/ d d d d d d d d
Then to get the mean at each frequency you take the mean down the columns to get
frequency --->
mean over trials d d d d d d d d
More Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!