Calculate PSD and plot smooth curve
113 次查看(过去 30 天)
显示 更早的评论
Hey all,
I've new to matlab, and have been wrestling with processing and plotting PSD data. I have raw data (time and magnitude in g), as well as already processed data by different software (in freq and g^2/Hz). I'd like to compare PSDs from this software versus whatever I can cook up in matlab.
I need to take the raw data (in csv files, two columns, time and amplitude of g) and run a PSD on it. I'd then like to plot a smoothed version of the PSD to make a profile curve that represents most of the data (i don't want to plot the results of the PSD, too much info).
I've been trying to use different functions in matlab some of which seem obsolete or deprecated, so any help is appreciated, thanks!
JT
0 个评论
采纳的回答
Wayne King
2011-11-30
Hi JT, you can use spectrum.periodogram and spectrum.welch
Fs = 1000;
t = 0:1/Fs:1-1/Fs;
x = cos(2*pi*100*t)+randn(size(t));
plot(psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x)));
figure;
plot(psd(spectrum.welch,x,'Fs',Fs,'NFFT',length(x)));
0 个评论
更多回答(4 个)
Wayne King
2011-11-30
Hi, yes, you can just return the output from psd() and plot it as you wish.
psdest = psd(spectrum.periodogram,x,'Fs',Fs,'NFFT',length(x));
plot(psdest.Frequencies, psdest.Data); grid on;
ylabel('g^2/Hz');
xlabel('Hz');
0 个评论
Wayne King
2011-12-1
Hi, you do not want to input test in this example, because test is a matrix. psd() expects a vector input, a 1-D signal. What you want to input is either x or y, whichever is the meaningful time series, also, for 'NFFT', you do not want to input a vector, like t =0:length(x). NFFT should just be a number, the number of FFT bins, use length(x), or length(y).
Finally, make sure that fs is your sampling frequency
'Fs',10000 or 'Fs',1 whatever the sampling frequency of your data is.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parametric Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!