how can i plot a power spectrum for my signal?

306 次查看(过去 30 天)
i generated three signal of frequency 1hz, 2hz and 3 hz. added these three signal. how to plot power spectrum for the added signal?
N=1024;
fs=1000;
f=1;
ts=1/fs;
t = ts*(0:N-1);
x=sin(2*pi*f*t);
subplot(2,3,1)
plot(t,x)
title('1hz');
f1=2;
x1=sin(2*pi*f1*t);
subplot(2,3,2)
plot(t,x1)
title('2hz');
f2=3;
x2=sin(2*pi*f2*t);
subplot(2,3,3)
plot(t,x2)
title('3hz');
x3=x+x1+x2;
subplot(2,3,4)
plot(t,x3)
title('added freq signal');

采纳的回答

Frantz Bouchereau
Frantz Bouchereau 2021-7-29
There are various ways in which you can compute and plot true power spectrum or power spectral density in MATLAB (when I say 'true power spectrum' I mean that the output values correspond to actual power values).
1) If you want to compute the power spectrum without having to specify many parameters and want the function to choose the best parameters for you, you can use pspectrum. Calling the function without outputs will give you a plot with the computed power spectrum.
2) If you want to compute power spectrum or power spectral density and want full control over the window size, window overlap, window type, and number of FFT points, you can use the Welch periodogram pwelch function. Calling the function without outputs will give you a plot with the computed power spectrum.
3) If you want to just visualize the power spectrum, you can use the Signal Analyzer app. The app let's you visualize your signals simultaneously in the time, frequency, and time-frequency domains. You can zoom into signal regions of interest and analyze the spectra at those zoomed regions.
4) If you have split your signals into multiple signal frames you can use the Spectrum Analyzer scope.
Finally, here is a popular MATLAB doc page that explains the relationship between FFT and true power spectra: Power Spectral Density Estimates Using FFT.

更多回答(1 个)

Bhaskar R
Bhaskar R 2019-11-16
It is from the reference
N=1024;
fs=1000;
% signal 1Hz
f=1;
ts=1/fs;
t = ts*(0:N-1);
x=sin(2*pi*f*t);
subplot(4,2,1),plot(t,x),title('1hz');
% power spectrum of 1 Hz
y = fft(x);
N = length(x); % number of samples
f = (0:N-1)*(fs/N); % frequency range
pow = abs(y).^2/N; % power of the DFT
subplot(4,2,2),plot(f,pow), title('1hz power');
% signal 2Hz
f1=2;
x1=sin(2*pi*f1*t);
subplot(4,2,3),plot(t,x1),title('2hz');
% power spectrum of 3 Hz
y = fft(x1);
N = length(x); % number of samples
f = (0:N-1)*(fs/N); % frequency range
pow = abs(y).^2/N; % power of the DFT
subplot(4,2,4),plot(f,pow), title('2hz power');
% signal 3Hz
f2=3;
x2=sin(2*pi*f2*t);
subplot(4,2,5),plot(t,x2),title('3hz');
% power spectrum of 3 Hz
y = fft(x2);
N = length(x); % number of samples
f = (0:N-1)*(fs/N); % frequency range
pow = abs(y).^2/N; % power of the DFT
subplot(4,2,6),plot(f,pow), title('3hz power');
% signal combined Hz
x3=x+x1+x2;
subplot(4,2,7),plot(t,x3),title('added freq signal');
% power spectrum of combined Hz
y = fft(x3);
N = length(x); % number of samples
f = (0:N-1)*(fs/N); % frequency range
pow = abs(y).^2/N; % power of the DFT
subplot(4,2,8),plot(f,pow), title('combine hz power');
  1 个评论
prajith samraj
prajith samraj 2022-4-19
how to plot nonlinear differntial equation of van der pol oscilator or mlc oscillator?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by