Time to frequency domain
105 views (last 30 days)
Show older comments
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 Comment
krn99
on 4 Apr 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)
Accepted Answer
Star Strider
on 29 Mar 2017
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 Comments
tina26
on 11 Jun 2020
I tried this code and I get an error: FT_signal function is not defined. What could be the problem?
More Answers (2)
jagadeesh jagadeesh
on 28 Oct 2019
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)|')
0 Comments
Richard Zappulla
on 29 Mar 2017
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!
See Also
Categories
Find more on Digital Filter Design 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!