Time to frequency domain

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.

1 comentario

krn99
krn99 el 4 de Abr. de 2017
Hello can any one say the difference between 1st part fft code and 2nd part 1, X=load('EMG_neurogenic.txt'); Fs=1000; L=length(X); Y = fft(X); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; plot(f,P1)
2, Ts = mean(diff(time)); % Sampling Interval Fs = 1/Ts; % Sampling Frequency Fn = Fs/2;
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);
figure(1) plot(Fv, abs(FT_Signal(Iv))*2)

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 29 de Mzo. de 2017

1 voto

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.

9 comentarios

s p
s p el 29 de Mzo. de 2017
Thank you for the help.
Star Strider
Star Strider el 29 de Mzo. de 2017
My pleasure.
s p
s p el 29 de Mzo. de 2017
I just got frequency domain but would also like to find out the 1x 2x 3x ..harmonics from the frequency graph plotted using MATLAB so that I can compared these faulty condition with healthy condiiton. What should I do in MATLAB to get it done?
Star Strider
Star Strider el 29 de Mzo. de 2017
The easy way would be to use the Signal Processing Toolbox findpeaks function. That will give you the amplitudes and frequencies of the peaks. It has a number of name-value pair arguments that will help you define your peaks of interest without having to do significant extra coding.
The more difficult way would be to define bandpass filters for the frequencies you want (this requires knowing the frequencies before you define the filters), then filtering your time-domain signal with each filter.
I would use findpeaks first, and only use the filters if findpeaks does not give you the result you want, and the frequencies of the harmonics are known in advance.
krn99
krn99 el 4 de Abr. de 2017
hello strider my data base is of .txt format, m beginner to matlab. apologies if its sounds simple...my signals contain 200000 samples..can u send me code to compute fft,and calculate and plot power spectral density and mean frequency of my signal
krn99
krn99 el 4 de Abr. de 2017
Hello Strider, i tried to calculate answer from your code but getting wrong answer
Ts = mean(diff(time)); % Sampling Interval msgbox(strcat('time = ',mat2str(Ts),''));
the output m getting is 1....but actually my signal contain 200000 samples
krn99
krn99 el 4 de Abr. de 2017
Hello can any one say the difference between 1st part fft code and 2nd part 1, X=load('EMG_neurogenic.txt'); Fs=1000; L=length(X); Y = fft(X); P2 = abs(Y/L); P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; plot(f,P1)
2, Ts = mean(diff(time)); % Sampling Interval Fs = 1/Ts; % Sampling Frequency Fn = Fs/2;
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);
figure(1) plot(Fv, abs(FT_Signal(Iv))*2)
tina26
tina26 el 11 de Jun. de 2020
I tried this code and I get an error: FT_signal function is not defined. What could be the problem?
Mohanad Ayman
Mohanad Ayman el 31 de Mayo de 2021
@tina26 show us ur code, please

Iniciar sesión para comentar.

Más respuestas (2)

jagadeesh jagadeesh
jagadeesh jagadeesh el 28 de Oct. de 2019

1 voto

Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
% Sum of a 50 Hz sinusoid and a 120 Hz sinusoid
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
y = x + 2*randn(size(t)); % Sinusoids plus noise
figure(1)
plot(Fs*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)'
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
figure(2)
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
Richard Zappulla
Richard Zappulla el 29 de Mzo. de 2017

0 votos

Hi,
For converting the data to the frequency domain, I would suggest using the fft() function. The examples from the MATLAB documentation on this function will form a good template for you (fft documentation webpage: FFT documentation).
As far as filtering the data, you can potentially use filteredData = filter(b,a,rawData), where b and a are the numerator and denominator coefficients of the filter. As far as determining the coefficients, that is problem specific. Results of the FFT of the raw data will help inform the selection of your coefficients.
Hope this helps!

1 comentario

s p
s p el 29 de Mzo. de 2017
I know that I should fft function but how should I use above mentioned data to get FFT result using fft() fundtion that is the concern.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

s p
el 29 de Mzo. de 2017

Comentada:

el 31 de Mayo de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by