fft doesnt work for me

조회 수: 3 (최근 30일)
Ali Ghazzawi
Ali Ghazzawi 2020년 6월 22일
댓글: Star Strider 2021년 10월 25일
good morning i am a student first year in collage. i want to analyze signals for a project using fft but for some reason the plot looks weird of the hz spectrum a very high spikes occuer at 0hz and the end of the plot causing very narrow plot. here is the code and the signal file and the plot.
clear all
xls=xlsread('signals'); %importing the excel file
xlsz=size(xls); %size of the xls
xlr=xlsz(1); %number of rows
m=1000000;% scaling factor of time (Micro)
t=1/m*xls(2:xlr,1)';
%%
signum=5; %the signal number
y=xls(2:xlr,signum+1);
%%
x=fft(y);%fourier transform
f=(0:length(x)-1)*m/length(x); % detecting the range of for frequancy
plot(f,abs(x))
please help thank you

채택된 답변

Star Strider
Star Strider 2020년 6월 22일
Try this:
xls = xlsread('signals.xls');
t = [0; xls(2:end,1)]*1E-6; % Time Vector (Set Initial ‘NaN’ To 0)
Fs = 1/mean(diff(t)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
y = xls(:,2:end); % Signal Matrix
ym = y - mean(y); % Subtract Column Means From All Columns (Eliminates D-C Offset Effect)
L = numel(t); % Signal Lengths
FTy = fft(ym)/L; % Fourier Transform (Scaled For Length)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTy(Iv,:))*2)
grid
sep = ones(numel(Fv),1) * (1:size(FTy,2)); % ‘Separation’ Matrix — Plots Each Record In Its Column Locatioln
Fm = ones(numel(size(FTy,2)),1) * Fv; % Frequency Matrix
figure
plot3(Fm, sep, abs(FTy(Iv,:))*2)
grid on
xlabel('Frequency (Hz)')
ylabel('Record (Column #)')
zlabel('Amplitude')
My code first subracts the mean from each column in order to eliminate the D-C offset at 0 Hz. It then simply calculates the fft of each column. The ‘Fv’ vector is a vector of the frequencies for a one-sided Fourier transform, and ‘Iv’ is the vector of indices corresponding to those frequencies, so that they are plotted correctly.
With 44 records, I added the second figure in order to make the Fourier transform of each record easier to see. The ‘sep’ matrix creates offsets for each record, and ‘Fm’ is the matrix of frequency vectors for each record (both required for plot3).
.
  댓글 수: 7
Jonnathan Singh Alvarado
Jonnathan Singh Alvarado 2021년 10월 25일
YOU GUYS ARE GODSENDS
Star Strider
Star Strider 2021년 10월 25일
Thank you!
A Vote is always appreciated!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by