how do i know which filter should i use?

8 views (last 30 days)
Sheraz Khan
Sheraz Khan on 19 Oct 2018
Commented: Star Strider on 20 Oct 2018
Hi guys, I have been working on a smartphone sensor and I have the data. it consists of time acceleration in x y z-direction. so i tried to plot the time history of all three in one graph and guess what, it comes up EMPTY. can anybody clear this issue for me? secondly, when I run FFT for the data it shows a lot of peaks(it should be showing a few peaks right?) I know there is noise in the signal but then I don't know which filter to use. how am I suppose t know which kind of filter is suitable for which condition. and how am I suppose to remove the peaks now.. I
have attached the data file (the data i used is till row 3767). i used the following code,,
%%Import data from text file.
% Script for importing data from the following text file:
%
% F:\Masters BUW\MASTER ARBEIT\Sensor Simulation\Data\SM-G950F_samsung_dreamltexx.csv
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.
% Auto-generated by MATLAB on 2018/10/19 00:51:50
%%Initialize variables.
filename = 'F:\Masters BUW\MASTER ARBEIT\Sensor Simulation\Data\SM-G950F_samsung_dreamltexx.csv';
delimiter = ' ';
startRow = 23;
endRow = 3767;
%%Format for each line of text:
% column1: double (%f)
% column2: double (%f)
% column3: double (%f)
% column4: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%f%f%f%f%*s%*s%[^\n\r]';
%%Open the text file.
fileID = fopen(filename,'r');
%%Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines', startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
%%Close the text file.
fclose(fileID);
%%Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
%%Allocate imported array to column variable names
tim = dataArray{:, 1};
x = dataArray{:, 2};
y = dataArray{:, 3};
z = dataArray{:, 4};
%%Clear temporary variables
clearvars filename delimiter startRow endRow formatSpec fileID dataArray ans;
%%mydata
t=tim-3.103056357614000e+03;
accx=detrend(x, 'constant');
accy=detrend(y, 'constant');
accz=detrend(z, 'constant');
X= [accx, accy, accz];
%
for i = 1:1:3
subplot(3,1,i)
plot(t,X(i))
end
Fs= 50;
T= 1/Fs;
L=3745;
time= (1:L-1)*T;
accxx= detrend(accx);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(accxx,NFFT,1);
f = Fs/2*linspace(0,1,NFFT/2);
% Plot single-sided amplitude spectrum.
figure
plot(f,abs(Y(1:NFFT/2)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
  3 Comments
Rik
Rik on 20 Oct 2018
Today I formatted your code, next time, use the {}Code button. See here for a GIF showing how to do it.
Star Strider
Star Strider on 20 Oct 2018
If you have broadband noise (as it appears you do), a frequency-selective filter will not produce the results you want.
I would use the Wavelet Toolbox (link) functions instead.

Sign in to comment.

Answers (0)

Categories

Find more on Signal Generation and Preprocessing 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!