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

Node and Auth0 - Integration

 so now we have completed all the steps for integration  since we have the node and auth0 as two separate things the integration happens in the app.js  we need to modify the app.js with some auth0 code  app.js / const http = require('http'); const express = require('express'); var router = require('express').Router(); const { auth } = require('express-openid-connect'); const app = express(); app.use('/', router); const hostname = '127.0.0.1'; const port = 3000; http.createServer(app)   .listen(port, () => {     console.log(`Listening on `);   }); const config = {   authRequired: false,   auth0Logout: true,   secret: 'a long, randomly-generated string stored in env',   baseURL: 'http://localhost:3000',   clientID: 'QxpAXsXkzy0Vm2VdT6dFFS0VOKdrah67',   issuerBaseURL: 'https://dev-bnga041p.us.auth0.com' }; console.log(config) // auth router attaches /login, /logout, and /callback routes to the baseURL app.u

Auth0

You might be wondering what is this auth0  it is used for authentication of you applications  could be any apps  1.SPA - Angular , React  2.web app 3.Node  here we will talk about the node use case and go with example  moving ahead for now  if your are not familiar with node dont worry its a funny exercise for now walk with me  we dont have to worry too much for authentication as the service is  provided from auth0   create your node app  install node  https://nodejs.org/en/download/package-manager/  choose your os and do the installation once installed check for the version ' node -v  ' i assume u have installed so that u wil get the version for now  since iam using LINUX this will look like root@strings-desktop:/home/strings/js# node -v v16.13.0 moving on to creating node app for now    create a file app.js and paste the contents  app.js/ const http = require('http'); const express = require('express'); const app = express(); const hostname = '127.0.0.1&#