FFT plotting trouble: Concatenated inputs
Show older comments
I am currently working on tap testing and am running into an issues with my FFT now that I am trying to Concatenate them to improve the "resolution". The plots max values fit what I expect however i need it to be a line and not have all the points underneath. I'm uncertian if my issue is in my measurements or in my code.
clear all
close all
clc
% each channel is notated with _n where n is the channel
% Hammer is on channel 1
% Accelerometer is on channel 2
% dataset_plot(11,'y')
% dataset_plot(12,'y')
% dataset_plot(13,'y')
%
% dataset_plot(21,'y')
dataset_plot(22,'y')
The goal is to have a single clear line so that I can create the transfer function to describe the system.
function dataset_plot(n,direction)
%% data Loading
out_2 = [];
out_1 = [];
for f_n = 1:5
fprintf('loading '+ string(n) + '_' + direction + '_' + string(f_n) + '_1.csv'+'\n')
raw_1 = table2array(readtable(string(n)+'_' + direction + '_' + string(f_n) + '_1.csv'));% read in hammer
raw_cut_1 = raw_1(3:height(raw_1),:); %remove header
if f_n == 1 %if its the first loop find signal length for window
window = hanning(length(raw_cut_1));
sample_rate = mean(diff(raw_cut_1(:,1))); %time between samples
Fs = 1/sample_rate; %Frequency in HZ
end
% Zero correction
Hammer_Zeroing = raw_cut_1(1:(length(raw_cut_1(:,2))*0.2)-1);%fix the offset
Hammer_adj = mean(Hammer_Zeroing);
raw_cut_1(:,2) = raw_cut_1(:,2) - (Hammer_adj);
%concatenate
out_1 = [out_1; raw_cut_1(:,2).*hanning(length(raw_cut_1))];
raw_2 = table2array(readtable(string(n)+'_' + direction + '_' + string(f_n) + '_2.csv'));% read in accel
raw_cut_2 = raw_2(3:height(raw_1),:); %remove header
%Zero correction
Accel_Zeroing = raw_cut_2(1:(length(raw_cut_2(:,2))*0.2)-1);%fix the offset
Accel_adj = mean(Accel_Zeroing);
raw_cut_2(:,2) = raw_cut_2(:,2) - (Accel_adj);
%concatenate
out_2 = [out_2; raw_cut_2(:,2).*hanning(length(raw_cut_2))];
clear raw_cut_2 raw_cut_1 raw_1 raw_2 padding Hammer_adj Hammer_Zeroing Accel_adj Accel_Zeroing
end
%% create X axis
Hammer = out_1;%(:,2);
Accel = out_2;%(:,2);
x_axis = linspace(0,sample_rate*length(Accel),length(Accel));
Accel = vertcat(Accel,ones(length(x_axis)-length(Accel),1).*mean(diff(Accel)));
meas_time_2 = sample_rate*length(x_axis);
%% run FFT functions
[H_f,H_P1] = FFT_ploting(smoothdata(Hammer,"gaussian",20),meas_time_2);
[A_f,A_P1] = FFT_ploting(smoothdata(Accel,"gaussian",20),meas_time_2);
%% fix units
H_P1 = H_P1./0.00225; %convert from V to N @ 2.25 mV/N
A_P1 = A_P1./0.0102; %convert from V to m/s^2 10.2 mV/(m/s²)
%% plot
close all
figure('Name','raw data check')
hold on
plot(Accel)
plot(smoothdata(Accel,"gaussian",10))
figure('Name','FFT Plots')
hold on
yyaxis left
plot(H_f,H_P1);
ylabel 'lbf'
yyaxis right
plot(A_f,A_P1);
ylabel 'm/s^2'
grid on
xlim([5 3000]); %accelerometer limit of 3000Hz
%we are focusing on 5 to 500 Hz
title('Accelerometer & Hammer FFT')
legend('Hammer FFT','Acceleromter FFT')
xlabel('Hz');
end
function [f,P1] = FFT_ploting(fun_data,meas_time)
% count = count + 1; %FFT itteration count
Fs = (meas_time/length(fun_data))^-1; %frequecy in Hz
T = 1/Fs; %meas time between samples (inverse)
L = length(fun_data);
t = (0:L-1)*T;
f = Fs*(0:(L-1)/2)/L;
fft_data = fft(fun_data,L);
P2 = (abs(fft_data/L));
P1 = P2(1:(L+1)/2);
P1(2:end) = 2*P1(2:end);
end
Accepted Answer
More Answers (0)
Categories
Find more on Vibration Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



