Python NO CODING 1746092725
Python NO CODING 1746092725
Vibration Analysts
Without Coding
Experience
A Step-by-Step Guide Using Google Colab and Gemini
We will use Google Colaboratory (Colab), a free online tool, and an AI assistant like
Gemini.
● Colab provides the environment to run Python code without installing anything.
● Gemini (or a similar AI) will act as your personal coder. You will describe the
analysis task you want to perform in plain English (we call this a "prompt"), and
the AI will generate the necessary Python code for you.
Your job shifts from writing code to clearly describing your analysis needs to the AI.
What You'll Achieve:
By the end of this guide, you will be able to use Google Colab and AI prompts to:
1. Load your vibration data (from uploads or Google Drive).
2. Visualize time waveforms.
3. Calculate standard time-domain metrics (RMS, Peak, Crest Factor).
4. Perform Fast Fourier Transforms (FFT) to analyze frequency content.
5. Plot frequency spectra and identify key peaks.
6. Apply basic digital filters to your data.
Let's begin!
Think of Google Colab and an AI assistant like Gemini as your new digital workshop for
vibration analysis.
Steps:
1. Open your Web Browser: Chrome is recommended, but others work too.
2. Go to Google Colab: Navigate to https://colab.research.google.com.
3. Sign In: You'll likely be prompted to sign in with your Google Account. If you don't
have one, you'll need to create one (it's free).
4. Welcome Screen: You might see a welcome pop-up showing recent files,
examples, etc. You can close this for now.
5. Create a New Notebook: Go to the File menu and select New notebook.
You now have a blank Colab notebook! Let's take a quick tour:
● File Name: At the top left, click UntitledX.ipynb to rename your notebook (e.g.,
"Motor_Bearing_Analysis.ipynb"). Notebooks are automatically saved to your
Google Drive in a folder called 'Colab Notebooks'.
● Menu Bar: Contains standard options like File, Edit, View, Insert, Runtime, Tools,
Help. We'll use File (New, Save) and Runtime (Run cells) most often.
● Toolbar: Quick access buttons below the menu bar. The most important are:
○ + Code: Adds a new Code cell (where you'll paste AI-generated Python code).
○ + Text: Adds a new Text cell (where you can write notes, headings,
explanations using simple formatting called Markdown).
● Main Work Area: This is where your Code and Text cells live. You'll start with one
▶️
empty Code cell.
● Cell Execution: Each Code cell has a (Run) button on its left. Clicking this
executes the code inside that specific cell. You can also press Shift + Enter to run
📁
the selected cell and move to the next one.
● File Browser (Left Sidebar): Click the folder icon ( ) on the far left to open the
file browser. This is where you can upload files or connect to Google Drive.
Code Cells vs. Text Cells
● Code Cells: Have a greyish background and a ▶️ (Run) button. This is where you
put Python code. When you run it, the output (text, tables, plots) appears directly
below the cell.
● Text Cells: Have a white background. Double-click to edit. You can use simple
formatting (like # Heading 1, ## Heading 2, *italic*, **bold**, - bullet points).
These are for documentation, notes, and structuring your analysis.
Try it:
▶️
1. In the first Code cell, type print("Hello Vibration World!").
2. Click the button next to the cell (or press Shift + Enter).
3. You should see the text Hello Vibration World! printed below the cell.
Congratulations, you've run your first piece of Python code!
4. Click + Text from the toolbar. Type # My Analysis Notes in the new cell. Click
outside the cell (or press Shift + Enter) to see it formatted as a heading.
Now that you're familiar with the basic Colab environment, let's prepare your data.
Common Formats:
For basic time-series vibration analysis, your data file should ideally contain at least
two columns:
1. Time: A column representing the time elapsed for each measurement, usually in
seconds.
2. Amplitude: A column (or multiple columns for multi-axis sensors) representing
the vibration measurement (e.g., in g's, mm/s, mils).
(Example CSV Data Snippet - motor_data_bearing1.csv)
In this example:
● The first row is the header, defining column names.
● Each subsequent row is a data point.
● Values are separated by commas.
● We might be interested in "Timestamp", "Accel_X (g)", and "Accel_Y (g)".
The Sample Rate (or Sampling Frequency, Fs) is how many data points are recorded
per second (measured in Hertz, Hz). This is essential for accurate Frequency Domain
(FFT) analysis.
● How to find it? Check the documentation for your data acquisition system, the
settings used during recording, or sometimes the file metadata.
● If you don't know Fs, your frequency analysis will be meaningless!
● You can sometimes calculate it if you have accurate time stamps: Fs=1/(Time
difference between consecutive samples). For the example above, the time
difference is 0.001 s, so Fs=1/0.001=1000 Hz (or 1 kHz).
Make sure your data file is ready and you know its sample rate. In the next sections,
we'll bring this file into Colab.
This is the quickest way to get a single file into Colab for immediate analysis, but the
data disappears when your Colab session ends (usually after a period of inactivity or if
you close the browser tab for too long).
Steps:
1. Open File Browser: In your Colab notebook, click the folder icon ( 📁) in the left
sidebar.
2. Click Upload: Click the "Upload to session storage" button (looks like a page with
an upward arrow).
3. Select File: Your computer's file dialog will open. Navigate to and select your
vibration data file (e.g., motor_data_bearing1.csv). Click "Open" or "Upload".
4. Warning: You might see a warning that uploaded files will be deleted when the
runtime is recycled. Click "OK".
5. Verify: Your file should now appear in the file browser list in the left sidebar.
Pros:
● Very simple and fast for single files.
● No setup required beyond clicking.
Cons:
● Data is temporary: Files are lost when the Colab session ends. Not suitable for
long-term projects or if you need to close and reopen the notebook later.
● Can be slow for very large files.
File Path: When uploaded this way, the file usually resides directly in the root working
directory. Its path will simply be its name, e.g., 'motor_data_bearing1.csv'.
This is the recommended method for most projects. It connects your Colab notebook
directly to your Google Drive, allowing you to access files stored there. The data
persists between sessions.
Steps:
1. Add a Code Cell: If you don't have one, click + Code.
2. Enter Mount Code: Type or paste the following standard code snippet into the
cell:
from google.colab import drive
drive.mount('/content/drive')
3. Run the Cell: Click the▶️ button or press Shift + Enter.
4. Authorize Access:
○ You'll see output with a URL (like
https://accounts.google.com/o/oauth2/auth?...). Click this link.
○ A new browser tab will open asking you to choose the Google Account whose
Drive you want to connect. Select the correct account.
○ You'll be asked to grant permission for "Google Drive for desktop" (or similar)
to access your Google Account. Review the permissions and click "Allow" or
"Continue".
○ You'll be given an authorization code. Copy this code.
5. Enter Code in Colab: Go back to your Colab notebook tab. Paste the copied
authorization code into the input box that appeared below the code cell and
press Enter.
📁
6. Confirmation: You should see a message like Mounted at /content/drive.
7. Browse Drive: Now, in the left sidebar's file browser ( ), you should see a drive
folder. Expand it, then expand MyDrive. This is the root of your Google Drive. You
can navigate through your folders here to find your data file.
Finding Your File Path:
● Navigate through the drive/MyDrive/ folders in the file browser until you find your
data file (e.g., inside a folder named VibrationData).
● Right-click on the file (e.g., motor_data_bearing1.csv).
● Select Copy path.
● The path will look something like
/content/drive/MyDrive/VibrationData/motor_data_bearing1.csv. This is the path
you'll need for loading the data.
Pros:
● Data persists between sessions.
● Good for larger files and organized projects.
● Access any file in your Google Drive.
Cons:
● Requires one-time authorization per session (though often quicker after the first
time).
● Slightly more setup than direct upload.
Now that your data file is accessible (either uploaded or in Drive), let's tell the AI
assistant (like Gemini) to load it into a usable format. In Python, data is often loaded
into a structure called a DataFrame, which is like a smart spreadsheet table. The most
common library for this is pandas.
Steps:
1. Formulate Your Prompt: Think about what information the AI needs:
○ What library to use (pandas).
○ What function to use (read_csv).
○ The exact path to your file (e.g., 'motor_data_bearing1.csv' if uploaded, or
'/content/drive/MyDrive/VibrationData/motor_data_bearing1.csv' if from Drive).
○ The name you want to give the DataFrame (e.g., df is common).
○ Any special conditions (e.g., does the file have a header row?).
○ What you want to see as output (e.g., the first few rows).
2. Example Prompt (using Drive path):
Prompt for AI:
Using the pandas library, load the CSV file located at
'/content/drive/MyDrive/VibrationData/motor_data_bearing1.csv' into a pandas
DataFrame called `df`.
Assume the first row of the CSV is the header.
After loading, display the first 5 rows of the DataFrame `df`.
Also, import the pandas library first.
3. Get Code from AI: Use your chosen AI interface (Gemini web, integrated tool)
with the prompt above. The AI should generate Python code.
4. Example AI-Generated Code (Conceptual):
# Import the pandas library
import pandas as pd
# Define the file path (replace with your actual path)
file_path = '/content/drive/MyDrive/VibrationData/motor_data_bearing1.csv'
# Or if uploaded directly: file_path = 'motor_data_bearing1.csv'
# Load the CSV file into a DataFrame
# Assumes the first row is the header (this is the default for read_csv)
df = pd.read_csv(file_path)
# Display the first 5 rows
print("First 5 rows of the DataFrame:")
print(df.head())
Self-Correction Note: The AI might generate df.head() directly without print(),
which also works in Colab to display the output nicely formatted.
5. Paste and Run in Colab:
○ Copy the code generated by the AI.
○ Go to your Colab notebook.
○ Click + Code to add a new cell.
○ Paste the code into the cell.
○ Crucially, double-check the file_path variable in the code and make sure
▶️
it exactly matches the path to your file.
○ Run the cell ( or Shift + Enter).
6. Check the Output: Below the cell, you should see the first 5 rows of your data
printed in a table format. If you see an error (like FileNotFoundError),
double-check the file path you provided in the code.
You have successfully loaded your vibration data into Colab using an AI prompt!
Now that the data is in the DataFrame df, let's ask the AI to help us understand its
structure and basic properties.
Goal: Get information about columns, data types, and summary statistics.
Key Python Library: pandas (already imported, functions are called on the
DataFrame df)
○ Expected AI Code:
print("DataFrame Info:")
df.info()
○ Expected AI Code:
print("\nDescriptive Statistics:")
print(df.describe())
○ Expected Output: A table showing these statistics for each numeric column.
This gives a quick overview of the range and central tendency of your
measurements (e.g., average acceleration, max RPM).
3. Show Number of Rows and Columns:
○ Prompt:
Show the total number of rows and columns in the DataFrame `df`.
○ Expected AI Code:
print(f"\nDataFrame shape (rows, columns): {df.shape}")
The most fundamental vibration plot is the time waveform. Let's ask the AI to plot
amplitude against time.
Key Python Libraries: matplotlib.pyplot (for plotting), pandas (to access data
columns)
Steps:
1. Identify Columns: From the previous step (df.info() or df.head()), note the exact
names of your time column (e.g., 'Timestamp') and the amplitude column you
want to plot (e.g., 'Accel_X (g)'). Column names are case-sensitive!
2. Formulate Prompt:
Prompt for AI:
Using the matplotlib.pyplot library (import it as plt), create a line plot using data
from the DataFrame `df`.
Plot the column named 'Accel_X (g)' on the y-axis against the column named
'Timestamp' on the x-axis.
Add the title 'Vibration Time Waveform (X-Axis)' to the plot.
Label the x-axis 'Time (s)'.
Label the y-axis 'Amplitude (g)'.
Display the plot.
Make sure to import matplotlib.pyplot as plt first.
3. Get Code from AI: The AI should generate code using matplotlib.
4. Example AI-Generated Code (Conceptual):
# Import the plotting library
import matplotlib.pyplot as plt
# Create the plot
plt.figure(figsize=(12, 4)) # Optional: Adjust figure size for better viewing
plt.plot(df['Timestamp'], df['Accel_X (g)'])
# Add title and labels
plt.title('Vibration Time Waveform (X-Axis)')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude (g)')
# Add grid for easier reading (optional)
plt.grid(True)
# Display the plot
plt.show()
5. Paste and Run in Colab: Paste the code into a new Code cell and run it.
6. Interpret the Plot: Below the cell, you should see the time waveform graph. Look
for:
○ Overall amplitude levels.
○ Any obvious impacts or transient events.
○ Periodic patterns.
○ The general shape of the vibration.
Refining Your Plots
The default plot might be okay, but often you'll want to customize it. You can ask the AI
to make changes.
Key Python Libraries: numpy (for numerical calculations), pandas (to access data)
Concepts:
● Peak: The maximum absolute value in the signal (max positive or max negative
magnitude).
● Peak-to-Peak (Pk-Pk): The difference between the maximum positive value and
the minimum negative value.
● RMS (Root Mean Square): A measure of the overall energy or intensity of the
signal. Calculated as the square root of the mean of the squared signal values.
● Crest Factor: The ratio of the Peak value to the RMS value. Indicates how "peaky"
the signal is (high crest factor suggests impacts).
Steps:
1. Identify Amplitude Column: Note the exact name of the amplitude column you
want to analyze (e.g., 'Accel_X (g)').
2. Formulate Prompt:
Prompt for AI:
Using the numpy library (import it as np), calculate the following time-domain
metrics for the data in the 'Accel_X (g)' column of the DataFrame `df`:
1. Maximum Peak value (absolute maximum)
2. Peak-to-Peak value (max value - min value)
3. Root Mean Square (RMS) value
4. Crest Factor (Peak / RMS)
Print each calculated metric with a descriptive label and format the numbers to 4
decimal places. Make sure to import numpy as np first.
5. Paste and Run in Colab: Paste into a new Code cell and run.
6. Interpret the Output: Below the cell, you'll see the calculated values. Compare
these to expected levels or historical trends for your equipment. A high Crest
Factor (> 3-5 is often a rule of thumb, but depends heavily on the machine) can
indicate impacting or bearing faults.
(Page 13: Handling Multiple Channels)
Your data likely has multiple vibration axes (e.g., X, Y, Z). The AI can handle this easily.
Example Prompts:
1. Plotting Multiple Channels (Overlay):
Prompt: Using matplotlib, plot both 'Accel_X (g)' and 'Accel_Y (g)' columns from
DataFrame `df` against the 'Timestamp' column on the SAME axes. Add a legend
to identify the lines. Include title and axis labels. Make the figure size (14, 5).
(AI should generate code with two plt.plot() calls and plt.legend())
2. Plotting Multiple Channels (Subplots):
Prompt: Using matplotlib, create two subplots stacked vertically.
In the top subplot, plot 'Accel_X (g)' vs 'Timestamp' from DataFrame `df`. Title it
'X-Axis Vibration'.
In the bottom subplot, plot 'Accel_Y (g)' vs 'Timestamp' from DataFrame `df`. Title
it 'Y-Axis Vibration'.
Add appropriate x and y labels to both. Share the x-axis. Make the overall figure
size (12, 8).
(AI should use plt.subplot() or plt.subplots())
3. Calculating Metrics for Multiple Channels: You can ask for metrics for each
channel individually, or ask the AI to loop through them.
Prompt: For EACH of the columns 'Accel_X (g)' and 'Accel_Y (g)' in DataFrame
`df`, calculate and print the RMS and Peak values. Label the output clearly for
each axis. Use numpy. Format numbers to 4 decimal places.
(AI might generate separate calculations or use a loop)
Process: As before, use the prompts, get the code, paste, run, and interpret. This
allows you to compare vibration levels and characteristics across different sensor
axes.
Part 4: Frequency
Domain Analysis
(FFT) with AI
Introduction to FFT
The time waveform shows when vibration occurs, but the Fast Fourier Transform
(FFT) shows what frequencies are present in the signal. This is crucial for diagnosing
specific machine faults, as different components (bearings, gears, shafts) generate
vibration at characteristic frequencies.
Key Concepts:
● FFT: An efficient algorithm to compute the Discrete Fourier Transform (DFT). It
decomposes a time signal into its constituent sine wave frequencies.
● Frequency Spectrum: The output of the FFT, typically plotted as Amplitude vs.
Frequency. Peaks in the spectrum indicate dominant frequencies in the original
signal.
● Sample Rate (Fs): How many data points per second (Hz). Absolutely critical
for correct frequency scaling in the FFT.
● Number of Samples (N): The total number of data points in the time block being
analyzed. Affects frequency resolution.
● Frequency Resolution (Δf): The spacing between frequency lines in the FFT
spectrum. Δf=Fs/N. A smaller Δf (better resolution) requires a longer time block
(larger N).
● Nyquist Frequency (Fnyquist): The maximum frequency that can be reliably
detected by the FFT. Fnyquist=Fs/2. Any frequencies in the signal above this will
be aliased (appear incorrectly at lower frequencies).
Goal: Transform the time-domain signal into the frequency domain and plot the
spectrum.
Key Python Libraries: numpy (for FFT calculation), matplotlib.pyplot (for plotting)
Steps:
1. Define Parameters: You MUST know your sample rate (Fs). Let's assume
Fs=1000 Hz for our example data (based on the 0.001s time step).
2. Identify Signal Column: Choose the amplitude column (e.g., 'Accel_X (g)').
3. Formulate Prompt:
Prompt for AI:
1. Extract the data from the 'Accel_X (g)' column of DataFrame `df` into a numpy
array called `signal`.
2. Get the total number of samples in `signal` and store it in a variable `N`.
3. Assume the sample rate is 1000 Hz and store it in a variable `Fs`.
4. Using numpy's FFT function (`np.fft.fft`), calculate the Fast Fourier Transform of
the `signal`. Store the complex result in a variable called `fft_raw`.
5. Make sure to import numpy as np first.
Print a message confirming the calculation is done, showing N and Fs.
6. Paste and Run in Colab: Paste, ensure Fs is correct for your data, and run.
7. Output: You'll see the confirmation message. The fft_raw variable now holds the
complex FFT result, which isn't directly interpretable yet.
Calculating Frequency Bins and Magnitude
The raw FFT output contains complex numbers and includes negative frequencies (a
mathematical artifact). We need to process it to get a usable spectrum: frequency
values (x-axis) and corresponding magnitudes (y-axis), usually only for positive
frequencies up to the Nyquist frequency.
Goal: Calculate the frequency axis and the amplitude spectrum magnitude.
Steps:
1. Formulate Prompt: We need the results from the previous step (fft_raw, N, Fs).
Prompt for AI:
Using the results from the previous FFT calculation (`fft_raw`, `N`, `Fs`):
1. Calculate the corresponding frequency bins using `np.fft.fftfreq`. Store this in
`freq_bins`.
2. Calculate the single-sided amplitude spectrum magnitude. This involves:
a. Taking the absolute value of `fft_raw`.
b. Normalizing by the number of samples `N`.
c. Multiplying by 2 (to account for discarding negative frequencies).
d. Store the result in `magnitude`.
3. Keep only the positive frequency components: Find the index corresponding to
the Nyquist frequency (Fs/2). Keep only the `freq_bins` and `magnitude` values
up to this index. Store these positive-frequency results in `freq` and
`magnitude_positive`.
Print the number of points in the final `freq` and `magnitude_positive` arrays.
4. Paste and Run in Colab: Paste, adjust plt.xlim if desired, and run.
5. Interpret the Plot: This is the core diagnostic plot! Look for peaks:
○ Identify Frequencies: Note the frequency (x-axis value) of significant peaks.
○ Compare to Fault Frequencies: Relate these peak frequencies to known
fault frequencies for your equipment (e.g., running speed, bearing defect
frequencies, gear mesh frequencies, blade pass frequencies).
○ Amplitude: The height of the peak (y-axis value) indicates the severity of
vibration at that frequency. Track changes over time.
Prompting for Peak Identification
Manually reading peaks from the plot is okay, but we can ask the AI to find the most
significant ones automatically.
Goal: Identify the frequencies and amplitudes of the highest peaks in the spectrum.
Steps:
1. Formulate Prompt: We need freq and magnitude_positive. We also need to
decide how many peaks to find or set criteria (e.g., minimum height).
Prompt for AI:
Using the `scipy.signal.find_peaks` function:
1. Find the indices of peaks in the `magnitude_positive` array. You might need to
specify a minimum height threshold (e.g., only find peaks higher than 0.1 g) or a
minimum distance between peaks to avoid finding multiple points on the same
broad peak. Let's start by finding peaks with a minimum height of 0.05.
2. Get the frequencies and magnitudes corresponding to these peak indices from
the `freq` and `magnitude_positive` arrays.
3. Store the peak frequencies and magnitudes.
4. Print a table or list showing the top 10 highest peaks found, sorted by
magnitude in descending order (highest first). Display both frequency (Hz) and
magnitude (g), formatted to 2 decimal places.
Make sure to import `find_peaks` from `scipy.signal` and `numpy as np`.
4. Paste and Run in Colab: Paste, potentially adjust min_height or min_distance
based on your spectrum's appearance, and run.
5. Interpret the Output: You get a clean list of the most dominant frequencies and
their amplitudes, making it much easier to focus your diagnostic efforts.
Part 5: Basic
Filtering
Why Filter?
Sometimes, raw vibration signals contain noise or components that aren't relevant to
your specific analysis. Digital filters allow you to selectively remove or isolate certain
frequency ranges.
Common Goals:
● Noise Reduction: Remove high-frequency noise unrelated to machine operation
(using a Low-Pass filter).
● Isolate Low Frequencies: Focus on running speed and its harmonics, removing
high frequencies (using a Low-Pass filter).
● Isolate High Frequencies: Focus on bearing or gear mesh frequencies, removing
low-frequency components like unbalance (using a High-Pass filter).
● Focus on a Specific Band: Isolate frequencies within a known range, like a
specific bearing defect frequency band (using a Band-Pass filter).
Types of Filters (Simplified):
● Low-Pass: Allows frequencies below a cutoff frequency (fc) to pass, attenuates
frequencies above fc.
● High-Pass: Allows frequencies above a cutoff frequency (fc) to pass, attenuates
frequencies below fc.
● Band-Pass: Allows frequencies between two cutoff frequencies (flow, fhigh) to
pass, attenuates frequencies outside this band.
Key Python Library: scipy.signal (contains functions for filter design and application)
Let's ask the AI to design and apply a common type of filter, the Butterworth filter.
Steps:
1. Define Filter Parameters:
○ Filter Type: e.g., 'lowpass'
○ Cutoff Frequency (fc): The frequency where the filter starts working (e.g., 100
Hz).
○ Filter Order: Controls how sharply the filter cuts off (e.g., 4th order is
common). Higher order = sharper cutoff, but can introduce phase distortion.
○ Sample Rate (Fs): Still essential! (e.g., 1000 Hz).
2. Identify Signal: We need the original time-domain signal array (e.g., signal
created earlier from df['Accel_X (g)']).
3. Formulate Prompt (Low-Pass Example):
Prompt for AI:
Using the `scipy.signal` library:
1. Design a 4th-order Butterworth digital filter.
2. Make it a 'lowpass' filter with a cutoff frequency of 100 Hz.
3. Use the sample rate `Fs` (which we defined earlier as 1000 Hz).
4. Apply this filter to the numpy array `signal` (which contains the original time
data). Use the `filtfilt` function for zero-phase filtering.
5. Store the filtered signal in a new numpy array called `filtered_signal`.
Make sure to import the necessary functions from `scipy.signal` (like `butter`,
`filtfilt`).
Print a message confirming the filtering is complete.
6. Paste and Run in Colab: Paste, verify parameters, and run.
7. Output: Confirmation message. The filtered_signal array now holds the low-pass
filtered version of your original signal.
Adapting for Other Filter Types:
● High-Pass: Change filter_type = 'highpass' in the code/prompt.
● Band-Pass: Change filter_type = 'bandpass' and provide the cutoff frequency as
a list/tuple: cutoff_freq = [low_cut, high_cut] (e.g., cutoff_freq = [500, 800] for
500-800 Hz band). The AI should adjust the prompt/code accordingly.
(Page 21: Visualizing Filtered Data)
How do we know the filter worked? By comparing the original and filtered signals in
both the time and frequency domains.
Prompts:
1. Compare Time Waveforms:
Prompt: Using matplotlib, create two subplots side-by-side (figure size 16x5).
Left subplot: Plot the original `signal` array against time (use `df['Timestamp']` or
create a time vector `np.arange(N)/Fs`). Title it 'Original Signal'.
Right subplot: Plot the `filtered_signal` array against the same time vector. Title it
'Filtered Signal (Low-Pass 100Hz)'.
Add appropriate axis labels and grid lines to both.
2. Compare FFT Spectrums: (This requires recalculating the FFT for the filtered
signal)
Prompt:
1. Calculate the FFT for the `filtered_signal` array (using `np.fft.fft`, same `N` and
`Fs` as before). Store the raw result.
2. Process this raw FFT to get the single-sided positive frequency axis
(`freq_filtered`) and magnitude (`magnitude_filtered_positive`), similar to how we
did it for the original signal.
3. Using matplotlib, create one plot (figure size 14x5).
4. On these axes, plot BOTH the original spectrum (`magnitude_positive` vs
`freq`) AND the filtered spectrum (`magnitude_filtered_positive` vs
`freq_filtered`).
5. Use different colors (e.g., blue for original, red for filtered) and add a legend.
6. Title the plot 'Original vs Filtered Spectrum'. Add axis labels and grid lines.
7. Optionally limit the x-axis (e.g., `plt.xlim(0, Fs/2)`).
Process:
● Use the prompts to get the code for plotting.
● For the FFT comparison, the AI needs to generate code that first recalculates the
FFT for filtered_signal and then plots both original and filtered magnitudes on the
same axes.
● Run the code and examine the plots.
Interpretation:
● Time Waveform Plot: The filtered signal should look smoother if it was a
low-pass filter (high frequencies removed) or might show different dominant
patterns if high-pass/band-pass.
● FFT Spectrum Plot: This clearly shows the filter's effect.
○ Low-Pass: Magnitudes above the cutoff frequency (100 Hz in our example)
should be significantly reduced in the filtered (red) spectrum compared to the
original (blue).
○ High-Pass: Magnitudes below the cutoff should be reduced.
○ Band-Pass: Magnitudes outside the specified band should be reduced.
Part 6: Putting it
Together & Next
Steps
Mini Case Study - Workflow Example
Let's walk through a typical analysis sequence using prompts. Assume we have
bearing_fault_data.csv in Google Drive at /content/drive/MyDrive/TestData/ and the
sample rate Fsis 2048 Hz.
Analysis Goal: Load data, view waveform, check metrics, view FFT, identify peaks,
maybe apply a high-pass filter.
Basic Troubleshooting
Even with AI help, things can go wrong. Here are common issues and how to approach
them:
● FileNotFoundError:
○ Cause: The Python code cannot find the file specified in the path.
○ Fix: Double-check the file path in the code cell matches the exact location
and name of your file (case-sensitive!). Use the "Copy path" feature in Colab's
file browser to be sure. Ensure your Drive is mounted if accessing from Drive.
Ensure the file was uploaded correctly if using direct upload.
● NameError: name '...' is not defined:
○ Cause: The code is trying to use a variable (e.g., df, signal, Fs) that hasn't
been created yet or wasn't created in a cell that has been run in the current
session.
○ Fix: Make sure you have run the previous code cells that define the variable.
Colab cells execute in the order you run them, not necessarily top-to-bottom.
You might need to re-run earlier cells. Check for typos in variable names in
your prompt or the AI's code.
● KeyError: 'ColumnName':
○ Cause: Trying to access a column in a DataFrame (df['ColumnName']) using a
name that doesn't actually exist in the DataFrame's headers.
○ Fix: Check the exact column names using df.head() or df.info(). Pay attention
to capitalization, spaces, and special characters. Correct the column name in
your prompt or the AI's code.
● IndexError: index ... is out of bounds:
○ Cause: Trying to access an element in a list or array using an index number
that is too large (e.g., asking for the 100th element of a 50-element array).
Often happens in plotting or processing loops if indexing is wrong.
○ Fix: This usually indicates a logic error in the code. Ask the AI to review the
specific line causing the error and fix the indexing logic.
● Incorrect Plot / Weird Results:
○ Cause: Could be many things: incorrect data loaded, wrong columns used for
plotting, incorrect sample rate (Fs) used for FFT, inappropriate filter
parameters.
○ Fix: Go back step-by-step. Verify data loading (df.head(), df.info()).
Double-check column names in plotting/calculation prompts. Confirm your
Sample Rate (Fs) is correct. Re-examine filter parameters (cutoff frequency,
order). Simplify the analysis (e.g., plot a smaller section of data) to isolate the
issue.
Asking the AI for Help:
You've learned how to use Colab and AI prompts to perform fundamental vibration
analysis! This opens the door to many possibilities:
● Explore More scipy.signal: Ask the AI about:
○ Windowing: Applying windows (Hanning, Hamming, Flat Top) before FFT to
reduce spectral leakage. (Prompt: "Apply a Hanning window to the signal
before calculating the FFT.")
○ Spectrograms: Visualizing how frequency content changes over time.
(Prompt: "Using scipy.signal.spectrogram, calculate and plot a spectrogram
for the signal array with sample rate Fs.")
○ Other Filter Types: Explore Chebyshev or Elliptic filters.
● Advanced Plotting: Use libraries like plotly for interactive plots (zooming,
panning). (Prompt: "Regenerate the FFT plot using the plotly.graph_objects library
to make it interactive.")
● Saving Results:
○ Saving Plots: (Prompt: "Save the last generated matplotlib plot as a PNG file
named 'spectrum.png' to my Google Drive in the
'/content/drive/MyDrive/Results/' folder.")
○ Saving Data: (Prompt: "Save the calculated peak frequencies and
magnitudes (the peaks variable) to a CSV file named 'peak_results.csv' in my
Google Drive.")
○ Saving Filtered Data: (Prompt: "Create a new DataFrame containing the
'Timestamp' column from df and the filtered_signal array. Save this DataFrame
to a CSV file named 'filtered_data.csv' in Google Drive.")
● Automation: For repetitive tasks on many files, you can ask the AI to help
structure code that loops through files in a directory. (This requires
understanding basic loop concepts).
● Specialized Libraries: Explore Python libraries built specifically for vibration or
rotating machinery analysis (e.g., pyvib, vibration-toolbox), although these might
require more understanding of Python concepts.
● Learning Basic Python: If you find yourself wanting more control or wanting to
understand the AI's code better, consider learning Python fundamentals
(variables, data types, lists, loops, functions). Many free online resources exist
(like the official Python tutorial, W3Schools, Codecademy).
The combination of Colab and AI provides a powerful, low-barrier entry point. Keep
experimenting with prompts and exploring the capabilities!
Glossary
● AI Assistant (e.g., Gemini): A tool that understands natural language prompts
and can generate code, text, or other content.
● Amplitude: The magnitude or intensity of the vibration signal (e.g., in g, mm/s,
mils).
● Colab (Google Colaboratory): A free, cloud-based environment for running
Python code in interactive notebooks.
● CSV (Comma Separated Values): A common, plain-text file format for storing
tabular data.
● Crest Factor: The ratio of the Peak amplitude to the RMS amplitude of a signal.
● Cutoff Frequency (fc): The frequency at which a filter starts to significantly
attenuate signals.
● DataFrame (pandas): A primary data structure in the pandas library,
representing data in a labeled, 2D table format (like a spreadsheet).
● FFT (Fast Fourier Transform): An efficient algorithm for converting a
time-domain signal into its frequency-domain components.
● Filter (Digital): An algorithm applied to a signal to remove or enhance specific
frequency ranges.
● Frequency (Hz): Hertz, cycles per second. The rate of oscillation.
● Frequency Resolution (Δf): The spacing between frequency lines in an FFT
spectrum (Δf=Fs/N).
● Frequency Spectrum: A plot showing the amplitude (or power) of different
frequency components present in a signal.
● Gemini: Google's large language model AI assistant.
● Google Drive: Google's cloud storage service, easily integrated with Colab.
● Header: The first row in a data file (like CSV) that contains the names of the
columns.
● Jupyter Notebook: An open-source web application that allows you to create
and share documents containing live code, equations, visualizations, and narrative
text. Colab is based on this.
● Magnitude: The size or amplitude, often used for the y-axis of an FFT spectrum.
● matplotlib: A fundamental Python library for creating static, animated, and
interactive visualizations.
● Mount (Drive): The process of connecting your Google Drive to your Colab
session so you can access files.
● Notebook (.ipynb): The file format used by Jupyter and Colab, containing code
cells, text cells, and outputs.
● numpy: A fundamental Python library for numerical computing, especially array
manipulation.
● Nyquist Frequency (Fnyquist): The highest frequency that can be accurately
represented in a sampled signal (Fnyquist=Fs/2).
● pandas: A powerful Python library for data manipulation and analysis, providing
structures like the DataFrame.
● Peak: The maximum absolute amplitude value in a signal.
● Peak-to-Peak (Pk-Pk): The difference between the maximum positive and
minimum negative values in a signal.
● Prompt: The natural language instruction given to an AI assistant.
● Python: A high-level, interpreted, general-purpose programming language widely
used in data science and engineering.
● RMS (Root Mean Square): A statistical measure of the magnitude of a varying
quantity; represents the effective amplitude or energy of the signal.
● Sample Rate (Fs): The number of data points (samples) recorded per unit of time
(usually seconds), measured in Hz.
● scipy: A Python library used for scientific and technical computing; scipy.signal
contains tools for signal processing like filtering and FFT analysis.
● Session (Colab): The temporary connection to Google's servers that runs your
notebook. Uploaded files are lost when the session ends.
● Signal: A function that conveys information about the behavior or attributes of
some phenomenon (e.g., vibration over time).
● Time Domain: Representation of a signal as its amplitude changes over time.
● Time Waveform: A plot of a signal's amplitude versus time.