Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Wed May 16 21:32:53 2018
- @author: rkabealo
- A program to import .rdvxz files collected from the RedVox app, decode the files
- and extract the collected Microphone data (using methods declared in reader.py), and finally plot this data and
- save the plotted figure (visually, a waveform)
- """
- import api900_pb2
- import reader
- import struct
- import typing
- import google.protobuf.internal.containers as containers
- import lz4.block
- import numpy
- import numpy as np
- from matplotlib import pyplot as plt
- """ A list of test files we have, as well as the file we've designated
- for testing """
- rPhone = "0937537210_1526315748790.rdvxz"
- spaceX = "1637160009_1526493437311.rdvxz"
- cTest = ""
- testFile = rPhone
- """ Gets the decoded version of the data from the test file and displays
- it to the console """
- dRVOP = reader.read_file(testFile)
- #print(dRVOP)
- """ Gets the wrapped RedVox packet for our data """
- wRVP = reader.WrappedRedvoxPacket(dRVOP)
- """ Displays whether the microphone channel exists (just checking
- for our own sanity) """
- findMic = wRVP.has_channel(api900_pb2.MICROPHONE)
- #print(findMic)
- """ Gets the different types of channels, so we can see which ones are
- interleaved. From this call we see that the MICROPHONE channel (denoted [0])
- is NOT interleaved. """
- listofChannels = wRVP.get_channel_types()
- #print(listofChannels)
- """ We can check again that the microphone is
- NOT interleaved through this method """
- listofChannelNames = wRVP.get_channel_type_names()
- #print(listofChannelNames)
- """ Gets the microphone channel in its entirity
- # Takes: channel_type enum
- # Returns: api900_pb2.EvenlySampledChannel"""
- micChannel = wRVP.get_channel(api900_pb2.MICROPHONE)
- #print(micChannel)
- """ Failure #1: Gets the payload from the mic data
- # Takes: channel_type enum
- # Returns: api900_pb2.EvenlySampledChannel"""
- #payloadMic = reader.InterleavedChannel(micChannel).get_payload()
- #print(payloadMic)
- """ Failure #2: Gets the payload from the mic data
- # Takes: channel_type enum
- # Returns: api900_pb2.EvenlySampledChannel"""
- #strMic = reader.InterleavedChannel(micChannel).has_payload(api900_pb2.MICROPHONE)
- #reader.extract_payload(micChannel)
- #print(strMic)
- """ Gets the sample rate (in Hz) from the microphone channel. We
- can access the sample rate like this because it's an attribute of the
- microphone channel """
- #print(micChannel.sample_rate_hz)
- """ Gets the payload data from the microphone channel as a numpy array. We
- can access the payload like this because it's an attribute of the
- microphone channel. Just like above with sample_rate_hz"""
- data = micChannel.payload
- #print(data)
- """Plotting the payload"""
- fig, ax = plt.subplots(nrows=1, ncols=1,figsize=(5,1.25)) # create figure & 1 axis
- ax.plot(data, color='blue')
- ax.set_title('ID: 1637650005 Data', fontsize=3.75)
- ax.set_xlabel('Time (s)', fontsize=3.75)
- ax.set_ylabel('Amplitude', fontsize=3.75)
- plt.xticks(fontsize=3.875, rotation=0)
- plt.yticks(fontsize=3.875, rotation=90)
- """Save the figure"""
- fig.savefig('testFile.png', dpi = 250)
Advertisement
Add Comment
Please, Sign In to add comment