zero frequency amplitude issue at fft

30 views (last 30 days)
Bass Tea
Bass Tea on 6 Jun 2021
Edited: Paul on 8 Jun 2021
hey,
i wanna fft torque and rotational speed data sets like this
actually i know the theory and have read the docs of fft and zero padding, etc.
but to be sure that i will get correct spectrum of unperiodic measurement data, i startet to verify code on well known signal construct
example:
% assumed i would have a signal superposed of 3 single sinusodials..
A0 = 9.5; A1 = 25; A2 = 15; % physical amplitudes in [rpm] (no voltages)
f0 = 0; f1 = 10; f2 = 22; % frequency in [Hz]
% assumed sampling frequency is 50 [Hz], samples every 20 [ms]..
fs = 50;
% this leads to..
n = A0 + A1*sin(2*pi*10*t) + 15*sin(2*pi*22*t); % superposed speed signals
% assumed measurement row carries 653 elements..
t = (0:1/fs:662*1/fs)';
% this leads to..
t = (0:1/fs:662*1/fs)';
S0 = A0*ones(size(t));
S1 = A1*sin(2*pi*f1*t);
S2 = A2*sin(2*pi*f2*t);
S = S0 + S1 + S2;
figure();
ax1 = subplot(4,1,1); plot(t,S0); grid on;
ax2 = subplot(4,1,2); plot(t,S1); grid on;
ax3 = subplot(4,1,3); plot(t,S2); grid on;
ax4 = subplot(4,1,4); plot(t,S,'r'); grid on;
linkaxes([ax1,ax2,ax3,ax4],'x');
So, actually after fft i expect 3 peaks: 9.5 rpm @ 0 Hz, 25 rpm @ 10 Hz and 15 rpm @ 22 Hz if i match the frequency bins and so on as well as possible.
But for sure i dont expect amplitude greater than those, if any, thy should be smaller than those
% if i'm not doing zero padding with..
L_n = (size(n,1));
Nfft = L_n; % 1*2^nextpow2(L_n);
f_n = fs*(0:(Nfft/2))/Nfft;
Y_n = fft(n,Nfft);
P2_n = abs(Y_n/L_n);
P1_n = P2_n(1:Nfft/2+1);
P1_n(2:end-1) = 2*P1_n(2:end-1);
% i get this:
% Ok, S0 got a little excess, S1 and S2 are a little undercut as expected.
% Now, if i'm increasing zero padding to NOT increase the DFT/FFT resolution
% but to increase the readability, with ...
...
Nfft = 1*2^nextpow2(L_n); % padds to 1024
... (rest is even)
% i get..
% So, we are getting closer..
% If i further increase zero padding with..
...
Nfft = 8*2^nextpow2(L_n); % padds to 8192
... (rest is even)
% i got..
So, S1 & S2 fit well, but S0 "ffs"??????? How could i trust this DC signal if i wouldn't know the source signal..??? Technically zero padding adds zeros to the signal and @ it's the overall mean value of overall signal. So why the mean value - aka 0 Hz - isn't deceasing with zero padding instead of increasing. If i'm adding multiple zeros, the mean value should decrease . How can i know, how far i can push zero padding to not kill the DC signal
regards

Answers (3)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 6 Jun 2021
WHat you are doing is not zero padding. You are changing the block size and freq resolution.
Thus, no matter what would be the block size DC will be present in your exercise because of S0 = A0*ones(size(t));
Zero-padding will be done with the signal in time domain. And in your exercise, zero-padding will be done with:
S0 = A0*zeros(size(t))
  1 Comment
Bass Tea
Bass Tea on 7 Jun 2021
Hey, thy for your answer.
first of all, e.g. i refer my code to https://de.mathworks.com/help/signal/ug/amplitude-estimation-and-zero-padding.html and because they are increasing "L" and call it zero padding, i assumed, that "fft" with
fft(data, L)
instead of
fft(data)
will automatically automatically fills signal with trailing zeros in time domain. If its not, i misunderstodd something. But anyway. The key is, that i want my constructed signal to have a certain DC value. If i'm using your advice with
A0*zeros(size(t))
, yeah both amplitudes right-hand side fill exactly my exspectations. worse amplitude along with bad frequency bins. amplitude is getting more exactly when increasing frequency resolution. But that way i kicked DC-signal. In later real measurement data i cannot kick minor DC values as well.
i dont get, why i cannot preserve the DC part of superposed signal and get correct amplitudes as well. there have to be a way.

Sign in to comment.


Paul
Paul on 6 Jun 2021
Edited: Paul on 6 Jun 2021
In the third plot, the data tip is not at X = 0 (as is the case with the first two plots). Try zooming in and picking the actual first point on the plot.
Also, the way the code runs the value of the FFT at dc will be the same in all three cases because of this line:
P2_n = abs(Y_n/L_n);
because it looks like L_n is always 663. The FFT at dc would decrease if this line instead were Y_n/Nfft. I'm just pointing this because there seemed to be an expectation that the FFT at dc would decrease with increased zero padding.
  4 Comments
Bass Tea
Bass Tea on 7 Jun 2021
obviously the side band amplitudes in fft are getting more and more accurate with more "padding", but the DC amplitudes is getting worse and worse (in detail the amplitude right next to DC)
but if i'm not "padding", the sideband amplitudes are terrible. how can i know - with a unknown, non-synthesis measurement signal - how far i can "pad" to get acceptable sideband amplitudes.
in terms of that sythesis signal here i would now say: ok i pad a little - from 663 to 1024 datapoints - and therefore i m getting good DC amplitude (9.552 instead of 9.5), good amplitude at 10 Hz (24.35 instead of 25) and ok amplitude at 22 Hz (13.1 instead of 15 here)
but how can i know, if i'm not knowing the measurement signal
Paul
Paul on 7 Jun 2021
Edited: Paul on 8 Jun 2021
In response to this comment, my point wrt the division by L_n is that because the original code divides by L_n (as opposed to the Nfft length after zero-padding), the reults at dc will be the same at dc for all three cases, which is now shown after zooming in on the third case (the value for all three values of Nfft is 9.552).
I was not recommending to divide by Nfft, I was just making a point in response to the statement in the Question that "If i'm adding multiple zeros, the mean value should decrease." Of course the mean value should decrease, but by dividing by L_n the value at dc will not be the mean. An in no case did the value at dc increase (it is always 9.552 if dividing by L_n).
Finally, consider this line:
P1_n(2:end-1) = 2*P1_n(2:end-1);
I think that line is why you're seeing such high "sideband" to the right of dc. Zero padding can introduce high values of the FFT at frequencies to the right of dc (but still smaller than the dc value), (plot the fft of S0 for different values of Nfft), and then they get mutiplied by 2.

Sign in to comment.


Sulaymon Eshkabilov
Sulaymon Eshkabilov on 6 Jun 2021
Here is correctly zero-padded signal and fft of whole signal:
...
% this leads to..
t = (0:1/fs:662*1/fs)';
S0 = A0*zeros(size(t)); % Zero-padded
%S0 = A0*ones(size(t));
S1 = A1*sin(2*pi*f1*t);
S2 = A2*sin(2*pi*f2*t);
S = S0 + S1 + S2;
...
figure
plot(f_n, P1_n) % Compare this one
  1 Comment
Bass Tea
Bass Tea on 7 Jun 2021
i dont think that is correct zero padding !?!?
You just kicked out my certain DC samples with valueing to zero.
i understand zeropadding for a DC signal e.g.
4, 4, 4, 4, 4, 4 is streched to 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0
then i padded 4 zeroes to original signal in time domain. Am i wrong?

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!