File:Bartlett's method.svg

Summary

Description
English: Linear spectrum calculated by Bartlett's method
Date
Source Own work based on: code from Bartl.png by Kirlf (talk · contribs)
Author Ixfd64
SVG development
InfoField
 The source code of this SVG is invalid due to an error.
 This W3C-invalid vector image was created with an unknown SVG tool.
Category:Invalid SVG created with Other tools#1000Bartlett's%20method.svg

Python source code

import numpy as np
from scipy import signal
import matplotlib.pyplot as plt

Nsub = 100  # number of subsequences

w_1 = 30  # frequency of 1st component of  signal (Hz)
w_2 = 40  # frequency of 2nd component of signal (Hz)

a = 0.7  # magnitude of 1st component of signal
b = 0.4  # magnitude of  2nd component of signal

t = np.array([i for i in range(1, 301)]) / 1000  # time samples (s)
fs = 1 / (t[1] - t[0])  # sampling frequency (Hz)

x = a * np.cos(2 * np.pi * w_1 * t) + b * np.sin(2 * np.pi * w_2 * t)  # considered signal

y_mat = np.dot(np.ones((Nsub, 1)), x.reshape((1, len(x))))  # assume subsequences are identical

f = []
Pxx = np.empty((Nsub, int((len(x) / 2) + 1)))
for i in range(np.shape(y_mat)[0]):
    y_mat[i, :] = y_mat[i, :]
    f, Pxx[i, :] = signal.periodogram(y_mat[i, :], fs=fs, scaling='spectrum')
Pxx_bart = np.mean(Pxx, axis=0)

plt.subplots(1, 1, figsize=(6, 4), dpi=250)
plt.stem(f[1:20], Pxx_bart[1:20], '-')
plt.ylabel('Spectrum')
plt.xlabel('Frequencies (Hz)')
plt.title('Bartlett\'s method')
plt.grid(True)
plt.savefig("Bartett's method.svg", format="svg")

Licensing

Ixfd64, the copyright holder of this work, hereby publishes it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
Attribution:
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Bartlett's%20method.svgCategory:Self-published work
Category:Digital signal processing
Category:CC-BY-SA-4.0 Category:Digital signal processing Category:Invalid SVG created with Other tools Category:Self-published work