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 CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by