Commit 3e39e5cb authored by John, Fabian's avatar John, Fabian
Browse files

Added fft_single_sided functionality

function [y_fft,f] = fft_single_sided(x_data,y_data,fmax)
%FFT_SINGLE_SIDED encapsulates the fft matlab functionality. [y_fft,f] = fft_single_sided(x_data,y_data,fmax)
% This function automatically performs zerofill to a size of 10 times of the input data.
% Only the sigle sided spectrum is given
% The output f is automatically limited to the given frequency fmax
T = x_data(2)-x_data(1); % Sampling period
Fs = 1/T; % Sampling frequency
L = length(x_data)*10; % Length of signal
t = (0:L-1)*T; % Time vector
Y = fft([reshape(y_data, [1, length(y_data)]), zeros(1, (length(x_data)*10)-length(y_data))]);
P2 = abs(Y/L);
y_fft = P2(1:L/2+1);
y_fft(2:end-1) = 2*y_fft(2:end-1);
f = Fs*(0:(L/2))/L;
max_idx = find(f > fmax, 1);
if length(max_idx) == 1
f = f(1:max_idx-1);
y_fft = y_fft(1:max_idx-1);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment