drawing a fast Fourier transform

1 回表示 (過去 30 日間)
Ken Chi
Ken Chi 2020 年 1 月 10 日
編集済み: Ken Chi 2020 年 1 月 12 日
how to draw fft? Hints wanted

採用された回答

Meg Noah
Meg Noah 2020 年 1 月 11 日
Here's a solution
X = dlmread('ECG.csv');
Fs = 350*60; % [samples/min] sampling frequency
T = 1/Fs; % [s] sampling period
N = 3000; % [samples] Length of signal
t = (0:N-1)*T; % [s] Time vector
deltaF = Fs/N; % [1/min]) frequency intervalue of discrete signal
figure('color','white','position',[70 100 600 900]);
subplot(3,1,1);
plot(60*t,X)
title({'Heartbeat data'})
xlabel('t (seconds)')
ylabel('X(t)')
% compute the fast fourier transform
Y = fft(X);
% manually shifting the FFT
Y = abs(Y/N);
Amp = [Y(ceil(end/2)+1:end)' Y(1) Y(2:ceil(end/2))']';
if (mod(N,2) == 0)
sampleIndex = -N/2:1:N/2-1; %raw index for FFT plot
else
sampleIndex = -(N-1)/2:1:(N-1)/2; %raw index for FFT plot
end
AmpSquared = Amp.^2;
subplot(3,1,2);
plot(deltaF*sampleIndex, AmpSquared);
hold on;
idx = find(AmpSquared > 15);
idx(sampleIndex(idx) < 0) = [];
plot(deltaF*sampleIndex(idx), AmpSquared(idx), '+');
for k = 1:length(idx)
if (idx(k) > (N-1)/2 && AmpSquared(idx(k))> 15)
h = text(deltaF*sampleIndex(idx(k)), AmpSquared(idx(k))+2,...
['f=' num2str(deltaF*sampleIndex(idx(k))) ' BPM']);
set(h,'rotation',60)
end
end
xlabel('Frequency [BPM]');
ylabel('|FFT(ECG)|^2');
title(['Power of FFT of ECG']);
xlim([0 max(deltaF*sampleIndex)/4]);
subplot(3,1,3);
half_f = deltaF*(0:(N/2));
plot(60*fftshift([half_f -fliplr(half_f(2:end+mod(N,2)-1))]), ...
abs(fftshift(Y)/N).^2);
xlabel('Frequency [BPM]');
ylabel('|FFT(ECG)|^2');
title('Using fftshift - Displaying Full Spectrum Power');
HeartbeatPower.png
  1 件のコメント
Meg Noah
Meg Noah 2020 年 1 月 11 日
You'll need to change the xlim values to get to 0 to 120 BPM.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by