diff --git a/index.html b/index.html index 2427d9c..de9c3b4 100644 --- a/index.html +++ b/index.html @@ -3,21 +3,30 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- +In some cases, we want to generate a time domain signal with defined Power Spectral Density. -Two methods are presented in sections 2 and 3. +Two methods are presented in sections 2 and 3.
-Finally, some notes are done on how to compute the noise level and signal level from a given Power Spectral Density in section 4. +Finally, some notes are done on how to compute the noise level and signal level from a given Power Spectral Density in section 4.
-In this section, the basics of spectral analysis is presented with the associated Matlab commands. @@ -114,11 +123,11 @@ This include:
-A typical measurement setup is shown in figure 1 where we measure a physical signal which is here a velocity \(v(t)\) using a geophone. +A typical measurement setup is shown in figure 1 where we measure a physical signal which is here a velocity \(v(t)\) using a geophone. The geophone has some dynamics that we represent with \(G_g(s)\), its output a voltage. The output of the geophone is then amplified by a voltage amplifier with a transfer function \(G_a(s)\).
@@ -132,7 +141,7 @@ To obtain the real physical quantity \(v(t)\) as measured by the sensor from the -
Figure 1: Schematic of the instrumentation used for the measurement
@@ -147,10 +156,10 @@ Let’s say, we know that the sensitivity of the geophone used is The parameters are defined below.G0 = 88; % Sensitivity [V/(m/s)] -f0 = 2; % Cut-off frequency [Hz] +G0 = 88; % Sensitivity [V/(m/s)] + f0 = 2; % Cut-off frequency [Hz] -Gg = G0*(s/2/pi/f0)/(1+s/2/pi/f0); + Gg = G0*(s/2/pi/f0)/(1+s/2/pi/f0);
Ga = 1000; +Ga = 1000;
Let’s here try to obtain the time domain signal \(v(t)\) from the measurement \(x\).
-If \({G_a(s)}^{-1} {G_g(s)}^{-1}\) is proper, we can simulate this dynamical system to go from the voltage \(x\) to the velocity \(v\) as shown in figure 2. +If \({G_a(s)}^{-1} {G_g(s)}^{-1}\) is proper, we can simulate this dynamical system to go from the voltage \(x\) to the velocity \(v\) as shown in figure 2.
@@ -180,7 +189,7 @@ If \({G_a(s)}^{-1} {G_g(s)}^{-1}\) is not proper, we add low pass filters at hig
-
Figure 2: Schematic of the instrumentation used for the measurement
@@ -191,13 +200,13 @@ If \({G_a(s)}^{-1} {G_g(s)}^{-1}\) is not proper, we add low pass filters at hig Let’s load the measured \(x\).data = load('mat/data_028.mat', 'data'); data = data.data; +data = load('mat/data_028.mat', 'data'); data = data.data; -t = data(:, 3); % Time vector [s] -x = data(:, 1)-mean(data(:, 1)); % The offset if removed (coming from the voltage amplifier) [v] + t = data(:, 3); % Time vector [s] + x = data(:, 1)-mean(data(:, 1)); % The offset if removed (coming from the voltage amplifier) [v] -dt = t(2)-t(1); % Sampling Time [s] -Fs = 1/dt; % Sampling Frequency [Hz] + dt = t(2)-t(1); % Sampling Time [s] + Fs = 1/dt; % Sampling Frequency [Hz]
lsim
command.
v = lsim(inv(Gg*Ga), x, t);
+ v = lsim(inv(Gg*Ga), x, t);
lsim
command.
And we plot the obtained velocity
-
Figure 3: Computed Velocity from the measured Voltage
@@ -221,8 +230,8 @@ And we plot the obtained velocity
From the Matlab documentation:
@@ -275,9 +284,9 @@ As explained in (Schmid 2012), it is recommen
First, define a window (preferably the hanning
one) by specifying the averaging factor na
.
nx = length(v);
-na = 8;
-win = hanning(floor(nx/na));
+ nx = length(v);
+ na = 8;
+ win = hanning(floor(nx/na));
[Sv, f] = pwelch(v, win, 0, [], Fs); +[Sv, f] = pwelch(v, win, 0, [], Fs);
-The obtained PSD is shown in figure 4. +The obtained PSD is shown in figure 4.
-
Figure 4: Power Spectral Density of the measured velocity
-The Amplitude Spectral Density (ASD) is defined as the square root of the Power Spectral Density and is shown in figure 5. +The Amplitude Spectral Density (ASD) is defined as the square root of the Power Spectral Density and is shown in figure 5.
\begin{equation} \Gamma_{vv}(f) = \sqrt{S_{vv}(f)} \quad \left[ \frac{m/s}{\sqrt{Hz}} \right] \end{equation} -
Figure 5: Power Spectral Density of the measured velocity
@@ -316,22 +325,22 @@ The Amplitude Spectral Density (ASD) is defined as the square root of the PowerInstead of computing the time domain velocity before computing the Power Spectral Density, we could have directly computed the PSD of the measured voltage \(x\) and then take into account the sensitivity of the measurement devices to have the PSD of the velocity.
-To do so, we use the fact that a signal \(u\) with a PSD \(S_{uu}\) going through a LTI system \(G_(s)\) (figure 6) will generate a signal \(y\) with a PSD: +To do so, we use the fact that a signal \(u\) with a PSD \(S_{uu}\) going through a LTI system \(G_(s)\) (figure 6) will generate a signal \(y\) with a PSD:
\begin{equation} S_{yy}(\omega) = \left|G(j\omega)\right|^2 S_{uu}(\omega) \end{equation} -
Figure 6: Schematic of the instrumentation used for the measurement
@@ -353,10 +362,10 @@ Thus, we could have computed the PSD of \(x\) and then obtain the PSD of the vel The PSD of \(x\) is computed below.nx = length(x);
-na = 8;
-win = hanning(floor(nx/na));
-[Sx, f] = pwelch(x, win, 0, [], Fs);
+ nx = length(x);
+ na = 8;
+ win = hanning(floor(nx/na));
+ [Sx, f] = pwelch(x, win, 0, [], Fs);
Svv = Sx.*squeeze(abs(freqresp(inv(Gg*Ga), f, 'Hz'))).^2; +Svv = Sx.*squeeze(abs(freqresp(inv(Gg*Ga), f, 'Hz'))).^2;
-The result is compare with the PSD computed from the \(v\) signal obtained with the lsim
command in figure 7.
+The result is compare with the PSD computed from the \(v\) signal obtained with the lsim
command in figure 7.
-Similarly to what has been done in the last section, we can consider the displacement \(d\) can be obtained from the velocity \(v\) by going through an LTI system \(1/s\) as shown in figure 8. +Similarly to what has been done in the last section, we can consider the displacement \(d\) can be obtained from the velocity \(v\) by going through an LTI system \(1/s\) as shown in figure 8.
-
Figure 8: Schematic of the instrumentation used for the measurement
@@ -428,15 +437,15 @@ Note here that the PSD (and ASD) of one variable and its derivatives/integrals a With Matlab, the PSD of the displacement can be computed from the PSD of the velocity with the following code.Sd = Sv.*(1./(2*pi*f)).^2; +Sd = Sv.*(1./(2*pi*f)).^2;
-The obtained PSD of the displacement can be seen in figure 9. +The obtained PSD of the displacement can be seen in figure 9.
-
Figure 9: PSD of the Velocity and Displacement (png, pdf)
@@ -444,14 +453,14 @@ The obtained PSD of the displacement can be seen in figureThe Cumulative Power Spectrum is the cumulative integral of the Power Spectral Density:
\begin{equation} -\label{orgf27b554} +\label{org644886e} CPS_v(f) = \int_0^f PSD_v(\nu) d\nu \quad [(m/s)^2] \end{equation} @@ -459,7 +468,7 @@ The Cumulative Power Spectrum is the cumulative integral of the Power Spectral D It is also possible to integrate from high frequency to low frequency: \begin{equation} -\label{org1c25e5d} +\label{org47d268d} CPS_v(f) = \int_f^\infty PSD_v(\nu) d\nu \quad [(m/s)^2] \end{equation} @@ -470,7 +479,7 @@ The Cumulative Power Spectrum taken at frequency \(f\) thus represent the powerThe choice of the integral direction depends on the shape of the PSD. -If the power is mostly present at low frequencies, it is preferable to use equation \eqref{org1c25e5d}. +If the power is mostly present at low frequencies, it is preferable to use equation \eqref{org47d268d}.
@@ -485,37 +494,37 @@ The Root Mean Square value of the velocity corresponds to the Cumulative Amplitu-With Matlab, the Cumulative Power Spectrum can be computed with the below formulas and the results are shown in figure 10. +With Matlab, the Cumulative Power Spectrum can be computed with the below formulas and the results are shown in figure 10.
CPS_v = cumtrapz(f, Sv); % Cumulative Power Spectrum from low to high frequencies -CPS_vv = flip(-cumtrapz(flip(f), flip(Sv))); % Cumulative Power Spectrum from high to low frequencies +CPS_v = cumtrapz(f, Sv); % Cumulative Power Spectrum from low to high frequencies + CPS_vv = flip(-cumtrapz(flip(f), flip(Sv))); % Cumulative Power Spectrum from high to low frequencies
figure; -ax1 = subplot(1, 2, 1); -hold on; -plot(f, CPS_v); -hold off; -set(gca, 'xscale', 'log'); set(gca, 'yscale', 'log'); -xlabel('Frequency [Hz]'); ylabel('Cumulative Power Spectrum [$(m/s)^2$]') +figure; + ax1 = subplot(1, 2, 1); + hold on; + plot(f, CPS_v); + hold off; + set(gca, 'xscale', 'log'); set(gca, 'yscale', 'log'); + xlabel('Frequency [Hz]'); ylabel('Cumulative Power Spectrum [$(m/s)^2$]') -ax2 = subplot(1, 2, 2); -hold on; -plot(f, CPS_vv); -hold off; -set(gca, 'xscale', 'log'); set(gca, 'yscale', 'log'); -xlabel('Frequency [Hz]'); + ax2 = subplot(1, 2, 2); + hold on; + plot(f, CPS_vv); + hold off; + set(gca, 'xscale', 'log'); set(gca, 'yscale', 'log'); + xlabel('Frequency [Hz]'); -linkaxes([ax1,ax2],'xy'); -xlim([0.1, 500]); ylim([1e-15, 1e-11]); + linkaxes([ax1,ax2],'xy'); + xlim([0.1, 500]); ylim([1e-15, 1e-11]);
Figure 10: Cumulative Power Spectrum (png, pdf)
@@ -524,22 +533,22 @@ xlim([0.1, 500]); ylim([1e-15, 1e -We load the PSD of the signal we wish to replicate.
load('./mat/dist_psd.mat', 'dist_f'); +load('./mat/dist_psd.mat', 'dist_f');
dist_f.f = dist_f.f(3:end); -dist_f.psd_gm = dist_f.psd_gm(3:end); +dist_f.f = dist_f.f(3:end); + dist_f.psd_gm = dist_f.psd_gm(3:end);
Using sisotool
or any other tool, we create a transfer function \(G\) such that its magnitude is close to the Amplitude Spectral Density \(\Gamma_x = \sqrt{S_x}\):
@@ -573,15 +582,15 @@ Using sisotool
or any other tool, we create a transfer function \(G
G_gm = 0.002*(s^2 + 3.169*s + 27.74)/(s*(s+32.73)*(s+8.829)*(s+7.983)^2); +G_gm = 0.002*(s^2 + 3.169*s + 27.74)/(s*(s+32.73)*(s+8.829)*(s+7.983)^2);
-We compare the ASD \(\Gamma_x(\omega)\) and the magnitude of the generated transfer function \(|G(j\omega)|\) in figure [[]]. +We compare the ASD \(\Gamma_x(\omega)\) and the magnitude of the generated transfer function \(|G(j\omega)|\) in figure 12.
--We know that a signal \(u\) going through a LTI system \(G\) (figure 13) will have its ASD modified according to the following equation: +We know that a signal \(u\) going through a LTI system \(G\) (figure 13) will have its ASD modified according to the following equation:
\begin{equation} \Gamma_{yy}(\omega) = \left|G(j\omega)\right| \Gamma_{uu}(\omega) \end{equation} -
Figure 13: Schematic of the instrumentation used for the measurement
@@ -614,27 +623,27 @@ Thus, if we create a random signal with an ASD equal to one at all frequency and To obtain a random signal with an ASD equal to one, we use the following code.Fs = 2*dist_f.f(end); % Sampling Frequency [Hz] -Ts = 1/Fs; % Sampling Time [s] +Fs = 2*dist_f.f(end); % Sampling Frequency [Hz] + Ts = 1/Fs; % Sampling Time [s] -t = 0:Ts:500; % Time Vector [s] -u = sqrt(Fs/2)*randn(length(t), 1); % Signal with an ASD equal to one + t = 0:Ts:500; % Time Vector [s] + u = sqrt(Fs/2)*randn(length(t), 1); % Signal with an ASD equal to one
-We then use lsim
to compute \(y\) as shown in figure 13.
+We then use lsim
to compute \(y\) as shown in figure 13.
y = lsim(G_gm, u, t); +y = lsim(G_gm, u, t);
-The obtained time domain signal is shown in figure 14. +The obtained time domain signal is shown in figure 14.
-We now compute the Power Spectral Density of the computed time domain signal \(y\).
nx = length(y);
-na = 16;
-win = hanning(floor(nx/na));
+ nx = length(y);
+ na = 16;
+ win = hanning(floor(nx/na));
-[pxx, f] = pwelch(y, win, 0, [], Fs);
+ [pxx, f] = pwelch(y, win, 0, [], Fs);
One advantage of this technique is that it can be easily integrated into simulink.
-The corresponding schematic is shown in figure 16 where the block Band-Limited White Noise
is used to generate a random signal with a PSD equal to one (parameter Noise Power
is set to 1).
+The corresponding schematic is shown in figure 16 where the block Band-Limited White Noise
is used to generate a random signal with a PSD equal to one (parameter Noise Power
is set to 1).
@@ -685,17 +694,17 @@ Then, the signal generated pass through the transfer function representing the w
-
Figure 16: Simulink Schematic
-We simulate the system shown in figure 16. +We simulate the system shown in figure 16.
out = sim('matlab/generate_signal_psd.slx'); +out = sim('matlab/generate_signal_psd.slx');
nx = length(out.u_gm.Data);
-na = 8;
-win = hanning(floor(nx/na));
+ nx = length(out.u_gm.Data);
+ na = 8;
+ win = hanning(floor(nx/na));
-[pxx, f] = pwelch(out.u_gm.Data, win, 0, [], 1e3);
+ [pxx, f] = pwelch(out.u_gm.Data, win, 0, [], 1e3);
-Finally, we compare the PSD of the generated signal with the original PSD in figure 17. +Finally, we compare the PSD of the generated signal with the original PSD in figure 17.
-The technique comes from (Preumont 1994) (section 12.11). @@ -737,14 +746,14 @@ It makes used of the Unversed Fast Fourier Transform (IFFT).
We load the PSD of the signal we wish to replicate.
load('./mat/dist_psd.mat', 'dist_f'); +load('./mat/dist_psd.mat', 'dist_f');
dist_f.f = dist_f.f(3:end); -dist_f.psd_gm = dist_f.psd_gm(3:end); +dist_f.f = dist_f.f(3:end); + dist_f.psd_gm = dist_f.psd_gm(3:end);
Figure 18: PSD of the original signal (png, pdf)
@@ -769,18 +778,18 @@ The PSD of the signal is shown on figure fig:psd_oriWe define some parameters that will be used in the algorithm.
Fs = 2*dist_f.f(end); % Sampling Frequency of data is twice the maximum frequency of the PSD vector [Hz] -N = 2*length(dist_f.f); % Number of Samples match the one of the wanted PSD -T0 = N/Fs; % Signal Duration [s] -df = 1/T0; % Frequency resolution of the DFT [Hz] - % Also equal to (dist_f.f(2)-dist_f.f(1)) +Fs = 2*dist_f.f(end); % Sampling Frequency of data is twice the maximum frequency of the PSD vector [Hz] + N = 2*length(dist_f.f); % Number of Samples match the one of the wanted PSD + T0 = N/Fs; % Signal Duration [s] + df = 1/T0; % Frequency resolution of the DFT [Hz] + % Also equal to (dist_f.f(2)-dist_f.f(1))
phi = dist_f.psd_gm; +phi = dist_f.psd_gm;
C = zeros(N/2,1); -for i = 1:N/2 - C(i) = sqrt(phi(i)*df); -end +C = zeros(N/2,1); + for i = 1:N/2 + C(i) = sqrt(phi(i)*df); + end
C
.
theta = 2*pi*rand(N/2,1); % Generate random phase [rad] +theta = 2*pi*rand(N/2,1); % Generate random phase [rad] -Cx = [0 ; C.*complex(cos(theta),sin(theta))]; -Cx = [Cx; flipud(conj(Cx(2:end)))];; + Cx = [0 ; C.*complex(cos(theta),sin(theta))]; + Cx = [Cx; flipud(conj(Cx(2:end)))];;
The time domain data is generated by an inverse FFT.
@@ -827,13 +836,13 @@ The time domain data is generated by an inverse FFT.
The ifft
Matlab does not take into account the sampling frequency, thus we need to normalize the signal.
u = N/sqrt(2)*ifft(Cx); % Normalisation of the IFFT -t = linspace(0, T0, N+1); % Time Vector [s] +u = N/sqrt(2)*ifft(Cx); % Normalisation of the IFFT + t = linspace(0, T0, N+1); % Time Vector [s]
Figure 19: Obtained signal in the time domain (png, pdf)
@@ -841,14 +850,14 @@ t = linspace(0, T0, N+1); -We duplicate the time domain signal to have a longer signal and thus a more precise PSD result.
u_rep = repmat(u, 10, 1); +u_rep = repmat(u, 10, 1);
nx = length(u_rep);
-na = 16;
-win = hanning(floor(nx/na));
+ nx = length(u_rep);
+ na = 16;
+ win = hanning(floor(nx/na));
-[pxx, f] = pwelch(u_rep, win, 0, [], Fs);
+ [pxx, f] = pwelch(u_rep, win, 0, [], Fs);
We here make use of the Power Spectral Density to estimate either the noise level or the amplitude of a deterministic signal. @@ -889,17 +898,17 @@ Everything is explained in (Schmid 2012) sect
Let’s first define the number of sample and the sampling time.
N = 10000; % Number of Sample -dt = 0.001; % Sampling Time [s] +N = 10000; % Number of Sample + dt = 0.001; % Sampling Time [s] -t = dt*(0:1:N-1)'; % Time vector [s] + t = dt*(0:1:N-1)'; % Time vector [s]
asig = 0.1; % Amplitude of the signal [V] -fsig = 10; % Frequency of the signal [Hz] +asig = 0.1; % Amplitude of the signal [V] + fsig = 10; % Frequency of the signal [Hz] -ahar = 0.5; % Amplitude of the harmonic [V] -fhar = 50; % Frequency of the harmonic [Hz] + ahar = 0.5; % Amplitude of the harmonic [V] + fhar = 50; % Frequency of the harmonic [Hz] -anoi = 1e-3; % RMS value of the noise + anoi = 1e-3; % RMS value of the noise
-The signal \(x\) is generated with the following code and is shown in figure 21. +The signal \(x\) is generated with the following code and is shown in figure 21.
x = anoi*randn(N, 1) + asig*sin((2*pi*fsig)*t) + ahar*sin((2*pi*fhar)*t); +x = anoi*randn(N, 1) + asig*sin((2*pi*fsig)*t) + ahar*sin((2*pi*fhar)*t);
Figure 21: Time Domain Signal (png, pdf)
@@ -942,18 +951,18 @@ The signal \(x\) is generated with the following code and is shown in figure
Let’s compute the PSD of the signal using the blackmanharris
window.
nx = length(x); -na = 8; -win = blackmanharris(floor(nx/na)); +nx = length(x); + na = 8; + win = blackmanharris(floor(nx/na)); -[pxx, f] = pwelch(x, win, 0, [], 1/dt); + [pxx, f] = pwelch(x, win, 0, [], 1/dt);
CG = sum(win)/(nx/na); -NG = sum(win.^2)/(nx/na); -fbin = f(2) - f(1); +CG = sum(win)/(nx/na); + NG = sum(win.^2)/(nx/na); + fbin = f(2) - f(1); -pxx_norm = pxx*(NG*fbin/CG^2); + pxx_norm = pxx*(NG*fbin/CG^2);
isig = round(fsig/fbin)+1; -ihar = round(fhar/fbin)+1; +isig = round(fsig/fbin)+1; + ihar = round(fhar/fbin)+1;
srmt = asig/sqrt(2); % Theoretical value of signal magnitude +srmt = asig/sqrt(2); % Theoretical value of signal magnitude
srms = sqrt(sum(pxx(isig-5:isig+5)*fbin)); % Signal spectrum integrated -srmsp = sqrt(pxx_norm(isig) * NG*fbin/CG^2); % Maximum read off spectrum +srms = sqrt(sum(pxx(isig-5:isig+5)*fbin)); % Signal spectrum integrated + srmsp = sqrt(pxx_norm(isig) * NG*fbin/CG^2); % Maximum read off spectrum
The noise level can also be computed using the integration method. @@ -1046,7 +1055,7 @@ The noise level can also be computed using the integration method. The theoretical RMS noise value is.
nth = anoi/sqrt(max(f)) % Theoretical value [V/sqrt(Hz)] +nth = anoi/sqrt(max(f)) % Theoretical value [V/sqrt(Hz)]
navg = sqrt(mean(pxx_norm([ihar+10:end]))) % pwelch output averaged +navg = sqrt(mean(pxx_norm([ihar+10:end]))) % pwelch output averaged
This is taken from here. @@ -1121,11 +1130,11 @@ Interestingly, the noise amplitude is uniformly distributed.
The quantization noise can take a value between \(\pm q/2\), and the probability density function is constant in this range (i.e., it’s a uniform distribution). -Since the integral of the probability density function is equal to one, its value will be \(1/q\) for \(-q/2 < e < q/2\) (Fig. 22). +Since the integral of the probability density function is equal to one, its value will be \(1/q\) for \(-q/2 < e < q/2\) (Fig. 22).
-
Figure 22: Probability density function \(p(e)\) of the ADC error \(e\)
@@ -1183,7 +1192,7 @@ Finally:Created: 2020-11-12 jeu. 10:22
+Created: 2021-04-26 lun. 17:04