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

相关文章

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 设置容器

笔记整理—内核!启动!—kernel部分(2)从汇编阶段到start_kernel

kernel起始与ENTRY(stext),和uboot一样,都是从汇编阶段开始的,因为对于kernel而言,还没进行栈的维护,所以无法使用c语言。_HEAD定义了后面代码属于段名为.head .text的段。         内核起始部分代码被解压代码调用,前面关于uboot的文章中有提到过(eg:zImage)。uboot启动是无条件的,只要代码的位置对,上电就工作,kern

项目实战系列三: 家居购项目 第四部分

购物车 🌳购物车🍆显示购物车🍆更改商品数量🍆清空购物车&&删除商品 🌳生成订单 🌳购物车 需求分析 1.会员登陆后, 可以添加家居到购物车 2.完成购物车的设计和实现 3.每添加一个家居,购物车的数量+1, 并显示 程序框架图 1.新建src/com/zzw/furns/entity/CartItem.java, CartItem-家居项模型 /***

Open a folder or workspace... (File -> Open Folder)

问题:vscode Open with Live Server 时 显示Open a folder or workspace... (File -> Open Folder)报错 解决:不可以单独打开文件1.html ; 需要在文件夹里打开 像这样

android java.io.IOException: open failed: ENOENT (No such file or directory)-api23+权限受权

问题描述 在安卓上,清单明明已经受权了读写文件权限,但偏偏就是创建不了目录和文件 调用mkdirs()总是返回false. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_E

码蹄集部分题目(2024OJ赛9.4-9.8;线段树+树状数组)

1🐋🐋配对最小值(王者;树状数组) 时间限制:1秒 占用内存:64M 🐟题目思路 MT3065 配对最小值_哔哩哔哩_bilibili 🐟代码 #include<bits/stdc++.h> using namespace std;const int N=1e5+7;int a[N],b[N],c[N],n,q;struct QUERY{int l,r,id;}que

bash: arm-linux-gcc: No such file or directory

ubuntu出故障重装了系统,一直用着的gcc使用不了,提示bash: arm-linux-gcc: No such file or directorywhich找到的命令所在的目录 在google上翻了一阵发现此类问题的帖子不多,后来在Freescale的的LTIB环境配置文档中发现有这么一段:     # Packages required for 64-bit Ubuntu