-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformFFT.m
More file actions
37 lines (27 loc) · 904 Bytes
/
performFFT.m
File metadata and controls
37 lines (27 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [Fss, Magnitude, Phase] = performFFT(y, dqrate, window)
% PERFORMFFT performs n-point fft on input signal y of given frequency
% rate dqrate applying a specified window.
%
% (c) Georgios Printezis 2022
NFFT = height(y);
%% Apply Window
if window == "hanning"
W = hann(NFFT);
elseif window == "hanning2"
W = hann(NFFT) .^ 2;
elseif window == "flattop"
W = flattopwin(NFFT);
elseif window == "rectangular"
W = ones(NFFT, 1);
end
y = W .* y / sum(W);
%% Two-Sided
Yts = fft(y, NFFT, 1);
Fts = (0 : 1 / NFFT : 1 - 1 / NFFT)' * dqrate;
%% Single-Sided
Yss = Yts(1 : round(NFFT / 2), :);
Yss(2 : end - 1, :) = 2 * Yss(2 : end - 1, :);
Fss = Fts(1 : round(NFFT / 2));
Magnitude = abs(Yss);
Phase = unwrap(angle(Yss));
end