FFT when rescaling data
1 view (last 30 days)
Show older comments
David Harra
on 25 Mar 2022
Commented: Walter Roberson
on 25 Mar 2022
Hi everyone
I have been trying to use an FFT on my imported data. My Time step from my data wasn't equidistant so I tried to use the interp1 function as seen in the code below and it seems to give me a plot which seems reasonable, so I think the code is correct. My time and frequency domain can be seed side by side just below.
My issue is when I try to rescale my data such that the amplitude is rescaled from 0 to 1. You can see the time domain signal is scaled but the FFT looks very off and I have no idea why. Its making me not feel confident about my origanl attempt of the FFT or I am perhaps not accounting for something when rescaling the data. Also below you can see my recaled images showing how different the FFT has turned out
Any help would be great. Thanks :)
FName = 'Tit_10MHz_110F.flxhst';
MyData = read_history(FName);
Time = MyData.TimeRecB.Time;
Data= MyData.DataRecB(1).Data;
%%
%Start signal from the front wall
select= find(Time>=2.7e-6 & Time<=7e-6);
Time= Time(select);
Data= Data(select);
% Data=rescale(Data);
%Plot Data
figure(01)
plot(Time,Data)
xlabel('Time (s)')
xlim([2.7e-6 7e-6])
ylabel('Amplitude')
title('Features 110 Full A-scan')
%FFT of full signal
dt=Time(2)-Time(1); %Time step
xq=Time(1):dt:Time(end); % Time step is not equidistant so need to create time array and inerpolate the data ?
interpolated_signal=interp1(Time, Data, xq).' ;
fft_points = 2 ^ nextpow2(size(interpolated_signal, 1));
time_step=xq(2)- xq(1); % New Time step
frequency_spectrum = fft(interpolated_signal, fft_points);
frequency_spectrum = frequency_spectrum(1:end / 2, :);
frequency_step = 1 / (fft_points * time_step);
frequency = ([1 : fft_points / 2] - 1) * frequency_step;
figure(02)
plot(frequency/1e6, abs(frequency_spectrum));
xlabel('Frequency (MHz)')
xlim([0 20])
ylabel('Amplitude')
title('Features 110 FFT Full Signal')
Accepted Answer
Walter Roberson
on 25 Mar 2022
The first bin of an fft result is the sum of the input signal.
In cases where the mean of the signal is 0, then the sum of the signal would be 0, and the first bin would be 0.
But you shifted the baseline of your data from about 0 to about 1/2. If you had a signal length of (say) 5000, then the sum() around that 1/2 is going to be roughly 2500 as the first bin of the fft.
When the first item in a plot is 2500-ish and the other values are at most 50-ish then the 50-ish data is noise compared to the 2500 values, so the 50-ish data barely shows up on the plot.
There is nothing you can do about this. You deliberately shifted the mean to about 1/2 and now you are stuck with the first bin of the fft being about 2500. If you want to plot the entire fft, then you can no longer expect a useful output.
You could xlim() to skip that first point. You could remove the first point before you plot (make sure you correct the frequencies.) You could zero out the first bin. But if you want to plot it all accurately... you are stuck.
0 Comments
More Answers (0)
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!