I have two signals, each one of them is a sum of random cosine & sine waves.
I need to classify them using a clustering algorithm.
How do I go about that using python?
classify what exactly?
>>8143761
I don't know this question is driving me crazy.
That's all what the exercise says.
My best guess is classify them according to the frequencies maybe?
Don't know what the clustering algorithm part of the question is talking about. I would use an FFT in Python using NumPy so you can get a graph with frequency on the X axis. There you will be able to see the frequency spectrum and understand what sine and cosine waves went into making your signal. You'll get awesome graphs if you make sure the frequency resolution is 1 Hz or smaller, but I don't know what you mean by "classify".
Just do FFT and then some clustering algorithm from scikit-learn. ezpz
>>8143789
find some k means algorithm for python
draw the fft of your signal
I might be wrong, but I suggest that as your features, you use frequencies AND phases, you might get something interesting. If phases are irrelevant, you will notice anyway.
each component of the signal corresponds to a point in a 2D space (frequency,phase).
try to visually see how many groups you can form (you can use better methods, but this is just a first test)
use your k-means on the set of obtained points, with the number of groups you want to get
don't know what your signal looks like so you might need more steps, but that's a way to start.
>>8143846
these are my two random signals. It's my first time with python I'm sure it's messy.
N = 10001 # Number of samples
Nf = np.sum(n) # number of Frequencies
t = np.arange(N, dtype= float)
Ts = np.random.rand(Nf)*2000+10
fs = 1/Ts #random frequencies
print(fs)
#random amplitudes
amp= np.random.rand(Nf)*200+10
#First signal
for num in range(0, int(n[0])):
signal1 = np.array(signal1 + np.array(amp[num]* np.cos(fs[num]*2*np.pi*t)))
for num in range(0, int(n[1])):
signal1 = np.array(signal1 + np.array(amp[num+int(n[0])]* np.sin(fs[num+int(n[0])]*2*np.pi*t)))
#Second signal
for num in range(0, int(n[2])):
signal2 = np.array(signal2 + np.array(amp[num+int(n[0])]* np.cos(fs[num+int(n[0])]*2*np.pi*t)))
for num in range(0, int(n[3])):
signal2 = np.array(signal2 + np.array(amp[num+int(n[0])]* np.sin(fs[num+int(n[0])]*2*np.pi*t)))
>>8143854
sorry this is the second signal
#Second signal
for num in range(0, int(n[2])):
signal2 = np.array(signal2 + np.array(amp[num+int(sum(n[0:2]))]* np.cos(fs[num+int(sum(n[0:2]))]*2*np.pi*t)))
for num in range(0, int(n[3])):
signal2 = np.array(signal2 + np.array(amp[num+int(sum(n[0:3]))]* np.sin(fs[num+int(sum(n[0:3]))]*2*np.pi*t)))
>>8143854
I forgot something: you can also consider amplitude as a feature. And here it looks like there is no phase so you can remove that.
and instead of k-means, I suggest a gaussian mixture model because of the rand.
>>8143904
I'm really new to all of this. any help concerning the Gaussian mixture ?