
fft doesnt work for me
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ali Ghazzawi
le 22 Juin 2020
Commenté : Star Strider
le 25 Oct 2021
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
0 commentaires
Réponse acceptée
Star Strider
le 22 Juin 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Discrete Fourier and Cosine Transforms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
