how to use fft to plot the average values and their standard deviations in the frequency domain?
5 views (last 30 days)
Show older comments
Matthew Worker
on 18 Feb 2023
Commented: Sulaymon Eshkabilov
on 18 Feb 2023
Hello,
I would like to plot a signal (av) containing average values in the frequency domain, having a vector T containing time values.
But i would also like to put in the same plot the curve of av+ the vector of standard deviations sd
Here's the code i have used:

when i plot only av in the frequency domain i get a curve like this:

However when I plot both, i only get one curve and the other one has null values:

Any ideas of how to do it?
Best regards.
0 Comments
Accepted Answer
Sulaymon Eshkabilov
on 18 Feb 2023
First of all, both signals need to be in one domain. If the freq domain is chosen then both need to be in the freq domain.
In your shown part of your code, it is in freq domain. That is ok.
Presumably as shown here the magnitude of the two signals differ significantly and thus, they are not visible. To make both signals visible, use yyaxis l;eft and yyaxis right - see example:
fs = 2000; % Sampling frequency
t =0:1/fs:5; % Time
F1 = 5; % Lowest frequency
F2 = 17; % Mid frequency
F3 = 55; % Highest frequecy
X1 = 0.25*sin(2*pi*t*F3)+randn(size(t))*.5;
X2 = 3*sin(2*pi*t*F1)+cos(2*pi*t*F2)+randn(size(t))*.5+X1;
yyaxis left
N = 2^nextpow2(length(X1));
Y1 = fft(X1, N); % FFT of the signal x1(t)
Y2 = fft(X2, N); % FFT of the signal x2(t)
freq = fs*(0:(N/2))/N; % Freq values
Yp1 = abs(Y1/N); % Absolute value or magnitude of the signal spectrum
Yp2 = abs(Y2/N);
yyaxis left
plot(freq,Yp1(1:N/2+1))
ylabel('Magnitude of signal = |Y1(f)|')
yyaxis right
plot(freq,Yp2(1:N/2+1))
title('FFT analysis of a signal')
xlabel('Frequency, [Hz]')
ylabel('Magnitude of signal = |Y2(f)|')
grid on
xlim([0, 65])
2 Comments
More Answers (0)
See Also
Categories
Find more on Spectral Measurements 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!