Im doing some beginners spectral analysis for a homemade reactive RGB LED project and was thinking of ways to improve the accuracy of the audio analysis. Im using a Playstation eye with a Raspberry Pi Zero W (limited performance) and ive read several articles to try to better my understanding. According to this article, the playstation eye has 4 channels, where the 2nd and 3rd are reversed for noise cancellation.
I assume that the 2nd channel is a reverse of the 1st and the 3rd of the 4th. Am i correct to assume that the way to go about implementing these extra channels would be to average the two sums of 1+2 and 3+4 ie.
voltage = (c1+c2+c3+c4)/2?
Below is a script i use for testing, only the basics. Note that i use a sampling rate of 20khz instead of 44.1khz due to the limited cpu resources of the pi zero. I also use int16 as wiki states that the ps eye uses 16bit ints. Am i wrong not to use the default float?
The reason i want to improve it is that i havent recorded any frequencies over 7000, which seems a bit odd to me given the vast variety of music ive tested with. Im wondering if the playstation eye is not suitable for such precise analysis, or if my methods are wrong. Is it possible to improve this with noise cancellation, or will it worsen my results? Should i rather just use a single channel or sum channel 1+4?
#!/usr/bin/env python3 import sounddevice as sd import numpy as np RATE = 20000 lowest = 200 highest = 0 h_m = 0 def print_sound(indata, frames, time, status): global lowest, highest, h_m if status: print(status) if frames == 0: return data = np.sum(indata, axis=1) # data = data * np.hanning(len(data)) # smooth the FFT by windowing data fft = abs(np.fft.rfft(data)) # calculate magnitudes from positive fft coefficients freq = np.fft.rfftfreq(frames, 1.0/RATE) # calculate positive frequency bins max = np.max(fft) # highest magnitude freqPeak = freq[np.where(fft==max)] # find frequency with highest magnitude if freqPeak < lowest: lowest = freqPeak print("lowest: %d"%freqPeak) if freqPeak > highest: highest = freqPeak print("highest: %d"%freqPeak) if max > h_m: h_m = max print(max) with sd.InputStream(dtype='int16', channels=4, samplerate=RATE, callback=print_sound): while True: response = input() if response in ('', 'q', 'Q'): break