2
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('signal180_single.csv', sep=',', header=None)
x = df.values
length = len(x)
# frequency 0.02s
fs = 50.0
t = np.arange(0, length/fs,1.0/fs)

xF = np.fft.fft(x)
N = len(xF)
xF = xF[0:N/2]

# plot frequencys from 0 to fs, with num = N/2
fr = np.linspace(0,fs,N/2)

plt.figure()
plt.subplot(211)
plt.plot(t,x)
plt.subplot(212)
plt.plot(fr, abs(xF))
plt.show()

I am writing 180000 floating point values into an array from file. The values are sampled at 50Hz, and contains a sinus of 2Hz.

Then I plot the frequency in the upper plot window. I want to plot the frequency specter of the frequency in the lower plot window, but I get the same values as in the upper plot window. Can anyone see where the error is?

When I plot the formula x = np.sin(10*t) + np.cos(3*t), I get the frequency’s. But not when I read the sinus from a file or array.

1
  • Please accept the answer if it solved your problem. You don't need to add "solved" to the title. The question will be marked as solved once you do that. Commented Jun 29, 2017 at 7:56

1 Answer 1

3

the line

x = df.values 

returns a 180000 x 1 array. Where every value is stored separately. In this case replace the line with:

x = df.values.ravel()

And your script will work.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you kwant, so it was my data array i had to fix. Now it works.
Glad that it solved your problem. One more thing, could you mark the question as answered?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.