Posts

Why Do We Divide by n-1 for Sample Variance? (The Intuitive & Mathematical Guide)

Image
Why Do We Divide by (n - 1) in Sample Variance? Key point: Sample variance uses (n - 1) to remove bias caused by estimating the mean. Sample variance is defined as: s 2 = (1 / (n - 1)) ∑ i=1 n (x i - x̄) 2 The use of (n - 1) ensures that the estimator is unbiased. 1. Problem Definition Let a population have mean μ and variance σ 2 . We draw an i.i.d. sample: x 1 , ..., x n Sample mean: x̄ = (1 / n) ∑ x i 2. Naive Estimator and Bias Naive estimator: (1 / n) ∑(x i - x̄) 2 This estimator is biased downward: E[~s 2 ] < σ 2 3. Sample Mean Reduces Spread (Visualization) The sample mean minimizes squared deviations, which reduces observed spread. Figure 1. Sample points with true mean and sample mean. The sample mean shifts toward the data, reducing apparent variance. 4. Mathematical Derivation We now derive why dividing by n - 1 makes the sample variance unbiased. Assume that x 1 , x 2 , ..., x n are i.i.d. ...

Averaging and Moving Average Filters

Image
  1. Why Averaging Matters In engineering systems, especially in robotics, sensor data is often noisy. A simple and effective way to reduce noise is to compute the average of measurements. However, how we compute the average matters, especially when data keeps growing. 2. Batch Expression The average of k data points is defined as: x̄ k = (x 1 + x 2 + ··· + x k ) / k This is called a batch expression , because all data must be collected before computing the result. 3. Limitation of the Batch Method The batch method has two major drawbacks: Every time new data arrives, we must recompute the entire sum. All previous data must be stored in memory. This becomes inefficient when the number of data points is large. 4. Recursive Averaging Filter Instead of recomputing everything, we can reuse the previous average. Starting from the batch expression: x̄ k = (x 1 + x 2 + ··· + x k ) / k Multiply both sides by k : k x̄ k = x 1 + x 2 + ··· + ...

Modal Analysis Part2. Windows

Image
In this article, we'll briefly explore the significance of windows in signal processing and provide a simple Python code example to create a Hanning window. Understanding Windows in Signal Processing In the realm of signal processing, windows play a pivotal role in preparing data for analysis in the frequency domain. A windowing function modifies a time-domain signal's properties before transforming it into the frequency domain through techniques like the Fast Fourier Transform (FFT).  What are Windows in Signal Processing? Windows, in signal processing, are mathematical functions applied to a dataset to mitigate issues like spectral leakage and artifacts during frequency analysis. These issues often arise due to abrupt signal endings, causing unwanted effects in the frequency domain. Windows act as a weighting function, tapering the signal's edges to minimize these problems. 1. Rectangular Window The Rectangular window, sometimes referred to as the boxcar or Dirichlet wind...

Modal Analysis Part1. Time Domain and Frequency Domain

Image
  Today, I'd like to delve into the identification of modes within mechanical systems through vibration testing. This discussion will unfold across approximately 10 posts, meticulously clarifying crucial aspects. The aim is to assist aspiring mechanical, electrical, and civil engineering students navigating the realm of signal processing. Furthermore, it aims to bolster the mechanical foundation of test engineers. My dataset stems from a turning test, yet the principles remain consistent across various domains—be it machining, robotics, vehicular dynamics, wind turbines, or structural elements like buildings or bridges. While the fundamentals of signal processing persist, nuances emerge in the frequency domain's mode localization and the presence of external forces. Most modal analysis software simplifies mode identification with a few clicks. However, I'll illuminate how to pinpoint modes using Python. Admittedly, the free software I've utilized might not match the pre...

Have you heard of MATLAB?

Image
 Have you heard of MATLAB? It's like a special computer language that helps engineers and scientists create and understand amazing things that shape our world. Imagine it as a super tool that helps us figure out complex problems in a simple and organized way! In schools, students can easily use MATLAB because many schools have it available. It's like having a powerful tool that can do all sorts of cool math and science stuff. But once we graduate, it can be a bit tricky to keep using it because it can be expensive. Even big companies sometimes find it too costly! You might wonder, why do students and experts in science and engineering love using MATLAB so much? Well, it's like having a really smart friend who can help us understand and show our math and science ideas in a clear and visual way. Imagine it's your helpful buddy for making sense of all those tricky calculations and graphs. Example of Graph by MATLAB And the best part? It keeps getting better! The clever fol...

Aliasing and Nyquist-Shannon sampling theorem

Image
 Signal processing is an integral part of various engineering disciplines, including mechanical, electronic, electrical, mechatronics, chemical, and even civil engineering. Taking my own field, mechanical engineering, as an example, we find ourselves immersed in a world driven by automation. Our focus now extends to even more advanced levels of automation, incorporating technologies like machine learning and self-driving vehicles. Achieving these goals demands a diverse range of technologies. However, it's crucial that future advancements stem not just from the allure of cutting-edge technology, but from a solid foundation of established and reliable innovations. Currently, much research centers around enhancing the sensory perception of robots, involving new sensors, LiDAR, and cameras, as well as fortifying the computational "brain" with advanced semiconductors or GPUs. Amidst these advancements, it's essential to acknowledge the existing technologies such as sensor...

Are you a programming novice? Begin by launching Google Colab!

Image
I frequently encounter a common query from my close contacts: "What's the best way to set up my computer for coding?" While there are plenty of reliable resources available online, they often seek advice from me, given my involvement in a similar field. Many individuals tend to believe that a cutting-edge computer with a powerful GPU is the key. Typically, those posing this question are beginners. Hence, I advocate a different approach: I strongly suggest initiating code development on platforms like Colab or Kaggle, and then investing in a new computer that aligns with the specific requirements of the project. In my blog, I not only recreate code but also construct simplified versions within Python notebooks. I do this to share with a broader audience, enabling them to effortlessly replicate it in platforms like Colab or Kaggle Notebook by means of copy-paste operations. I've previously introduced Python Notebook code, and I intend to continue doing so, except for in...