我在一个 csv 文件中给出了加速度计数据,该文件如图所示加载并通过傅立叶变换运行以进行分析和过滤。过滤后的 Ifft 函数返回的值仍然具有复杂的分量。我真的不知道为什么我是傅立叶分析的新手并且在这里一无所知。我已经将代码附加到逆傅立叶,如果有人能发现错误我非常感谢你。提前感谢您的时间。
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);