Time to frequency domain

105 次查看(过去 30 天)
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 个评论
krn99
krn99 2017-4-4
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)

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2017-3-29
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 个评论
tina26
tina26 2020-6-11
I tried this code and I get an error: FT_signal function is not defined. What could be the problem?

请先登录,再进行评论。

更多回答(2 个)

jagadeesh jagadeesh
jagadeesh jagadeesh 2019-10-28
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 2017-3-29
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 个评论
s p
s p 2017-3-29
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Digital Filter Design 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by