About using and understanding pwelch in Matlab

I am using pwelch method in Matlab to calculate power spectra for some wind speed measurements. So far away I wrote the following code as an example:

t = 10800; % number of seconds in 3 hours
t = 1:t; % generate time vector
fs = 1; % sampling frequency (seconds)
A = 2; % amplitude
P = 1000; % period (seconds), the time it takes for the signal to repeat itself
f1 = 1/P; % number of cycles per second (i.e. how often the signal repeats itself every second).
y = A*sin(2*pi*f1*t); % signal

fh = figure(1);
set(fh,'color','white','Units', 'Inches', 'Position', [0,0,6,6],...
    'PaperUnits', 'Inches', 'PaperSize', [6,6]);
[pxx, f] = pwelch(y,[],[],[],fs);
loglog(f,10*(pxx),'k','linewidth',1.2);
xlabel('log10(cycles per s)');
ylabel('Spectral Density (dB Hz^{-1})');

      

I can't turn on the plot because I don't have enough reputation points.

It makes sense? I am struggling with the idea of ​​having noise on the right side of the plot. The signal that was decomposed was a sine wave without noise, where does this noise come from? Does the fact that the values ​​on the y-axis are negative mean that these frequencies are negligible? Also, what would be the best way to write the units on the y-axis if the wind speed is measured in m / s, could this be converted into something more meaningful to environmental scientists?
+3


source to share


1 answer


Your results are fine. dB

can be misleading.

The line chart will get a good overview,

Fs = 1000;                    % Sampling frequency
T = 1/Fs;                     % Sample time
L = 1000;                     % Length of signal
t = (0:L-1)*T;                % Time vector
y = sin(2 * pi * 50 * t);     % 50Hz signal

      

Approach fft

,

NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
subplot(1,2,1);
plot(f,2*abs(Y(1:NFFT/2+1))) 
xlabel('Frequency (Hz)') 
ylabel('|Y(f)|')

      

pwelch

,

subplot(1,2,2);
[pxx, freq] = pwelch(y,[],[],[],Fs);
plot(freq,10*(pxx),'k','linewidth',1.2);
xlabel('Frequency (Hz)'); 
ylabel('Spectral Density (Hz^{-1})');

      



enter image description here

As you can see, they both peak at 50Hz

.

Using loglog

for both,

enter image description here

So, "noise" has a meaning 1e-6

and exists in fft

, and can be ignored.

For your second question, I don't think the axis will change, it will be frequency

again. For Fs

you should use the sample rate of the wind speed, for example, if you have 10

speed samples in one second, yours Fs

is 10

. Higher frequencies in your graph mean more changes in wind speed, while lower frequencies represent smaller changes in speed.

+3


source







All Articles