drawing a fast Fourier transform

3 visualizaciones (últimos 30 días)
Ken Chi
Ken Chi el 10 de En. de 2020
Editada: Ken Chi el 12 de En. de 2020
how to draw fft? Hints wanted

Respuesta aceptada

Meg Noah
Meg Noah el 11 de En. de 2020
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 comentario
Meg Noah
Meg Noah el 11 de En. de 2020
You'll need to change the xlim values to get to 0 to 120 BPM.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by