混合信号系统中模拟地数字地处理方法探讨

Q. I’ve read your data sheets and application notes and also attended
your seminars, but I’m still confused about how to deal with analog
(AGND) and digital (DGND) ground pins on an ADC. Your data
sheets usually say to tie the analog and digital grounds together at
the device, but I don’t want the ADC to become my system’s star
ground point. What do I do?
A. First of all, don’t feel bad that you are confused about what to
do with your analog and digital grounds. So are lots of folks!
Much of the confusion comes from the labeling of the ADC
ground pins in the first place. The pin names, AGND and
DGND, refer to what’s going on inside the component itself
and do not necessarily imply what you should do with them
externally. Let me explain.
Inside an IC that has both analog and digital circuits, such as
an ADC, the grounds are usually kept separate to avoid
coupling digital signals into the analog circuits. The diagram
shows a simple model of an ADC. There is really nothing the
IC designer can do about the wirebond inductance and
resistance associated with connecting the pads on the chip to
the package pins. The rapidly changing digital currents produce
a voltage at point B which will inevitably couple into point A
of the analog circuits through the stray capacitance. It’s the IC
designer’s job to make the chip work in spite of this. However,
you can see that in order to prevent further coupling, the AGND
and DGND pins should be joined together externally to the
same low impedance ground plane with minimum lead lengths.
Any extra external impedance in the DGND connection will
cause more digital noise to be developed at point B; it will, in
turn, couple more digital noise into the analog circuit through
the stray capacitance. Though an extremely simple model, this
serves to illustrate the point.
并未回答如何把AGND和DGND和电源的地相连。

Q. O.K., you’ve told me to join the AGND and DGND pins of the IC
together to the same ground plane—but I am maintaining separate
analog and digital ground planes in my system. I want them tied
together only at one point: the common point where the power supply
returns are all joined together and connected to chassis ground. Now
what do I do?

A. If you have only one data converter in your system, you could
actually do what the data sheet says and tie your analog and
digital ground systems together at the converter. Your system
star ground point is now at the data converter. But this may be
extremely undesirable, unless you initially planned your system
with this thought in mind. If you have several data converters
located on different PCBs, the concept breaks down, because
the analog and digital ground systems are joined at each
converter on a number of PCBs. This is a perfect invitation for
ground loops!

在多卡系统中,不能使用星形接地,那应该使用何种方式呢?
Q. I think I’ve figured it out! If I must join the AGND and DGND
pins together at the device, and I want to maintain separate system
analog and digital grounds, I tie both AGND and DGND to either
the analog ground plane or the digital ground plane on the PCB,
but not both. Right? Now, which one should it be, since the ADC is
both an analog and a digital device?
A. Correct! Now, if you connect the AGND and DGND pins
both to the digital ground plane, your analog input signal is
going to have digital noise summed with it, because it is
probably single-ended and referenced to the analog ground
plane.
Q. So the right answer is to connect both AGND and DGND pins to
the analog ground plane? But doesn’t this inject digital noise on my
nice quiet analog ground plane? And isn’t the noise margin of the
output logic degraded because it now referenced to the analog ground
plane, and all the other logic is referenced to the digital ground plane?
I plan to run the ADC outputs to a backplane tristate data bus
which is going to be pretty noisy to begin with so I think I need all
the noise margin I can get.
A. Well, nobody ever said life was easy or fair! You have reached
the right conclusion by traveling a rocky road, but the problems
you suggest—digital noise on your analog ground plane and
reduced noise margin on your ADC outputs—really aren’t as
bad as they seem; they can be overcome. It is clearly better to
let a few hundred millivolts corrupt the digital interface than
to apply the same corrupting signal to the analog input where
the least-significant-bit for a 16-bit, 10-V-input-range ADC is
only 150 mV! First of all, the digital ground currents on DGND
pins can’t really be that bad, or they would have degraded the
internal analog parts of the ADC in the first place! If you bypass
the power pins of the ADC to the analog ground plane, using
a good-quality high-frequency ceramic capacitor for high
frequency noise (say 0.1 mF), you will isolate these currents to
a very small region around the IC, and they will have minimal
effect on the rest of your system.
You will incur some reduction in digital noise margin, but it is
usually acceptable with TTL or CMOS logic if it’s less than a
few hundred millivolts or so. If your ADC has single-ended
ECL outputs, you may want to put a push-pull gate on each
digital output—i.e., one with both true and complementary
outputs. Tie the grounds of this gate package to the analog
ground plane and connect the logic signals differentially across
the interface. Use a differential line receiver at the other end
which is grounded to the digital ground plane. The noise
between the analog and digital ground planes is now commonmode—
most of it will be rejected at the output of the differential
line receiver. You could use the same technique with TTL or
CMOS, but there is usually enough noise margin not to require
differential transmission techniques.
However, one thing you said troubles me greatly. In general, it
is unwise to connect the ADC outputs directly to a noisy data
bus. The bus noise may couple back into the ADC analog input
through the stray internal capacitance—which may range from
0.1 to 0.5 pF. It is much better to connect the ADC outputs
directly to an intermediate buffer latch located close to the
ADC. The buffer latch is grounded to your digital ground plane,
so its output logic levels are now compatible with those of the
rest of your system.

Q. I think I understand now, but why on earth didn’t you just call all
the ground pins of your ADC AGND in the first place; then none of
this would have come up in the first place?
A. Perhaps. But what if the incoming-inspection person connects
an ohmmeter between these pins and finds out that they are
not actually connected together inside the package? The whole
lot will probably be rejected—and the IC may be blown!
Furthermore, there is a tradition associated with ADC data
sheets which says we must label the pins to indicate their true
function, not what we would like them to be.
Q. O. K. Now, here comes a question I’ve been saving as your ultimate
test! I have a colleague who designed a system with separate analog
and digital ground systems. My colleague says that, with the ADC’s
AGND pin connected to the analog ground plane and the DGND
pin connected to the digital ground plane, the system is working
fine! How do you explain this?
A. First of all, just because a practice is not recommended doesn’t
necessarily mean you can’t get away with it some of the time
and thereby be lulled into a false sense of security. (This is one
of the lesser-known of Murphy’s Laws). Some ADCs are less
sensitive to external noise between the AGND and DGND
pins, and it may be that your colleague picked one of those by
accident. There could be other explanations—which would
require that we explore your colleague’s definition of “working
fine”—but the point is that the ADC’s specifications are not
guaranteed by the manufacturer under those operating
conditions. With a complex component like an ADC, it is
impossible to test the device under all possible operating
circumstances, especially those which aren’t recommended in
the first place! Your friend got lucky this time, but you can be
sure that Murphy’s law will ultimately catch up with him (or
her) if this practice is continued in future system designs.
Q. I think I understand the ADC grounding philosophy now, but what
about DACs?
A. The same philosophy applies. The DAC’s AGND and DGND
pins should be tied together and connected to the analog
ground plane. If the DAC has no input latches, the registers
driving the DAC should be referenced and grounded to the analog ground plane to prevent digital noise from coupling
into the analog output.
Q. What about mixed-signal chips which contain ADCs, DACs, and
DSPs such as your ADSP-21msp5O voiceband processor?
A. The same philosophy applies. You should never think of a
complex mixed-signal chip, such as the ADSP-21msp50, as
being only a digital chip! The same guidelines we’ve just been
discussing should be applied. Even though the effective
sampling rate of the 16-bit sigma-delta ADC and DAC is only
8 ksps, the converters operate at an oversampling frequency of
1 MHz. The device requires an external 13-MHz clock, and
an internal 52- MHz processor clock is generated from it with
a phase-locked loop. So you see, successful application of this
device requires an understanding of design techniques for both
precision- and high-speed circuits.
Q. What about the analog and digital power-supply requirements of
these devices? Should I buy separate analog and digital power supplies
or use the same supply?
A. This really depends on how much noise is on your digital
supply. The ADSP-21msp50, for example, has separate pins
for the +5- V analog supply and the +5-V digital supply. If you
have a relatively quiet digital supply, you can probably get away
with using it for the analog supply too. Be sure to properly
decouple each supply pin at the device with a 0.1-mF ceramic
capacitor. Remember to decouple to the analog ground plane,
not the digital ground plane! You may also want to use ferrite
beads for further isolation. The diagram below shows the proper
arrangement. A much safer solution is to use a separate +5-V
analog supply. You can generate the +5 V from a quiet +15-V
or +12-V supply using a three-terminal regulator, if you can
tolerate the extra power dissipation.

MathJax入门

1.安装 MathJax-LaTex 插件

直接在 wordpress 插件中,搜索并安装 MathJax-LaTeX,不过在网页里面插入latex代码片段后,还需要服务器对它进行解析,由于解析服务器在墙外,如果个人网站在国内那么需要安装本地解析服务

2. 安装本地 MathJax 服

下载 MathJax

wget https://github.com/mathjax/MathJax/archive/master.zip

解压 MathJax

unzip MathJax

将 MathJax 文件夹整个移动到 wordpress 的 mathjax-latex 插件目录下

sudo mv MathJax YOUR_WORDPRESS_PATH/wp-content/plugins/mathjax-latex/

更改 MathJax 所有者为 nginx

sudo -R nginx:nginx YOUR_WORDPRESS_PATH/wp-content/plugins/mathjax-latex/

测试 MathJax 是否安装成功

访问 http://www.YOUR_DOMAIN.com/wp-content/plugins/mathjax-latex/MathJax/test/

Mathjax语法总结

在wordpress中插入mathjax代码片段

\(formula inserted here\)

希腊字母
α \alpha          β \beta
γ \gamma       δ \delta
ϵ \epsilon        ζ \zeta
η \eta               θ \theta
ι \iota               κ \kappa
λ \lambda        μ \mu
ν \nu                 ξ \xi
π \pi                  ρ \rho
σ \sigma           τ \tau
υ \upsilon        ϕ \phi
χ \chi                ψ \psi
ω \omega

  • 如果要大写希腊字母,则首字母大写即可,如\Gamma显示为Γ \GammaΓ
  • 有的希腊字母有几种变体,则用var区分,如\varGamma

上标^,下标_

在公示中包含文本\text{plain text insert here}

在公式中引入空格或者间隔 \ \, \;

……

参考:

  1. Mathjax与LaTex公式简介 – 林大勇 – 博客园 (cnblogs.com)
  2. Mathjax语法总结_ajacker的博客-CSDN博客_mathjax语法

 

Ubuntu 安装 VSFPTD

  1. 安装:sudo apt-get install vsftpd
  2. 修改配置文件:sudo vim /etc/vsftpd.conf
  • #禁止匿名访问 anonymous_enable=NO
  • #接受本地用户 local_enable=YES
  • #允许上传 write_enable=YES
  • #用户只能访问限制的目录 chroot_local_user=YES
  • #如果使用主动模式,下面几行可以不配置
  • #使用被动模式
  • pasv_enable=YES
  • #被动模式下端口设置
  • pasv_min_port=1024
  • pasv_max_port=1048
  • pasv_address=你的访问IP(服务器外网IP)
  1.  创建FTP用户:sudo useradd -d /home/www -M ftpuser;  设置密码:sudo passwd ftpuser
  2. 修改/etc/pam.d/vsftpd文件:sudo vim /etc/pam.d/vsftpd 注释掉 #auth required pam_shells.so
  3. 关于ftp的根目录,例如www目录,vsftpd不允许ftp根目录有可执行权限,应该设置其权限为544,即rw-r-x-r-x 目录的拥有者设为www:www
  4.  在ftp根目录www下创建文件夹,例如data,设置其权限为644,ftp任何上传只能到此目录下

Matlab 小结

matlab符号计算

1> syms Vs Rs Ub1 Ub2 Ub3 Uo rbe1 Cbe1 rbe2 Cbe2 RL Cc S gm1 gm2;     //定义符号变量(常量)

2> eq1 = (Vs-Ub1)/Rs + (Ub3-Ub1)*S*Cc == (Ub1-Ub2)*(1/rbe1+S*Cbe1);  eq2 = (Ub1-Ub2)*(1/rbe1+S*Cbe1+gm1) == Ub2*(1/rbe2+S*Cbe2);  eq3 = (Ub3-Ub1)*S*Cc + gm1*(Ub1-Ub2) + (Ub3-Uo)*(1/rbe2+S*Cbe2) == 0;  eq4 = (Ub3-Uo)*(1/rbe2+S*Cbe2) + gm2*(Ub3-Uo) == Uo/RL + gm2*Ub2;   //联立方程组

3>sol = solve(eq1,eq2,eq3,eq4,Ub1,Ub2,Ub3,Uo);  //指定Ub1,Ub2,Ub3,Uo为未知量,求解eq1,eq2,eq3,eq4方程组,其中输出量sol为结构体类型

4>pretty(sol.Uo)  //让输出结果易于阅读

matlab符号表达式代入(部分)常量求数值解

1> f1 = subs(sol.Uo,[Rs,rbe1,Cbe1,rbe2,Cbe2,gm1,gm2],[8.2e3,1e2,1.59e-9,1,4e-6,1,100])   //代入部分值求数值表达式

2> digits(4)   //指定整数小数位数,简化最终表达式

3> f2=vpa(f1) //输出带部分符号变量的简化表达式

matlab分离符号表达式分子分母

1> [n,d] = numden(sol.Vo);  //N:numerator 分子;D:denominator分母

2> poles = solve(d == 0,S);  //求分母的根,即系统极点

V2ray部署

1.安装,用脚本安装是最方便的。网络上有网友提供了各具特色的脚本。不过有些脚本的提示语言是中文,不但要求VPS安装了中文语言支持,也需要终端支持中文显示。譬如Bandwagonhost的网页终端就不支持中文显示,谷歌云的网页终端是支持的。

bash <(curl -s -L https://233yes.com/v2ray.sh)
安装时候要注意记下v2ray的监听端口号,这个端口信息会写入到nginx配置文件中,当然,你也可以在/etc/v2ray/config.json里面找到这个端口号

2.配置WS+TLS+CDN 用上面的脚本配置WS+TLS比较简单,特别是如果你没有安装网页服务器的话,可以选择让脚本自动帮你安装Caddy做网页代理。不过我的VPS上已经有了LNMP环境,所以选择自己配置,以下假设我用域名test.top作为V2ray访问的域名。

添加vhost: lnmp vhost add 之后按提示输入域名,并添加SSL证书(添加证书之前要修改好域名的地址解析,将解析指向你的VPS服务器,否则SSL添加会失败)

注册CloudFlare账户,添加域名test.top,登陆域名提供商网站,修改DNS解析服务器,指向CloudFlare的DNS解析服务器。

修改/usr/local/nginx/conf/vhost/www.test.top.conf文件,在server{ listen 443 ........}这一节里面添加如下内容

location / {
proxy_redirect off; //可要可不要
proxy_pass http://127.0.0.1:8388; //也可以写成 http://localhost:8388,其中8388为V2ray监听端口号
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}

3.客户端配置

不熟悉脚本的话最好选择带图形界面的客户端,如V2rayN,openwrt的SSR Plus+以及 V2raypro等。配置很简单,协议选择"WS",端口"443",服务器填"test.top",路径填"/" 并勾选TLS。

 

M4800更换显卡之后修改显卡驱动INF信息

M4800的显卡从K1100M改为K2000M,虽然提升很少,不过喜欢折腾的人还是不放过这个机会。

硬件安装好之后就是安装显卡驱动了,在Nvidia下载原版驱动一般来讲是无法装上去的,因为显卡和CPU的组合不在驱动的INF文件里面。解决思路就是手动加入组合信息。教程在此:How to Modify NVIDIA Notebook Driver .INF Files

首先找到硬件ID号,打开设备管理器,在未安装驱动的显卡设备上右键->属性->详细信息->硬件ID,记录下硬件ID号,如,

PCI\VEN_10DE&DEV_0FFB&SUBSYS_15CC1028 

其中:0FFB对应GPU型号(K2000M),15CC代表笔记本具体型号(M4800),1028代表制造商编码(DELL)

 

然后在NVIDIA_VideoCard_Driver_416.30_revised\Win10_64\International\Display.Driver文件夹里面找到对应笔记本品牌商的INF文件。对应关系如下,

.inf files by manufacturer
Acer & Gateway = nvaci.inf
Asus = nvami.inf
Apple = nvaoi.inf
Compal = nvcti.inf
Clevo (Sager & other re-brands) = nvcvi.inf
Dell & Alienware = nvdmi.inf
Fujitsu = nvfmi.inf
HP = nvbli.inf
HP = nvhmi.inf
LG = nvloi.inf
Lenovo = nvlti.inf
MSI = nvmii.inf
NEC = nvqni.infSiemens = nvfui.inf
Sony = nvszci.inf
Toshiba Qosmio = nvtdi.inf
Toshiba = nvtsi.inf

打开文件之后查找字符串“NVIDIA_Devices”,在我的驱动里面可以找到三段如下信息(中间信息太多在此省略),

[Manufacturer]
%NVIDIA_A% = NVIDIA_Devices,NTamd64.10.0,NTamd64.10.0…14310,NTamd64.10.0,NTamd64.10.0…16299

[NVIDIA_Devices.NTamd64.10.0…14310]
%NVIDIA_DEV.0FF6.05CC.1028% = Section032, PCI\VEN_10DE&DEV_0FF6&SUBSYS_05CC1028
…….
%NVIDIA_DEV.0FFB.15CC.1028% = Section040, PCI\VEN_10DE&DEV_0FFB&SUBSYS_15CC1028

[NVIDIA_Devices.NTamd64.10.0…16299]
%NVIDIA_DEV.0FF6.05CC.1028% = Section032, PCI\VEN_10DE&DEV_0FF6&SUBSYS_05CC1028
…..
%NVIDIA_DEV.0FFB.15CC.1028% = Section040, PCI\VEN_10DE&DEV_0FFB&SUBSYS_15CC1028

[NVIDIA_Devices.NTamd64.10.0]
%NVIDIA_DEV.0FF6.05CC.1028% = Section031, PCI\VEN_10DE&DEV_0FF6&SUBSYS_05CC1028
…..
%NVIDIA_DEV.0FFB.15CC.1028% = Section040, PCI\VEN_10DE&DEV_0FFB&SUBSYS_15CC1028

找到字段中包含相同的GPU型号和电脑制造商编码的section,复制这一条记录,将其中的笔记本型号信息修改为硬件ID里面的型号,并将此条记录添加到字段的末尾或者任何位置。

查找字段“Strings”,并添加记录,

NVIDIA_DEV.0FFB.15CC.1028 = “NVIDIA Quadro K2000M”

等号前面的信息来源于设备管理器。

最后重要的一步:禁止微软驱动签名检查

 

Ubuntu 18.04 安装以及美化(转载)

1.安装:http://forum.ubuntu.org.cn/viewtopic.php?f=77&t=485693

前提:保留计算机的UEFI启动模式,基于UEFI平行引导Win10和Ubuntu 16.04。

第一步,下载Ubuntu X64版本的ISO,使用支持UEFI启动的刻录工具刻录到U盘上。我用的是rufus2.17
注意:刻录的时候,启动方式选择“UEFI+MBR”模式,文件系统默认单元大小选择4K。另外,我用ISO刻录方式U盘启动Ubuntu失败,后来改用dd刻录方式成功启动。在开始刻录之前rufus有相关提示。
第二步,在win10下使用磁盘管理工具,预留出给Ubuntu的磁盘空间,不用分区,更不用格式化不建议在Ubuntu安装程序中才进行这一步骤。另外建议至少给Ubuntu留出40G磁盘空间。
第三步,重启windows,开机进入BIOS,关闭安全启动模式(Secure Boot)。重新启动时按选择启动项的快捷键,比如我这里是F11,然后选择从U盘启动。
第四步,进入Ubuntu试用环境,点击桌面上的安装Ubuntu,开始安装。

安装注意事项:
1. 建议给Ubuntu三个分区,第一个分区,swap交换分区;第二个分区,/,第三个分区,/home。
2.在分区这一步,注意看最下面的引导器安装选项,选择下拉菜单中包含“windows boot manager”那一项。选择了这一项,意思是将Ubuntu引导器与Windows引导器并列安装到硬盘的UEFI分区中。这样安装完成后,计算机即可正常以UEFI方式启动并引导Windows和Ubuntu,而不对计算机产生额外的影响。默认的顺序是Windows在前,Ubuntu在后。默认进入Win10,如果要进Ubuntu,需要在开机时按下选择启动项的快捷键,然后选择Ubuntu。
3.网上有些教程过于啰嗦,甚至提到额外建立新的UEFI分区,没有必要。安装了win10 x64的系统默认都是以UEFI方式启动,UEFU分区本来就有,一般是个200M左右的分区。
4.如果你想将Ubuntu设为默认启动,只需到BIOS相关设置中修改UEFI启动的系统顺序即可。千万别去纠缠什么/boot和grub的问题,这种模式下Win和Ubuntu的启动相互独立,是平行关系,都归UEFI系统管理,要改也是改UEFI层面的设置。

2. 美化:https://www.k-xzy.xyz/archives/5577

一. 安装Gnome Tweaks sudo apt install gnome-tweaks

二. 安装Adapta主题

sudo add-apt-repository ppa:tista/adapta

sudo apt-get update

sudo apt install adapta-gtk-theme

安装完成之后打开Tweaks,设置主题为Adapta-nokto-eta

三. 安装Deepin图标,首先下载Deepin-icons,解压之后复制到 /usr/share/icons/: sudo cp -r ./Deepin/ /usr/share/icons/

四. 安装Gnome-extensions

我们不难发现Ubuntu 18.04左侧栏非常的丑

这是因为Ubuntu团队为了使Gnome更像他们的Unity而设计的

真™是画蛇添足

我们这时候就需要一个叫“Dash to dock”的Gnome扩展来帮我们解决问题了。

首先先安装装扩展必需的一个支持:

sudo apt install chrome-gnome-shell

(实际上这个东西和chrome没有任何关系)

然后火狐打开:https://extensions.gnome.org/

页面顶部会提示你安装一个浏览器插件,点击安装即可。

装完插件以后在网页里搜索“Dash to dock”,打开第一个,然后页面右上角有个滑块“OFF”,点一下变成“ON”即可。

然后可以到Tweaks->扩展里设置这个扩展。

(顺带一提,我后面卸载了这个扩展,但是Dock依然还在这里而且貌似更美观了我也不知道发生了什么)

另外还有一个非常重要的,就是上文提到的“Shell”——Gnome顶栏设置。

你需要安装一个叫做“User themes”的插件,安装该插件启用后即可设置“Shell”(Adapta主题带有配套的Shell)

除了这两个扩展,我还推荐一些:

名称 功能
Hide top bar 隐藏顶栏,可设置为平时隐藏鼠标放上去时显示顶栏
Gravatar 把你的Ubuntu用户头像设置成你的Gravtar
Openweather 在顶栏添加一个天气预报

Linux脚本-查找指定后缀的文件

最近下了很多音乐专辑,有.flac, .wav, .ape等,还好它们都关联一个同名的.cue文件。不过它们暂时都放在同一文件夹里面,就想着能否用脚本把每一张专辑放到各自文件夹里面。Window脚本我是不会写,Linux脚本也是才摸着门,幸好网络上资源丰富,于是有了以下的脚本

for f in *.cue do \

FILE=“”${f#*.}“”;\     # get all after last delimiter ‘.’

mkdir “FILE”;\

mv “FILE.*” “FILE”;\

done

 

参考资料

1.Loop over all files in all sub-directories

 

# show all .fasta files in all sub-directories of folder ‘assembly’
find assembly/ -name "*.fasta"
assembly/projectA/run1.fasta
assembly/projectA/run2.fasta
assembly/projectB/run1.fasta
assembly/projectB/run2.fasta
assembly/final.fasta

# search for ‘plasmid’ in all fasta files (run command  grep  on all files) in folder ‘assembly’

find assembly/ -name "*.fasta" -exec grep plasmid {} \;

# compress all .fasta files using gzip, include all sub-directories of folder ‘assembly’

find assembly/ -name "*.fasta" -exec gzip {} \;

General

find/path/-name  filter files   -exec   run command         {} \;  -name  # filter filenames
  -exec  # run command

   {}    # on each file
   \;# pass files one by one to the command
————————————————————————————————————

2.STRING SPLIT

Split string of variable ${FILE} by delimiter ‘_

# filename example

FILE=SRR01234_mapped_ecoli.txt

echo ${FILE%%_*}  # get all before first delimiter ‘_’
SRR01234

echo ${FILE%_*}   # get all before last delimiter ‘_’
SRR01234_mapped

echo ${FILE##*_
# get all after last delimiter ‘_’
ecoli.txt

echo ${FILE#*_}  
# get all after first delimiter ‘_’
mapped_ecoli.txt

Basename examples

# get filename without path prefix
F=/path/to/sample/SRR01234_mapped_ecoli.txt
FILE=`basename ${F}` 
echo ${FILE}
SRR01234_mapped_ecoli.txt


# get filename without path prefix and without extension
F=/path/to/sample/SRR01234_mapped_ecoli.txt
FILENAME=`basename ${F%%.*}`  # get all before first ‘.’ (remove file ending)
echo ${FILENAME}
SRR01234_mapped_ecoli
# get sample-ID
F=/path/to/sample/SRR01234_mapped_ecoli.txt
SAMPLE=`basename ${F%%_*}`  # get all before ‘_’
echo ${SAMPLE}
SRR01234

# get speciesname “ecoli”

F=/path/to/sample/SRR01234_mapped_ecoli.txt
FILENAME=`basename ${F%%.*}`  # get all before first ‘.’ (remove file ending)
SPECIES=${FILENAME##*_}  # get all after last delimiter ‘_’
echo ${SPECIES}
ecoli

Alternative use: cut

# get first word (-f 1) based on delimiter ‘_’
FILE=SRR01234_mapped_ecoli.txt

SAMPLE=$( cut -d '_' -f 1 - <<< "${FILE}" )
echo ${SAMPLE}
SRR01234
—————————————————————————————————————————————

3.Loop over list of files

Run a command on each file

do something (echo) with all .txt files
for f in *.txt;  do echo ${f}; done;
same, but using a pipe (reading from standard input), and a while-loop
ls *.txt | while read f; do echo ${f}; done;
do something with a small set of files 
for f in file1.txt file2.txt file3.txt; do echo ${f}; done;

file1.txt
file2.txt
file3.txt

same, but separately defined list of files
filelist="file1.txt file2.txt file3.txt"
for f in ${filelist}; do echo ${f}; done;
reading list of files from file ‘filelist.txt’ (for larger number of files)
ls *.csv > filelist.txt    # define your list of files
for f in `cat filelist.txt`; do echo ${f}; done;
if a line may include spaces better use a while loop:
cat filelist.txt | while read LINE; do echo "${LINE}"; done

loop over filenames without extension, see → basename string split
for f in Data/*.txt; do FILENAME=${f%%.*};  echo ${FILENAME};  done;

Data/fileA .txt
Data/fileB .txt

loop over filenames without extension and without path prefix
for f in Data/*.txt ; do FILENAME=`basename ${f%%.*}`; echo ${FILENAME}; done

Data/ fileA .txt
Data/ fileB .txt

exclude samples that are already processed
process input files Data/*.fastq only if result-files Result/*.txt does not exist
for f in Data/*.fastq; do \
  SAMPLE=`basename ${f%%.*}`; \
  if [ ! -f Results/${SAMPLE}.txt ]; then \
     echo "processing sample ${SAMPLE}"; \
     # do something \
  fi; \
done

# do something 10 times
for N in {1..10}; do \
   echo ${N}; \
done

 

# double loop over a series of numbers and letters
for N in {1..5}; do
  for S in {A..C}; do
    echo ${N} ${S};
  done;
done;
1 A
1 B
1 C
2 A
2 B
2 C
°°°
general use of:

  if then else  (-f  check if normal file)
if [ -f /path/to/${SAMPLE} ];
then

# do something if file exist

else
   # do something if file does not exist

fi

Examples

search string ‘ABC’ in all text files
for f in *.txt ; do echo --${f}-- ; grep "ABC" ${f} ; done
copy all files in filelist.txt to a newDir/
ls *.csv > filelist.txt    # define your list of files
mkdir newDir  # create the new directory
for f in `cat filelist.txt`; do echo copying ${f}; cp ${f} newDir/; done;
add path if files are not located in working directory
for f in `cat filelist.txt`; do echo copying ${f}; cp path/to/files/${f} newDir/; done;

4. 单引号双引号区别

1)、单引号属于强引用,它会忽略所有被引起来的字符的特殊处理,被引用起来的字符会被原

封不动的使用,唯一需要注意的点是不允许引用自身;

 

2)、双引号属于弱引用,它会对一些被引起来的字符进行特殊处理,主要包括以下情况:

1:$加变量名可以取变量的值 ,比如:

[root@localhost ~]# echo ‘$PWD’
$PWD  

[root@localhost ~]# echo “$PWD”

/root

2:反引号和$()引起来的字符会被当做命令执行后替换原来的字符,比如:

[root@localhost ~]# echo ‘$(echo hello world)’
$(echo hello world)
[root@localhost ~]# echo “$(echo hello world)”
hello world

[root@localhost ~]# echo ‘`echo hello world`’
`echo hello world`
[root@localhost ~]# echo “`echo hello world`”
hello world

3:当需要使用字符($  `  ”  \)时必须进行转义,也就是在前面加\ ;

[root@localhost ~]# echo ‘$ ` ” \’
$ ` ” \
[root@localhost ~]# echo “\$ \` \” \\”
$ ` ” \

 

What is dither?

To dither means to add noise to our audio signal. Yes, we add noise on purpose, and it is a good thing.

How can adding noise be a good thing??!!!

We add noise to make a trade. We trade a little low-level hiss for a big reduction in distortion. It’s a good trade, and one that our ears like.

The problem

The problem results from something Nyquist didn’t mention about a real-world implementation—the shortcoming of using a fixed number of bits (16, for instance) to accurately represent our sample points. The technical term for this is “finite wordlength effects”.

At first blush, 16 bits sounds pretty good—96 dB dynamic range, we’re told. And it is pretty good—if you use all of it all of the time. We can’t. We don’t listen to full-amplitude (“full code”) sine waves, for instance. If you adjust the recording to allow for peaks that hit the full sixteen bits, that means much of the music is recorded at a much lower volume—using fewer bits.

In fact, if you think about the quietest sine wave you can play back this way, you’ll realize it’s one bit in amplitude—and therefore plays back as a square wave. Yikes! Talk about distortion. It’s easy to see that the lower the signal levels, the higher the relative distortion. Equally disturbing, components smaller than the level of one bit simply won’t be recorded at all.

This is where dither comes in. If we add a little noise to the recording process… well, first, an analogy…

An analogy

Try this experiment yourself, right now. Spread your fingers and hold them up a few inches in front of one eye, and close the other. Try to read this text. Your fingers will certainly block portions of the text (the smaller the text, the more you’ll be missing), making reading difficult.

Wag your hand back and forth (to and fro!) quickly. You’ll be able to read all of the text easily. You’ll see the blur of your hand in front of the text, but definitely an improvement over what we had before.

The blur is analogous to the noise we add in dithering. We trade off a little added noise for a much better picture of what’s underneath.

Back to audio

For audio, dithering is done by adding noise of a level less than the least-significant bit before rounding to 16 bits. The added noise has the effect of spreading the many short-term errors across the audio spectrum as broadband noise. We can make small improvements to this dithering algorithm (such as shaping the noise to areas where it’s less objectionable), but the process remains simply one of adding the minimal amount of noise necessary to do the job.

An added bonus

Besides reducing the distortion of the low-level components, dither lets us hear components below the level of our least-significant bit! How? By jiggling a signal that’s not large enough to cause a bit transition on its own, the added noise pushes it over the transition point for an amount statistically proportional to its actual amplitude level. Our ears and brain, skilled at separating such a signal from the background noise, does the rest. Just as we can follow a conversation in a much louder room, we can pull the weak signal out of the noise.

Going back to our hand-waving analogy, you can demonstrate this principle for yourself. View a large text character (or an object around you), and view it by looking through a gap between your fingers. Close the gap so that you can see only a portion of the character in any one position. Now jiggle your hand back and forth. Even though you can’t see the entire character at any one instant, your brain will average and assemble the different views to put the characters together. It may look fuzzy, but you can easily discern it.

When do we need to dither?

At its most basic level, dither is required only when reducing the number of bits used to represent a signal. So, an obvious need for dither is when you reduce a 16-bit sound file to eight bits. Instead of truncating or rounding to fit the samples into the reduced word size—creating harmonic and intermodulation distortion—the added dither spreads the error out over time, as broadband noise.

But there are less obvious reductions in wordlength happening all the time as you work with digital audio. First, when you record, you are reducing from an essentially unlimited wordlength (an analog signal) to 16 bits. You must dither at this point, but don’t bother to check the specs on your equipment—noise in your recording chain typically is more than adequate to perform the dithering!

At this point, if you simply played back what you recorded, you wouldn’t need to dither again. However, almost any kind of signal processing causes a reduction of bits, and prompts the need to dither. The culprit is multiplication. When you multiply two 16-bit values, you get a 32-bit value. You can’t simply discard or round with the extra bits—you must dither.

Any for of gain change uses multiplication, you need to dither. This means not only when the volume level of a digital audio track is something other than 100%, but also when you mix multiple tracks together (which generally has an implied level scaling built in). And any form of filtering uses multiplication and requires dithering afterwards.

The process of normalizing—adjust a sound file’s level so that its peaks are at full level—is also a gain change and requires dithering. In fact, some people normalize a signal after every digital edit they make, mistakenly thinking they are maximizing the signal-to-noise ratio. In fact, they are doing nothing except increasing noise and distortion, since the noise level is “normalized” along with the signal and the signal has to be redithered or suffer more distortion. Don’t normalize until you’re done processing and wish to adjust the level to full code.

Your digital audio editing software should know this and dither automatically when appropriate. One caveat is that dithering does require some computational power itself, so the software is more likely to take shortcuts when doing “real-time” processing as compared to processing a file in a non-real-time manner. So, an applications that presents you with a live on-screen mixer with live effects for real-time control of digital track mixdown is likely to skimp in this area, whereas an application that must complete its process before you can hear the result doesn’t need to.

Is that the best we can do?

If we use high enough resolution, dither becomes unnecessary. For audio, this means 24 bits (or 32-bit floating point). At that point, the dynamic range is such that the least-significant bit is equivalent to the amplitude of noise at the atomic level—no sense going further. Audio digital signal processors usually work at this resolution, so they can do their intermediate calculations without fear of significant errors, and dither only when its time to deliver the result as 16-bit values. (That’s OK, since there aren’t any 24-bit accurate A/D convertors to record with. We could compute a 24-bit accurate waveform, but there are no 24-bit D/A convertors to play it back on either! Still, a 24-bit system would be great because we could do all the processing and editing we want, then dither only when we want to hear it.)

字词累积二

dà diāo
大貂

唐 代侍中的别称。 宋 孙光宪 《北梦琐言》卷四:“ 浙江 周寳 侍中 博陵 崔夫人 ,乃 乾符 中时相之姊妹也。少为女道士,或云寡而冠帔,自幽独焉。大貂素以豪侠闻,知 崔 有容色,乃踰垣而窃之。” 宋 洪迈 《容斋四笔·官称别名》:“ 唐 人好以它名标榜官称……侍中为大貂,散骑常侍为小貂。”

揲 dié

(1) 折叠

闲揲舞衣归未得,夜来砧杵六宫秋。——唐· 刘驾《长门怨》

(2) 同“蹀”。

◎ 揲 shé

〈动〉

(1) 按定数更迭数物,分成等分。古代多用于数蓍草占卦,以卜吉凶

揲,阅持也。从手——《说文》

揲之以四,以象四时。——《易·系辞》

(2) 又如:揲蓍(蓍,蓍草。古人用数点蓍草茎的占卜方法来卜卦,以预测吉利与否,称为揲蓍);揲揲锤锤(形容蟋蟀的叫声)

(3) “舍”的代字。舍亲

有这等没天理的?揲老性命织识他!——《二刻拍案惊奇》 (more…)