Issue with FFT/Power Spectral Density
Show older comments
Can someone explain what I'm doing wrong here? I wanna evaluate the PSD of ECG data (electrocardiogram), but I end up with this enormous peak in the fourier domain that I don't know what to do with. Where does this come from? What to do about it?
clear
load ecg_stress_test.mat
n=length(ecg_data);
fhat=fft(ecg_data,n);
PSD=fhat.*conj(fhat)/n;
figure
subplot(2,1,1), plot(ecg_data), xlim([0 length(ecg_data)])
subplot(2,1,2), plot(PSD), xlim([0 length(PSD)])
Accepted Answer
More Answers (1)
Paul
on 4 Nov 2021
That peak is at dc because the mean of the data is very large. Try
fhat=fft(detrend(ecg_data),n);
to take out the mean before taking the fft.
6 Comments
Sebastian Daneli
on 4 Nov 2021
What do you see for
sum(detrend(ecg_data))
and what is the index of PSD wher you see the spike?
Sebastian Daneli
on 4 Nov 2021
Hmm. My understanding of what should happen is:
n=length(ecg_data);
fhat=fft(detrend(ecg_data),n);
At this point we should have
fhat(1) == sum(detrend(ecg_data)) % to within rounding errors
What do you see for fhat(1) and sum(detrend(ecg_data)) ?
PSD=fhat.*conj(fhat)/n;
So you should see
PSD(1) == fhat(1)^2/n ;
Can you run this exact code and show the results:
clear
load ecg_stress_test.mat
whos ecgdata
n=length(ecg_data);
fhat=fft(detrend(ecg_data),n);
[fhat(1) sum(detrend(ecg_data))]
PSD=fhat.*conj(fhat)/n;
[PSD(1) fhat(1).^2/n]
Sebastian Daneli
on 5 Nov 2021
Paul
on 8 Nov 2021
I was confused abou the use of detrend. It should have been
fhat = fhat=fft(detrend(ecg_data,'constant'),n);
to subtract the mean.
Categories
Find more on Parametric Spectral Estimation 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!

