필터 지우기
필터 지우기

I need to calculate power spectral density of a signal in MATLAB.

조회 수: 8 (최근 30일)
what I have to do is to calculate the noise in a signal and see how it depends on the frequency spectrum. I am trying to calculate PSD of a signal but everytime, I get an error saying "vectors must be the same lengths". I am not able to find a solution.
Here is command which I'm using. please let me know if there is some problem with the command.
I imported the excel file as vectors.
x=time; %time vector in excel file
y=current; %current vector in excel file
plot(x,y); % plot current-time graph
xlabel('time(s)');
ylabel('current(A)');
Fs=50; %sampling frequency
T=1/Fs; %sampling time
L=length(y); %length of the signal
L1= x/T;
t=(0:L-1)*T; time vector
%%%calculate the mean current
Iavg=mean(L);
%calculate the FFT
NFFT=2^nextpow2(L); %next power of 2 from length y
% calculate and plot PSD of conditioning mode
Nc=abs(fft((L-Iavg),NFFT)).^2./NFFT;% Nc is power spectral density
fc=Fs/2*linspace(0,1,NFFT/2+1);%frequency
plot(fc,Nc);

채택된 답변

Wayne King
Wayne King 2012년 4월 19일
You are calculating your frequency vector for a one-sided PSD estimate, but then you try to plot the PSD estimate for the entire period (two-sided) against that.
Also, you do not want to find the PSD of L, that is just a scalar which is the length of the signal, y. So fft((L-Iavg))is definitely not what you want, because that is just 0!!!
Nc=abs(fft((y-mean(y)),NFFT)).^2./NFFT;
Nc = Nc(1:513);
Nc(2:end-1) = 2*Nc(2:end-1);
fc=Fs/2*linspace(0,1,NFFT/2+1);%frequency
plot(fc,Nc)
Also, you probably want to plot it in dB
plot(fc,10*log10(Nc))
  댓글 수: 1
gaurav Nanda
gaurav Nanda 2012년 4월 19일
Thanks a lot for the answer. It still doesn't seem to work and it says "index exceeds matrix dimensions".
Actually this is the first time I am using Matlab and I have been to told to characterize the noise of my signal to find out low frequency noise 1/f, thermal noise and how do they depend on the concentration of Analyte, types of electrode used for measurement etc.
Also, I did not understand why you have used "Nc=Nc(1:513)"
Is there any way to perform curve fitting of this PSD?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

gaurav Nanda
gaurav Nanda 2012년 4월 19일
Thanks a lot for the answer. It still doesn't seem to work and it says "index exceeds matrix dimensions".
Actually this is the first time I am using Matlab and I have been to told to characterize the noise of my signal to find out low frequency noise 1/f, thermal noise and how do they depend on the concentration of Analyte, types of electrode used for measurement etc.
Also, I did not understand why you have used "Nc=Nc(1:513)" Is there any way to perform curve fitting of this PSD?

Wayne King
Wayne King 2012년 4월 19일
because you computed the DFT of a vector to length 1024, only 513 points are "positive" frequencies.
Why not just use spectrum.periodogram if you have the Signal Processing Toolbox?
Fs = 1e3;
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
plot(psd(spectrum.periodogram,x,'Fs',1000,'NFFT',length(x)));

카테고리

Help CenterFile Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by