How do I do the fourier transform of a data array?
49 views (last 30 days)
Show older comments
Goncalo Costa
on 18 Jun 2022
Commented: Star Strider
on 20 Jun 2022
I have been trying to do the fourier transform of a reference signal and of a row of signals, but the results I am getting are not the way they should be. What am I doing wrong?
I have got a two data arrays, the first is a reference signal and the second are 240 individual main signals (obtained over a period of 60 seconds). These signal are THz signals and their Fourier Transform is expected to take a certain shape, as shown in the the figure below (left shows the signal and right shows the fourier of the signal):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036975/image.png)
Fig.1 - Stereotypical FFT of a THz signal.
Each signal (the reference and the 240 main data signals) is composed of 1496 points.
The reference is : 1 x 1496;
The main signal is : 1496 x 240 (I was too lazy to make a transpose of this, but it can be easily done).
To get the fourier transform of said signal I have written the following:
ref_ft = fft(ref_clean); %ref_clean is the reference signal 1 x 1496;
for p=1:240
data_ft(:,p)=fft(data_clean(:,p)); %data clean are the main 240 signals, 1496 x 240 ;
end
plot(freq, ref_clean); %plotting them against frequency
plot(freq, data_clean)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036980/image.jpeg)
Fig. 2 - My FFT of the reference signal
This, in no shape of form looks like examples shown in Fig. 1. What could I be possibly doing wrong? Is it potentially the shape of my data? I don't think it is because my reference is a simple shape and I haven't had to put it through a for loop.
Any help would be deeply appreciated.
I have attached the data files in case anyone finds something weird about them.
0 Comments
Accepted Answer
Star Strider
on 18 Jun 2022
Try this —
% LD1 = load('ref_clean.mat');
% ref_clean = LD1.ref_clean;
LD2 = load('data_clean.mat');
data_clean = LD2.data_clean;
figure
waterfall(data_clean)
grid on
xlabel('rows')
ylabel('cols')
title('Signal Matrix')
Fs = 1; % Default Sampling Frequency (Actual Value Unstated)
Fn = Fs/2; % Nyquist Frequency
L = size(data_clean,1); % Signal Length
NFFT = 2^nextpow2(L); % For Efficiency
FTd_c = fft(data_clean,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
for k = 1:fix(size(FTd_c,2)/20)
idx = 12*(k-1)+1;
subplot(6,2,k)
plot(Fv, abs(FTd_c(Iv,idx))*2)
grid
xlabel('Frequency (Units)')
ylabel('Amplitude')
title(sprintf('Row %3d',idx))
end
Fh = gcf;
pos = Fh.Position;
Fh.Position = pos + [-100 -500 200 500]; % Expand To Show Detail
I have no idea what ‘ref_clean’ is, so I didn’t use it.
All the signals appear to be essentially the same, so their Fourier transforms are also essentially the same.
Supply the appropriate value of ‘Fs’ to get the correct frequency vector.
.
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!