Fft graphs exhibit symmetry on the x axis, but not around 0

7 visualizaciones (últimos 30 días)
Sophie S
Sophie S el 6 de Jul. de 2022
Comentada: Star Strider el 12 de Jul. de 2022
I'm pretty inexperienced with MatLab and Fourier transform. I'm trying to convert a matrix into a Fourier transform graph using the following code:
Y = fft(ppt1_female_dob_10_10_2020_20min_normal_colon_vid_05_10_2021matrx);
n = length(Y);
pwr = abs(Y(1:floor(n/2))).^2;
freq = (1:n/2)/(n/2) * 0.5;
plot(freq,pwr)
figure,plot(freq*100,pwr)
When I did this, I obtained bimodal data for every figure generated, and they were all symmetrical around an x value not equal to 0. (See attached files). Why might I be getting graphs that look like this?

Respuestas (1)

Star Strider
Star Strider el 6 de Jul. de 2022
It appears that you are plotting part of a two-sided Fourier transform.
I generally use this approach to plot a one-sided Fourier transform —
t = linspace(0, 20, 250); % Time Vector
s = sum(sin([1:5]'*2*pi*t)); % Signal Vector
Fs = 1/(t(2)-t(1)); % Sampling Frequency
Fs = 12.4500
Fn = Fs/2; % Nyquist Frequency
figure
plot(t, s)
grid
xlabel('t')
ylabel('s')
L = numel(t);
NFFT = 2^nextpow2(L);
FTs = fft(s, NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency')
ylabel('Amplitude')
There are other approaches as well that work. There is nothing particularly special about this approach, other than it generally works for me.
.
  10 comentarios
Sophie S
Sophie S el 12 de Jul. de 2022
This is exceedingly helpful; thanks! One additional follow-up question: I attached a matrix as a .mat file as an example. Where would I put this variable name within the code to yield the signal vector for each column?
Star Strider
Star Strider el 12 de Jul. de 2022
My pleasure!
The provided .mat file is a doouble matrix, not a table, so there are no variable names associated with any of the columns. There is also no time vector or sampling frequency provided.
My previous code would change to:
LD = load('vid00232_05212022_Colon_3cm_matrx.mat');
Mouse2 = LD.vid00232_Mouse2_05212022_Colon_3cm_matrx;
L = size(Mouse2,1);
t = linspace(0, L-1, L); % Create Time Vector
figure
subplot(3,1,1)
plot(t, Mouse2(:,1))
title(sprintf('Column %4d',1))
grid
subplot(3,1,2)
plot(t, Mouse2(:,640))
title(sprintf('Column %4d',640))
grid
subplot(3,1,3)
plot(t, Mouse2(:,1280))
title(sprintf('Column %4d',1280))
grid
xlabel('Time')
Fs = 1/(t(2)-t(1));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FT_Mouse2 = fft(Mouse2-mean(Mouse2), NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
[maxpk,maxloc] = max(abs(FT_Mouse2)*2); % Maximum Peak Amplitude % Index For Each Column
PksLocs = table((1:size(Mouse2,2)).',maxpk(:),maxloc(:),Fv(maxloc(:)).', 'VariableNames',{'Column','Amplitude','Index','Frequency'});
figure
subplot(3,1,1)
plot(Fv, abs(FT_Mouse2(Iv,1))*2)
title(sprintf('Column %4d, Freq = %.6f',1,Fv(maxloc(1))))
grid
subplot(3,1,2)
plot(Fv, abs(FT_Mouse2(Iv,640))*2)
title(sprintf('Column %4d, Freq = %.6f',1,Fv(maxloc(640))))
grid
subplot(3,1,3)
plot(Fv, abs(FT_Mouse2(Iv,1280))*2)
title(sprintf('Column %4d, Freq = %.6f',1,Fv(maxloc(1280))))
grid
xlabel('Frequency')
This plots only a sample of the data, since there are too many to plot all of them. It calculates the Fourier transforms for each column and returns a table of the column number, maximum amplitude, row index of the maximum, and the corresponding frequency for each column. You can add the column names as a separate variable if you want. I did not because there were no column names provided.
If a common sampling frequency ‘Fs’ is provided, the time vector would change to:
t = linspace(0, L-1, L)/Fs; % Create Time Vector
This will also automatically change the frequencies for the peaks, and the frequency vector for the plots.
.

Iniciar sesión para comentar.

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by