Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- If it will be helpful, please like this post
- """
- import pandas as pd
- import matplotlib.pyplot as plt
- import numpy as np
- import scipy.stats
- from statsmodels.graphics.tsaplots import plot_acf
- #https://scicoding.com/4-ways-of-calculating-autocorrelation-in-python/
- if __name__ == '__main__':
- df = pd.read_csv('CompanyABCProfit.csv').set_index('Year')
- # fig = plt.figure(figsize=(10, 10))
- # plt.xlabel('Year')
- # plt.ylabel('Profit')
- # df.plot()
- # plt.close()
- values_df = []
- for value in df["Profit(Rs '000)"]:
- values_df.append(value)
- corr_func = (np.correlate(values_df - df.mean()[0], values_df - df.mean()[0], 'full')) / df.var()[0] / len(values_df)
- # fig = plt.figure(figsize=(10, 10))
- corr_function = pd.DataFrame(corr_func).reset_index()
- corr_function['index'] = corr_function['index'] - len(df)
- corr_function = corr_function.set_index('index')
- corr_function.plot()
- # plt.show()
- # plt.close()
- Fs = 1024
- sampling_rate = 30 #signal freq
- Number_of_repeat = 10
- N = int(Number_of_repeat * Fs / sampling_rate) #number of samples
- t_step = 1 / Fs
- t = np.linspace(0, (N - 1) * t_step, N) #time interval
- freq = Fs / N #freq step
- f = np.linspace(0, (N - 1) * freq, N) # freq interval
- data = 2 * np.sin(2 * np.pi * sampling_rate * t) + 4 * np.sin(2 * np.pi * 3 * sampling_rate * t)
- fureir = scipy.fft.fft(data)
- fureier_abs = abs(fureir / N)
- data_spec = f[0 : int(N / 2 + 1)]
- furier_abs_plot = 2 * fureier_abs[0 : int(N / 2 + 1)]
- fureier_abs[0] /= 2
- fig, [ax1, ax2] = plt.subplots(nrows=2, ncols=1)
- ax1.plot(t, data)
- ax2.plot(data_spec, furier_abs_plot)
- plt.show()
- stop = 'here'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement