MATLAB: Time to frequency domain

fftfilter

Hi guys I have to convert the signal generated from accelerator(recorded in xls file) which is in time series to freq domian. So far I did this
% read data
data = xlsread('X');
%Frequency Analysis
time = data(:,1); % sampling time
signal = data(:,2); % signal data in Time-Domain
Ts=time;
Fs=20000; % sampling frequency
Now I want to convert this time signal to frequency signal with filtering . What should I do to get Frequency domain and filtering. Thank you in advance.

Best Answer

Read your data and plot your signal with this:
% read data
data = xlsread('X');
%Frequency Analysis
time = data(:,1); % Time Vector
signal = data(:,2); % Signal data in Time-Domain
N = length(signal); % Number Of Samples
Ts = mean(diff(time)); % Sampling Interval
Fs = 1/Ts; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FT_Signal = fft(signal)/N; % Normalized Fourier Transform Of Data
Fv = linspace(0, 1, fix(N/2)+1)*Fn; % Frequency Vector (For ‘plot’ Call)
Iv = 1:length(Fv); % Index Vector (Matches ‘Fv’)
figure(1)
plot(Fv, abs(FT_signal(Iv))*2)
grid
The ‘filtering’ step requires that you define the characteristics you want for the filter, and then design it, and filter your signal. You can filter it in the frequency-domain with the fftfilt (link) function, however it requires that you give it a finite-impulse-response or FIR filter. There are several ways to design your filter, the easiest being the designfilt (link) function.
You can also filter your signal in the time domain with either a FIR filter or an infinite-impulse-respone or IIR filter. Design your filter with the designfilt function, then use the filtfilt function to filter the signal with your filter.
See the documentation for the various functions to understand what they do and how to use them.
Related Question