Sunday, March 23, 2025

Signal Processing with Butterworth(Low Pass) Filter

 Example Signal:

       



Figure 1: Signal of 10Hz and 20Hz

    The frequency formula in terms of time is given as: f = 1/T where, f is the frequency in hertz, and T is the time to complete one cycle in seconds. Can see that a higher frequency signal complete a cycle faster in time than a lower frequency signal.

A low-pass filter (LPF) below allows signals with frequencies below 50Hz cutoff frequency to pass through while attenuating (reducing) signals with frequencies above that cutoff.


Coding 

from scipy.signal import butter, lfilter
    import numpy as np
    import matplotlib.pyplot as plt
    
    # Generate a sample signal
    fs = 200  # Sampling frequency in Hz
    t = np.linspace(0, 1, fs, endpoint=False)  # 1 second of data
    signal1 = np.sin(2 * np.pi * 80 * t) 
    
    # Design a low-pass filter (cutoff at 50 Hz)
    cutoff = 50 # Cutoff frequency in Hz
    nyquist = fs / 2  # Nyquist frequency
    Wn = cutoff / nyquist  # Normalized cutoff frequency
    b, a = butter(5, Wn, btype='low')  # 5th-order low-pass filter
    
    # Apply the filter
    filtered_signal = lfilter(b, a, signal1)
    
    # Plot the original and filtered signal
    plt.figure(figsize=(10, 6))
    plt.plot(t, signal1, label='Original Signal')
    plt.plot(t, filtered_signal, label='Filtered Signal')
    plt.title('Low-Pass Filter (50 Hz Cutoff)')
    plt.xlabel('Time [s]')
    plt.legend()
    plt.grid()
    plt.show()

As shown in graph, the original signal of 80 Hz is filter out, as the allowed signal is just below 50Hz.


References

1. https://www.linkedin.com/pulse/signal-processing-python-part-1-generate-signals-basic-hampiholi/


Sunday, March 16, 2025

Laplace Transform with Python

Laplace transform is an effective method for solving ordinary and partial differential equations, and it has been successful in many applications. These equations describe how certain quantities change over time, such as the current in an electrical circuit, the vibrations of a membrane, or the flow of heat through a conductor. The Laplace transform helps converts differential equations into simpler algebraic equations. Both the Laplace transform and its inverse are important tools for analyzing dynamic control systems. The Laplace transform changes a signal in the time domain into a signal in the s-domain, also called the splane, which can then be solved by the formal rules of algebra.

Example




Coding

from sympy import *

    t = Symbol('t', real=True)

    s = Symbol('s', real=True, positive=True)

    a = Symbol('a', real=True, positive=True)

    f = t*exp(-a*t)

    laplace_transform(f,t,s, noconds=True)





References:

1. https://www.geeksforgeeks.org/laplace-transform/

2. https://en.wikipedia.org/wiki/Laplace_transform

3. https://www.analog.com/media/en/technical-documentation/dsp-book/dsp_book_Ch32.pdf

Python to solve ODE(ordinary differential equations)

References: Udemy

Python to solve ODE(ordinary differential equations)

Coding

import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt def returns_dydt(y,t): dydt = t**3 + (2*t**2) return dydt # initial condition y0 = 4 # values of time , from 0 to 5 t = np.linspace(0,1,20) # solving ODE y = odeint(returns_dydt,y0, t) # plot results plt.plot(t,y) plt.xlabel("Time") plt.ylabel("Y") plt.show()



Results




Thursday, March 13, 2025

How to Install Python Anaconda On Your Window Laptop?

I think Python Anaconda is free for personal use for research etc. And it has quite some libraries ready for use.

1. Go to Anaconda.com. Click on 'Free Download' on the upper right corner. Provide your email address, then go to the link send to your email to download the installer. Install as per the instructions show. Tick on 'Launch Anaconda Navigator' and 'Getting Started with Anaconda Distribution'. 

2. After the installation completed, launch Anaconda Navigator from your window. Launch the Jupyter notebook.

3. Google search on how to enable local host in your window, or how to enable IIS in window. After that, go to the Jupyter launched in the Microsoft Edge. 

4. You can now use the python in the Jupyter.






Sunday, March 2, 2025

Serialization


Serialization is the process of converting a data object into a byte stream. Serialization converts objects in any programming language to 1’s and 0’s that can be understood by any computer hardware irrespective of the language they are using.

RS232 and RS485 are both serialization port. Both serial communication standards made major impacts on the industry. However, most RS232 ports have been replaced in personal computers by USB today. This is due to USBs’ advantages of being faster, having lower voltages, and having connectors that are simple to connect and use.


Figure 1: https://medium.com/@mk8961052/serialization-and-deserialization-in-java-75742c5f9b21


References:

1. https://medium.com/@hatim.zahid/serialization-and-deserialization-how-data-travels-in-a-computer-network-13f61dc225c4

2. https://www.seeedstudio.com/blog/2019/12/06/what-is-rs485-and-its-difference-between-rs232/