I have a csv file includes two column
no. of packet size
1 60
2 70
3 400
4 700
.
.
.
1000000 60
where the first column is
the number of packet
, and the second column is
the size of packet in bytes.
the total number of packets in the csv file is one million. I need to plot histogram for this data file by:
xrange = [0, 5 , 10 , 15 ]
which denotes the packet size in bytes. The range [0] denotes the packet size less than 100 bytes, and [5] denotes the packet bytes less than 500 bytes and so on.
yrange = [ 10, 100, 10000, 100000000],
which denots the number of packets
Any help will be highly appreciated.
Don't quite remember exactly how this works, but the commands given in my Gnuplot in Action book for creating a histogram are
bin(x,s) = s*int(x/s)
plot "data-file" using (bin(1,0.1)):(1./(0.1*300)) smooth frequency with boxes
I believe smooth frequency is the command that's important to you, and you need to figure out what the using argument should be (possibly with a different function used).
This should do the job:
# binning function for arbitrary ranges, change as needed
bin(x) = x<100 ? 0 : x<500 ? 5 : x<2500 ? 10 : 15
# every occurence is counted as (1)
plot datafile using (bin($2)):(1) smooth freq with boxes
Im not really sure what you mean by "yrange [10 100 1000 ...]", do you want a logscaled ordinate?
Then just
set xrange [1:1e6]
set logscale y
before plotting.
Related
I have generated a tone from Audacity at 440Hz with Amplitude as 1 for 1 sec like this:
I understand that this is going to create 440 peaks in 1 sec with Amplitude as 1.
Here i see that its a 32 bit file with 44100Hz is the sample rate which means there are 44100 samples per sec. The Amplitude is 1 which is as expected because that is what i chose.
What i dont understand is, what is the unit of this Amplitude? When right-clicked it shows linear(-1 to +1)
There is an option to select dB it shows (0 to -60 to 0) which i dont understand how is this converted!
now when i use this wav file in the python scipy to read the wav and get values of time and amplitude
How to match or get the relation between what i generated vs what i see when i read a wav file?
The peak is amplitude is 32767.987724003342 Frequency 439.99002267573695
The code i have used in python is
wavFileName ="440Hz.wav"
sample_rate, sample_data = wavfile.read(wavFileName)
print ("Sample Rate or Sampling Frequency is", sample_rate," Hz")
l_audio = len(sample_data.shape)
print ("Channels", l_audio,"Audio data shape",sample_data.shape,"l_audio",l_audio)
if l_audio == 2:
sample_data = sample_data.sum(axis=1) / 2
N = sample_data.shape[0]
length = N / sample_rate
print ("Duration of audio wav file in secs", length,"Number of Samples chosen",sample_data.shape[0])
time =np.linspace(0, length, sample_data.shape[0])
sampling_interval=time[1]-time[0]
notice in audacity when you created the one second of audio with aplitude choice of 1.0 right before saving file it says signed 16 bit integer so amplitude from -1 to +1 means the WAV file in PCM format stores your raw audio by varying signed integers from its max negative to its max positive which since 2^16 is 65536 then signed 16 bit int range is -32768 to 32767 in other words from -2^15 to ( +2^15 - 1 ) ... to better plot I suggest you choose a shorter time period much smaller than one second lets say 0.1 seconds ... once your OK with that then boost it back to using a full one second which is hard to visualize on a plot due to 44100 samples
import os
import scipy.io
import scipy.io.wavfile
import numpy as np
import matplotlib.pyplot as plt
myAudioFilename = '/home/olof/sine_wave_440_Hz.wav'
samplerate, audio_buffer = scipy.io.wavfile.read(myAudioFilename)
duration = len(audio_buffer)/samplerate
time = np.arange(0,duration,1/samplerate) #time vector
plt.plot(time,audio_buffer)
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.title(myAudioFilename)
plt.show()
here is 0.1 seconds of 440 Hz using signed 16 bit notice the Y axis of Amplitude range matches above mentioned min to max signed integer value range
I would like to prepare a script file to draw a 3D plot of some kinetic spectroscopy results. In the experiment the absorption spectrum of a solution is measured sequentially at increasing times from t0 to tf with a constant increase in time Δt.
The plot will show the variation of absorbamce (Z) with wavelength and time.
The data are recorded using a UV-VIS spectrometer and saved as a CSV text file.
The file contains a table in which the first column are the wavelengths of the spectra. Afterwards, a column is added for each the measured spectra, and a number of columns depends on the total time and the time interval between measuerments. The time for each spectra appears in the headers line.
I wonder if the data can be plotted directly witha minimum of preformatting and without the need to rewrite the data in a more estandar XYZ format.
The structure of the data file is something like this
Title; espectroscopia UV-Vis
Comment;
Date; 23/10/2018 16:41:12
Operator; laboratorios
System Name; Undefined
Wavelength (nm); 0 Min; 0,1 Min; 0,2 Min; 0,3 Min; ... 28,5 Min
400,5551; 1,491613E-03; 1,810312E-03; 2,01891E-03; ... 4,755786E-03
... ... ... ... ... ...
799,2119; -5,509266E-04; 3,26314E-04; -4,319865E-04; ... -5,087912E-04
(EOF)
A copy of a sample data is included in this file kinetic_spectroscopy.csv.
Thanks.
Your data is in an acceptable form for gnuplot, but persuading the program to plot this as one line per wavelength rather than a gridded surface is more difficult. First let's establish that the file can be read and plotted. The following commands should read in the x/y coordinates (x = first row, y = first column) and the z values to construct a surface.
DATA = 'espectros cinetica.csv'
set datafile separator ';' # csv file with semicolon
# Your data uses , as a decimal point.
set decimal locale # The program can handle this if your locale is correct.
show decimal # confirm this by inspecting the output from "show".
set title DATA
set ylabel "Wavelength"
set xlabel "Time (min)"
set xyplane 0
set style data lines
splot DATA matrix nonuniform using 1:2:3 lc palette
This actually looks OK with your data. For a smaller number of scans it is probably not what you would want. In order to plot separate lines, one per scan, we could break this up into a sequence of line plots rather than a single surface plot:
DATA = 'espectros cinetica.csv'
set datafile separator ";"
set decimal locale
unset key
set title DATA
set style data lines
set ylabel "Wavelength"
set xlabel "Time (min)"
set xtics offset 0,-1 # move labels away from axis
splot for [row=0:*] DATA matrix nonuniform every :::row::row using 1:2:3
This is what I get for the first 100 rows of your data file. The row data is colored sequentially by gnuplot linetypes. Other coloring schemes are possible.
I would like to display data in a repeated online diagram with:
plot "tail -140 logging.dat | tac -r" with lines
I get an error message file cannot be opened, however in CLI it gives the reverse list of data as expected. Could anyone help me with the correct syntax, please?
Just for the records, here is a gnuplot-only, hence platform-independent solution. Check via stats the total number of lines. If there are less than N lines (here: 140), all lines will be plotted, otherwise only the 140 last ones.
Remark: if you do plot ... with lines, gnuplot will plot column 1 as x and column 2 as y per default. However, the output graph will look the same whether you reverse the data or not. So, I don't see why reversing the data would be necessary, unless you want to plot something what you haven't shown here or e.g. list a reversed table as text.
Script:
### plot N last lines of a file
reset session
FILE = "SO55221113.dat"
# create some random test data
set table FILE
set samples 1000
y0 = rand(0)
plot '+' u 1:(y0=y0+rand(0)-0.5)
unset table
N = 140
stats FILE u 0 nooutput # get total number of lines into STATS_records
M = STATS_records<=N ? STATS_records : STATS_records-N
plot FILE u 1:2 w l lc rgb "green" ti "all values", \
'' u 1:2 every ::M w l lc rgb "red" ti sprintf("last %d values",N)
### end of script
Result:
I have 3 producers. Each has 200 consumers as turtles who have purchased laptops. All producers sell laptops. The laptops have 3 kinds of features : size of the screen, price, battery life. Each has some levels. For example battery life has 5 hours, 12 hours, 24 hours, 30 hours. Each producer has some information about how consumers have rated these items based on what they have experienced that is stored in a csv file. So the CSV file header is something like this :
Consumer 12 13 13.5 14 14.5 15 500 600 750 650 550 700 5 12 24 30
( To exaplin the header : 12 - 15 represent levels of screen size, 500 - 700 price, 5 - 30 battery life in hours)
Each producer needs to analyze the data stored in the CSV file. I used the example code in the library to use a csv file which creates a turtle and assigns values to it using item.
to read-turtles-from-csv
file-close-all ; close all open files
if not file-exists? "turtles.csv" [
user-message "No file 'turtles.csv' exists! Try pressing WRITE-TURTLES-TO-CSV."
stop
]
file-open "turtles.csv" ; open the file with the turtle data
; We'll read all the data in a single loop
while [ not file-at-end? ] [
; here the CSV extension grabs a single line and puts the read data in a list
let data csv:from-row file-read-line
; now we can use that list to create a turtle with the saved properties
create-turtles 1 [
if item 2 data > item 2 data ...
if item 7 data < item 8 data ...
]
]
file-close ; make sure to close the file
end
Here the csv file should not have a header row. The first row is selected for turtle 1. If we need to compare the consumer's rate for 2 levels of screen size like 13 and 13,5 , here it can do that :
If item 2 > item 3 ...
So far it works pretty well. Howeber, I need to use the header. For instance, I want to create a situation when a user chooses a number, if it is in one of the columns (is in the header), then the value gets selected. Otherwise, if the value does not exist in the header, somthing else should be done. Can I make the code recognize CSV header while working with agents?
Thanks,
OK hello all , what i am trying to do in VHDL is take an 8 bit binary value and represent it as BCD but theres a catch as this calue must be a fraction of the maximum input which is 9.
1- Convert input to Integer e.g 1000 0000 -> 128
2- Divide integer by 255 then multiply by 90 ( 90 so that i get the one's digit and the first digit after the decimal point to be all after the decimal point)
E.g 128/255*90 = 45.17 ( let this be signal_in)
3.Extract the two digits of 45 by dividing by 20 and store them as separate integers
e.g I would use something like:
LSB_int = signal_in mod 10
Then i would divide signal in by 10 hence changing it to 4.517 then let that equal to MSB_int.. (that would truncate the decimals and store 4 right)
4.Convert both the LSB_int and MSB_int to 4 digit BCD
..and i would be perfect from there...But sadly i got so much trouble...with different data types (signed unsigend std_logic_vectors)and division.So i just need help with any flaws in my thought process and things i should look out for when doing this..
I actually did over my code and thought i saved this one..but i didn't and well i still believe this solution can work i would reply with what i think was my old code...as soon as i could remember it all..
Here is my other question with my new code..(just to show i did do something..)
Convert 8bit binary number to BCD in VHDL
f I understand well, what you need is to convert an 8bit data
0-255 → 0-9000
and represent it with 4 BCD digit.
For example You want 0x80 → 4517 (BCD)
If so I suggest you a totally different idea:
1)
let convert input range in output range with a simple 8bit*8bit->16bit
(in_data * 141) and keep the 14 MSB (0.1% error)
And let say this 14 bit register is the TARGET
2)
Build a 4 digit BCD Up/Down counter (your output)
Build a 14bit Binary Up/Down counter (follower)
Supply both with the same input (reset, clk, UpDown)
(making one the shadow of the other)
3)
Compare TARGET and the binary counter
if (follower < target) then increment the counters
else if (follower > target) then decrements the counters
else nothing
4)
end