Calculate PSD and plot smooth curve
조회 수: 132 (최근 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!