why am i getting complex values with IFFT?
Afficher commentaires plus anciens
I have accelerometer data given in a csv file that is loaded as shown and ran through a fourier transform to analyze and filter. The Ifft function after filtering returns values with complex components still. I really have no idea why i am new to fourier analysis and am quite in the dark here.I have attached the code up to the inverse fourier, if anyone can spot a mistake id appreciate you so much. Thanks for your time in advance.
clear all
close all
clc
data = readmatrix("sensor3.csv","Range","160:578"); % Impulse Input Data
%data = readmatrix("test 1.csv","Range","4000:5742");
%171
time = data(:,1); % Time in seconds
gforce_z = data(:,4) - 1; % Vertical G-Forces, Removed Acceleration caused by gravity
accel = gforce_z .* -9.8067; % Convert G's to m/s^2
figure(1) % Unprocessed G-force vs time data.
plot(time,accel)
title("Noisy Acceleration vs Time")
xlabel("Time (s)")
ylabel("Acceleration m/s^2")
%% Applying noise filters
%fourier analysis
L = length(time);
%Fs2 = (length(time)/(time(end)-time(1)));
Fs = 1/mean(diff(time)); %same thing as above but computationally easier
f = (0:L-1) * Fs/L; %frequency vector 1xnnnn
%fast fourier transform
fftdata = fft(accel);
%normalize fft
fft_norm = (1/L) * fftdata;
%plot phase angle and amplitude
figure(2)
%subplot(1,2,1)
plot(f,abs(fft_norm),'*'),xlabel('Frequency (Hz)'),ylabel('Amplitude')
% subplot(1,2,2)
% plot(f,angle(fft_norm),'*'),xlabel('Frequency (Hz)'),ylabel('Phase Angle')
%fft data into table
ffttable = table(fft_norm.',f,abs(fft_norm.'),angle(fft_norm.'))
ffttable.Properties.VariableNames = {'FFT coeff','Frequency','Amplitude','Phase Angle'}
disp(ffttable)
%%
%deciding dominant frequencies to keep
indices1 = f(length(time)/2:end) > 94 %(high)range of frequencies aloud in reconstruction
indices2 = f(1:(length(time)/2)) < 7 %Low range
indices = [indices2' ; indices1'] %make sure this vector length is = to length of fft
Accel_recon = indices.*fftdata %multipying by logical array to zero out
%undesireable amplitudes
%reconstructing acceleration data
accel_smooth = ifft(Accel_recon);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Transforms dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!