plotting-fourier-series.ipynb

In [1]:
import matplotlib.pylab as plt
import numpy as np
# %matplotlib widget

Plot random waves and fourier tranform of the random waves

In [2]:
def get_wave(A, f, theta, phi):
    x = theta
    y = A*np.sin(2*np.pi*f*theta - phi)
#     plt.plot(x, y, alpha)
    return x, y
In [3]:
def plot_wave(time, data):
    A = data[0]
    f = data[1]
    phi = data[2]
    x, y = get_wave(A, f, time, phi)
    
    plt.figure(figsize = (13, 6))
    ax = plt.gca()
    plt.plot(x, y, color = 'blue')

    ax.set_xlabel('Time', fontsize = 20, color = 'red')
    ax.tick_params(axis='x', colors='red')
    ax.tick_params(axis='y', colors='red')
In [4]:
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
data = [2, 3, 0]
plot_wave(theta, data)
In [5]:
def plot_multiple_waves(time, data):
    no_of_plots = len(data)
    fig, axes = plt.subplots(no_of_plots, figsize = (16, 9))
    for i in range(no_of_plots):
        ax = axes[i]
        w_data = data[i] 
        A = w_data[0]
        f = w_data[1]
        phi = w_data[2]
        x, y = get_wave(A, f, time, phi)
        ax.plot(x, y, color = 'blue', alpha = 1)
        ax.set_ylabel(f'Wave {i + 1}', color = 'blue', fontsize = 15)

        fig.suptitle('Time', fontsize = 20, color = 'red')
        ax.tick_params(axis='x', colors='red')
        ax.tick_params(axis='y', colors='red')
        ax.set_ylim(-15, 15)
In [6]:
data = [
    [6, 1, 0],
    [5, 2, 0],
    [10, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
# time = theta
plot_multiple_waves(theta, data)
In [7]:
def plot_a_fourier_waves(data, time):
    no_of_plots = len(data)
#     fig, axes = plt.subplots(no_of_plots, figsize = (16, 9))
#     xs = np.zeros(len(time))
    ys = np.zeros(len(time))
    for i in range(no_of_plots):
#         ax = axes[i]
        w_data = data[i] 
        A = w_data[0]
        f = w_data[1]
        phi = w_data[2]
        x, y = get_wave(A, f, time, phi)
        ys += y
        
    fig = plt.figure(figsize = (16, 3))
    ax = plt.gca()
    plt.plot(x, ys, color = 'blue', alpha = 1)
#     ax.set_ylabel(f'Wave {i + 1}', color = 'blue', fontsize = 15)

    fig.suptitle('Time', fontsize = 20, color = 'red')
    ax.tick_params(axis='x', colors='red')
    ax.tick_params(axis='y', colors='red')
    lim = max(np.abs(ys))
    ax.set_ylim(-(lim+3), lim+3)
In [8]:
data = [
    [6, 1, 0],
    [5, 2, 0],
    [10, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
# time = theta
plot_a_fourier_waves(data, theta)
In [40]:
def plot_multiple_waves_fourier_wave(data, time, alpha = 1):
    no_of_plots = len(data) + 2
    fig, axes = plt.subplots(no_of_plots, figsize = (16, 9))
    xs = np.zeros(len(time))
    ys = np.zeros(len(time))
    for i in range(no_of_plots):
        ax = axes[i]
        if i < no_of_plots - 2:
            w_data = data[i] 
            A = w_data[0]
            f = w_data[1]
            phi = w_data[2]
            x, y = get_wave(A, f, time, phi)
            ax.plot(x, y, color = 'blue', alpha = alpha)
            xs += x
            ys += y
            
            
        elif i == no_of_plots - 2:
            for j in range(no_of_plots-2):
                w1_data = data[j]
                A = w1_data[0]
                f = w1_data[1]
                phi = w1_data[2]
                x1, y1 = get_wave(A, f, time, phi)
                ax.plot(x1, y1, color = 'green', alpha = alpha)
        else:
            ax.plot(xs, ys, color = 'red', alpha = alpha)
            
            
        fig.suptitle('Time', fontsize = 20, color = 'red')
        ax.tick_params(axis='x', colors='red')
        ax.tick_params(axis='y', colors='red')
        ax.set_xlim(min(time), max(time))
        ax.set_ylim(-20, 20)
        
In [43]:
data = [
    [6, 1, 0],
    [5, 2, 0],
    [10, 6, -np.pi/3],
    [1, 1, 0],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)
# time = theta
plot_multiple_waves_fourier_wave(data, theta)

Plot the given circular waves and fourier transform of the given circular waves

In [42]:
def get_circle(A, f, theta, phi):
    x = A*np.cos(2*np.pi*f*theta - phi)
    y = A*np.sin(2*np.pi*f*theta - phi)
#     ax.plot(x, y, color = color, alpha = alpha)
    return x, y
In [12]:
def plot_circles_fourier(data, time, alpha = 1):
    x = 0
    y = 0
    for A, f, phi in data:
        x_temp, y_temp = get_circle(A, f, time, phi)
        x += x_temp
        y += y_temp
    fig = plt.figure(figsize = (6, 6))
    ax = plt.gca()
    plt.plot(x, y, alpha, color = 'blue')
    
    ax.tick_params(axis='x', colors='red')
    ax.tick_params(axis='y', colors='red')
In [13]:
data = [
    [8, 1, 0],
    [5, 2, 0],
#     [50, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)

plot_circles_fourier(data, theta)
plt.gca().set_aspect('equal')
In [14]:
def plot_circular_wave(data, time):
    A = data[0]
    f = data[1]
    phi = data[2]
    x, y = get_circle(A, f, time, phi)
    
    plt.figure(figsize = (13, 6))
    ax = plt.gca()
    plt.plot(x, y, color = 'blue')

    ax.set_xlabel('Time', fontsize = 20, color = 'red')
    ax.tick_params(axis='x', colors='red')
    ax.tick_params(axis='y', colors='red')
    ax.set_aspect('equal')    
In [15]:
data = [2, 3, 0]

steps = 1000
theta = np.linspace(0, 2*np.pi, steps)

plot_circular_wave(data, theta)
In [ ]:
 
In [16]:
def plot_circles_fourier(data, time, alpha = 1):
    no_of_plots = len(data) + 2
    fig, axes = plt.subplots(ncols = no_of_plots, figsize = (16, 9))
    xs = np.zeros(len(time))
    ys = np.zeros(len(time))
    for i in range(no_of_plots):
        ax = axes[i]
        if i < no_of_plots - 2:
            w_data = data[i] 
            A = w_data[0]
            f = w_data[1]
            phi = w_data[2]
            x, y = get_circle(A, f, time, phi)
            ax.plot(x, y, color = 'blue', alpha = alpha)
            xs += x
            ys += y
        elif i == no_of_plots - 2:
            for j in range(no_of_plots-2):
                w1_data = data[j]
                A = w1_data[0]
                f = w1_data[1]
                phi = w1_data[2]
                x1, y1 = get_circle(A, f, time, phi)
                ax.plot(x1, y1, color = 'green', alpha = alpha)
        else:
            ax.plot(xs, ys, color = 'red', alpha = alpha)
            
            
        ax.set_xlim(-12, 12)
        ax.set_ylim(-12, 12)
        ax.set_aspect('equal')
In [17]:
data = [
    [6, 4, 0],
    [2, 9, 0],
#     [50, 6, -np.pi/3],
]
plot_circles_fourier(data, theta)
In [18]:
def plot_multiple_circular_waves(data, time):
    no_of_plots = len(data)
    fig, axes = plt.subplots(ncols = no_of_plots, figsize = (16, 9))
    for i in range(no_of_plots):
        ax = axes[i]
        w_data = data[i] 
        A = w_data[0]
        f = w_data[1]
        phi = w_data[2]
        x, y = get_circle(A, f, time, phi)
        ax.plot(x, y, color = 'blue')           
            
        ax.set_xlim(-12, 12)
        ax.set_ylim(-12, 12)
        ax.set_aspect('equal')

        ax.set_title(f'Wave {i + 1}', fontsize = 20, color = 'red')
        ax.tick_params(axis='x', colors='red')
        ax.tick_params(axis='y', colors='red')
In [ ]:
 
In [19]:
data = [
    [8, 1, 0],
    [5, 2, 0],
#     [50, 6, -np.pi/3],
]
steps = 1000
theta = np.linspace(0, 2*np.pi, steps)

plot_multiple_circular_waves(data, theta)
In [ ]:
 
In [ ]:
 

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing