Skip to main content

Fourier Transform - FFT


 so what is FFT or the fourier transform.

what is the use of the transform

ok an example would be a couple of data points in a digital world

and you want to  transform the data.


so why we need to transform the data 

consider a couple of digital data for sound wave and you want to do some manipulation on the data ,sine it resembles a sine wave 

we plot the data points as a sin wave 

 

your x axis would be time 

y axis would be your data 

The theory here is sound wave has a mix of signals so sin wave of 

different frequencies ,since we have collected data over time

we have to transform time data to freq data

 

in the freq domain our

x axis would be angular frequency 

y axis would be amplitude.

 

 you can find the link for the FFT and inverse FFT for  a sin wave 

 


 

https://github.com/naveez-alagarsamy/matplotlib/blob/main/fourier.ipynb

 

if u cant acess the link use the below code to run locally

 

import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fft, ifft

sample_rate = 8  # 8 samples in 1 second
sample_interval = 2*np.pi/sample_rate

x = np.arange(0, 2*np.pi, sample_interval) 
y = np.sin(x)

#adding another sin wave with freq =4
freq = 4
y += np.sin(freq*2*np.pi*x)

y_hat = np.arange(len(y))

print(y_hat)
#y = np.sin(2x)

plt.plot(x, y)
plt.show()


print(fft(y))
print(np.abs(fft(y)))

#fourier transform 
X = fft(y)

#angular freq which is = (2 * pi * n/sample_interval * sample rate )
w  = (2* np.pi* y_hat)/(sample_interval * sample_rate )
print(np.abs(w))

plt.figure(figsize = (12, 6))
plt.subplot(121)

plt.stem(np.abs(w), np.abs(X), 'b', \
         markerfmt=" ", basefmt="-b")
plt.xlabel('Freq (Hz)')
plt.ylabel('Amplitude ')
plt.xlim(0, 10)

plt.subplot(122)
plt.plot(x, ifft(X), 'r')
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.tight_layout()
plt.show()

 

Comments

Popular posts from this blog

SHA-256 initial values

The simple workout to arrive at the initial values for sha-256 The first 32 bit of the fractional part of the sqroot (first 8 prime number 2-19) Alright what does it say  Sqrroot(prime)- Let’s say the first prime is 2 Sqroot(2)  = 1.414213562373095 Convert to hexadecimal- Since we are worried about the fractional part alone Converting the fractional part would be easy Fractional part- 0.414213562373095 Multiply the fractional part with 16 to arrive at hex 0.414213562373095*16= 6.62741699796952 0.62741699796952*16= 10.03867196751232 0.03867196751232*16=0.61875148019712 0.61875148019712*16=9.90002368315392 0.90002368315392*16=14.40037893046272 0.40037893046272*16=6.40606288740352 0.40606288740352*16=6.49700619845632 0.49700619845632*16=7.95209917530112 Resulting hexadecimal would be 6a09e667 which is  h0 := 0x6a09e667 Iam going to stop at the 8th iteration , why is that ? Since we are interested in 32 bit (8*4=32) Alright to make it clear  Convert hexade...

Linear Regression with one variable - Introduction

 It is not but making a some how clear relationship among variables the dependent and independent variables. talking in terms of maths the equation can be used meaningfully for something may be to determine /predict values from data. if y = m * x + b  the values for m , b can be anything but has to appropriate to predict y  so the loss which is  difference from existing to prediction is close to zero ~0 to start with we can say the one variable as -x  in some scenario m , b are called variables    the equation stated about is a line equation we have any equation  y = 2*x  y = x*x y = 2x +2x*x  so why the need of all these equations , it is all about playing data now a days in machine learning problems we create a data sets , lets consider as x  y to be a value of x the datas . y = datas  when we express the data as a function and plot in the graph we get the curves  take some random data x and plot x and y  x =1 , 2, ...