From 20511f34f32fbb93d7a9d96155dd4ce1acbf6c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 23 Mar 2018 21:53:03 +0100 Subject: [PATCH] added a matlab demo - surprisingly seamless --- mat_sampling.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 mat_sampling.m diff --git a/mat_sampling.m b/mat_sampling.m new file mode 100644 index 0000000..7a42985 --- /dev/null +++ b/mat_sampling.m @@ -0,0 +1,24 @@ +% this is an example of sampling the ADC from Matlab and then plotting a +% FFT graph. The ADC unit called 'adc' is configured to use PA1 as Ch. 0 + +%transport = py.gex.TrxSerialThread(pyargs('port', '/dev/ttyUSB1', 'baud', 57600)); +transport = py.gex.TrxRawUSB(); +client = py.gex.Client(transport); +adc = py.gex.ADC(client, 'adc'); + +L=1000; +Fs=1000; + +adc.set_sample_rate(uint32(Fs)); +data = adc.capture(uint32(L)); +data = double(py.array.array('f',data)); + +Y = fft(data); +P2 = abs(Y/L); +P1 = P2(1:L/2+1); +P1(2:end-1) = 2*P1(2:end-1); + +f = Fs*(0:(L/2))/L; +plot(f,P1) + +client.close()