micsig .bin file 垂直档位部分debug.

2023-12-28 15:04

本文主要是介绍micsig .bin file 垂直档位部分debug.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

上图是一个现场记录的波形,直接用micsig bin2csv转换的结果

018:
Vertical Units,V,,2E-06,0.210000003129244
Vertical Scale,0.100000001490116,,2.4E-06,0.210000003129244
Vertical Offset,12,,2.8E-06,0.210000003129244
Probe Atten,0.200000002980232,,4E-06,0.206000003069639

探针当时按200mx设置,垂直档位是100mV,

这款示波器使用8位AD,当时的实际AD值大概是这样的:

Micsig,实际垂直方向8大格。一格按照bin2csv的注释,应该是:100mV*(1/0.2) = 500mV.

所以,原配的csv2bin的读数未考虑探针实际减少的5倍关系。

f.seek(0x3c,0); vScale = struct.unpack('d', f.read(8))[0]; 这是电压档位。

其中:

0x3c位置:
>>>hex_string = '000000a09999b93f'
>>>float_val = struct.unpack('<d', bytes.fromhex(hex_string))[0]
>>> print(float_val)
0.10000000149011612 
这是垂直档位100mV

0x34位置:

>>> hex_string = '000000a09999c93f'
>>> float_val = struct.unpack('<d', bytes.fromhex(hex_string))[0]
>>> print(float_val)
0.20000000298023224

这是探针倍率,修改后的波形:

 这个值是对的。

相关的.bin2csv的代码:

# based on Micsig's offical code written by Matlab.
# python verison,
# first created at Aug18,2023
# v1.1.20231228
#    * 修改了垂直档位部分
# by Fengxh@zz
#
'''
#usage:
import sys
#micsig_binRead_fft所在的相对路径
sys.path.append("..")
import micsig_bin_read as micsig;#usage:
#打印频谱:plot_spectrum(micsig_bin_file, resample_ratio);
micsig.plot_spectrum(r'2308230111.bin', 100);
#打印波形:draw_scope_ch_wave(micsig_bin_file, resample_ratio, False);
micsig.draw_scope_ch_wave(r'2308230112.bin', 1000, False)
'''import struct #for structual read
import numpy as np #for array
import matplotlib.pyplot as plt #for plot.'''
STO1004 header. input...v.
00000000h: 11 04 18 20 01 00 00 00 60 07 0B 01 04 00 00 00 ; ... ....`.......
00000010h: 00 00 00 00 00 00 00 00 BB 02 00 00 00 00 00 00 ; ........?......
00000020h: D0 12 33 41 00 00 00 00 00 00 00 00 FE FF FF FF ; ?3A........?
00000030h: 00 00 00 00 00 00 00 00 00 00 24 40 00 00 00 00 ; ..........$@....
00000040h: 00 00 14 40 00 00 00 00 00 00 F0 3F 00 00 00 00 ; ...@......?....
00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 ; ................
00000060h: 9A 99 99 99 99 99 B9 3F 0A 0F 9A 5D F7 D6 00 40 ; 殭櫃櫃?..歖髦.@
00000070h: 6E DB B6 6D DB E6 BB 40 80 1D 2C 04 01 00 00 00 ; n鄱m坻籃€.,.....
00000080h: 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; V...............
00000090h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000a0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000b0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000c0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000d0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000e0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
000000f0h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
'''
#return (x, wave, fs)
def scope_readwave_mini(file_name):with open(file_name, 'rb') as f:f.seek(4); iWaveType = struct.unpack('i', f.read(4))[0] #offset.04 4f.seek(8); length = struct.unpack('i', f.read(4))[0] #offset0.8 4#y_scale = struct.unpack('i', f.read(4))[0] #?#x_scale = struct.unpack('i', f.read(4))[0] #?#f.seek(12, 1) f.seek(0x34,0); probeMul = struct.unpack('<d', f.read(8))[0] #?probe type? 0:curr?f.seek(0x38,0); probeMul1 = struct.unpack('f', f.read(4))[0] #?probe x,#f.seek(12, 1)#fs = struct.unpack('d', f.read(8))[0]#f.seek(4, 1)'''if iWaveType == 2:f.seek(12, 1)fft_f_step = struct.unpack('f', f.read(4))[0]f.seek(4, 1)else:f.seek(4 * 5, 1)'''#num = struct.unpack('i', f.read(4))[0]f.seek(4, 1) #the last 1: 0:head;1:current;2:end.f.seek(0x44,0); timeScale = struct.unpack('d', f.read(8))[0];  #offset0x44 8f.seek(0x3c,0); vScale = struct.unpack('<d', f.read(8))[0];print(">>>>>>vScale:%lf, probeMul=%lf"  %(vScale, probeMul))vScale = vScale /probeMul / 50DataBits = struct.unpack('i', f.read(4))[0]f.seek(256)wave = np.frombuffer(f.read(length * 4), dtype=np.int32)fs = wave.size/(14*timeScale);x = np.arange(wave.size)x = x / fs#vScale = 1;wave = wave * vScaleprint(file_name,'total pt=', len(x), 'fs=', fs); return (x, wave, fs)def draw_scope_ch_wave(filename, re_sample_ratio, isWithFFT):percentStart = 50;percentStop = 100;#read(x,wave,fs) = scope_readwave_mini(filename);#samplex = x[::re_sample_ratio]; y = wave[::re_sample_ratio];print('draw wave after sample: pt=', len(x));#截断lenPrev = len(x);startPt = int(percentStart*1.0*lenPrev/100);stopPt = int(percentStop*1.0*lenPrev/100);x = x[startPt:stopPt];y = y[startPt:stopPt];print('draw wave after slice: pt=', len(x), 'start pt=', startPt, ',stop pt=', stopPt);#plot it# 绘制波形图plt.figure(figsize=(8, 6))  # 设置画布大小,可根据需要调整plt.plot(x, y, color='blue', label='Waveform')  # 绘制波形曲线plt.xlabel('Time')  # 设置 x 轴标签plt.ylabel('Amplitude')  # 设置 y 轴标签plt.title('Waveform Plot' + '-' + filename)  # 设置图表标题plt.grid(True)  # 显示网格线plt.legend()  # 显示图例plt.show()  # 显示图形#file, ratio, start, stop
def plot_spectrum(filename, re_sample_ratio):percentStart = 50;percentStop = 100;    #read(x,wave,fs) = scope_readwave_mini(filename);#sampleprint("pre x_max = %f, fs=%f;", x[-1], fs);x = x[::re_sample_ratio]; y = wave[::re_sample_ratio];sampling_rate = fs/re_sample_ratio;signal = y;print("pos resampled(1:%d), x_max = %f, fs=%f", re_sample_ratio,  x[-1], sampling_rate);#截断lenPrev = len(x);startPt = int(percentStart*1.0*lenPrev/100);stopPt = int(percentStop*1.0*lenPrev/100);x = x[startPt:stopPt];y = y[startPt:stopPt];# 计算FFTfft_result = np.fft.fft(signal)# 移动FFT结果,使得负数频率位于两侧shifted_fft = np.fft.fftshift(fft_result)# 计算频率轴freq_axis = np.fft.fftshift(np.fft.fftfreq(len(signal), 1/sampling_rate))# 取FFT结果的绝对值spectrum = np.abs(shifted_fft)# 绘制频谱图plt.figure(figsize=(8, 4))plt.plot(freq_axis, spectrum)plt.title('Signal Spectrum')plt.xlabel('Frequency (Hz)')plt.ylabel('Amplitude')plt.grid(True)plt.show()
'''
%attachment code in Matlab version.
%% 读取micsig mini示波器波形文件,包括wav文件和bin文件
% file_name: 波形文件的文件名
% x:返回波形数据x轴;
% y:返回波形数据y轴;
function [x,wave] = scope_readwave_mini(file_name)
fid1 = fopen(file_name,'r');
wave = [];
x = [];
if(fid1>0)fseek(fid1, 16, 'bof'); iWaveType = fread(fid1, 1, 'int32');len = fread(fid1, 1, 'int32');y_scale = fread(fid1, 1, 'int32');x_scale = fread(fid1, 1, 'int32');fseek(fid1, 12, 'cof');probeType = fread(fid1, 1, 'int32');probeMul = fread(fid1, 1, 'float32');fseek(fid1, 12, 'cof');fs = fread(fid1, 1, 'float64');fseek(fid1, 4, 'cof');if(iWaveType == 2)fseek(fid1, 12, 'cof');fft_f_step = fread(fid1, 1, 'float32');fseek(fid1, 4, 'cof');elsefseek(fid1, 4*5, 'cof');endnum = fread(fid1, 1, 'int32');fseek(fid1, 4, 'cof');timeScale = fread(fid1, 1, 'float64');vScale = fread(fid1, 1, 'float64')*probeMul/50;DataBits = fread(fid1, 1, 'int32');fseek(fid1, 200, 'bof'); if(DataBits == 32)[wave,cnt] = fread(fid1, len, 'int32');else[wave,cnt] = fread(fid1, len, 'int16');end
elsereturn;
end
x = 0:cnt-1;
if(iWaveType == 2)x = x*fft_f_step;
elsex = x./fs;
end
wave = wave*vScale;
'''

 

 

这篇关于micsig .bin file 垂直档位部分debug.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/546356

相关文章

一文详解如何在Python中从字符串中提取部分内容

《一文详解如何在Python中从字符串中提取部分内容》:本文主要介绍如何在Python中从字符串中提取部分内容的相关资料,包括使用正则表达式、Pyparsing库、AST(抽象语法树)、字符串操作... 目录前言解决方案方法一:使用正则表达式方法二:使用 Pyparsing方法三:使用 AST方法四:使用字

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre

Mysql删除几亿条数据表中的部分数据的方法实现

《Mysql删除几亿条数据表中的部分数据的方法实现》在MySQL中删除一个大表中的数据时,需要特别注意操作的性能和对系统的影响,本文主要介绍了Mysql删除几亿条数据表中的部分数据的方法实现,具有一定... 目录1、需求2、方案1. 使用 DELETE 语句分批删除2. 使用 INPLACE ALTER T

Java实现将byte[]转换为File对象

《Java实现将byte[]转换为File对象》这篇文章将通过一个简单的例子为大家演示Java如何实现byte[]转换为File对象,并将其上传到外部服务器,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言1. 问题背景2. 环境准备3. 实现步骤3.1 从 URL 获取图片字节数据3.2 将字节数组

Goland debug失效详细解决步骤(合集)

《Golanddebug失效详细解决步骤(合集)》今天用Goland开发时,打断点,以debug方式运行,发现程序并没有断住,程序跳过了断点,直接运行结束,网上搜寻了大量文章,最后得以解决,特此在这... 目录Bug:Goland debug失效详细解决步骤【合集】情况一:Go或Goland架构不对情况二:

解决JavaWeb-file.isDirectory()遇到的坑问题

《解决JavaWeb-file.isDirectory()遇到的坑问题》JavaWeb开发中,使用`file.isDirectory()`判断路径是否为文件夹时,需要特别注意:该方法只能判断已存在的文... 目录Jahttp://www.chinasem.cnvaWeb-file.isDirectory()遇

VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virtual disk”问题

《VMWare报错“指定的文件不是虚拟磁盘“或“Thefilespecifiedisnotavirtualdisk”问题》文章描述了如何修复VMware虚拟机中出现的“指定的文件不是虚拟... 目录VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virt

提示:Decompiled.class file,bytecode version如何解决

《提示:Decompiled.classfile,bytecodeversion如何解决》在处理Decompiled.classfile和bytecodeversion问题时,通过修改Maven配... 目录问题原因总结问题1、提示:Decompiled .class file,China编程 bytecode

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

lvgl8.3.6 控件垂直布局 label控件在image控件的下方显示

在使用 LVGL 8.3.6 创建一个垂直布局,其中 label 控件位于 image 控件下方,你可以使用 lv_obj_set_flex_flow 来设置布局为垂直,并确保 label 控件在 image 控件后添加。这里是如何步骤性地实现它的一个基本示例: 创建父容器:首先创建一个容器对象,该对象将作为布局的基础。设置容器为垂直布局:使用 lv_obj_set_flex_flow 设置容器