Blog


Verilog on Mac

posted May 20, 2020, 9:04 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated May 20, 2020, 9:13 PM ]

I've always I need to use a full-brown IDE to edit Verilog. It turns out, using Verilog on Mac (and Linux, although the installation procedure is slightly different) is a piece of 🎂.

$ brew install icarus-verilog

Next, enter the simplest code:

$ nano hello.v

module hello;
  initial 
    begin
      $display("Hello, World");
      $finish ;
    end
endmodule


Compile with the command

$ iverilog -o hello hello.v

The result will be in a file "hello. Next, execute it:

$ vvp hello

Hello, World

For bigger project, there be multiple files. For example, the counter in the following file counter.v

module counter(out, clk, reset);

  parameter WIDTH = 8;

  output [WIDTH-1 : 0] out;
  input 	       clk, reset;

  reg [WIDTH-1 : 0]   out;
  wire 	       clk, reset;

  always @(posedge clk or posedge reset)
    if (reset)
      out <= 0;
    else
      out <= out + 1;

endmodule // counter

and the testbench counter_tb.v

module test;

  /* Make a reset that pulses once. */
  reg reset = 0;
  initial begin
     # 17 reset = 1;
     # 11 reset = 0;
     # 29 reset = 1;
     # 11 reset = 0;
     # 100 $stop; // I replaced with $finish to have a clean exit
  end

  /* Make a regular pulsing clock. */
  reg clk = 0;
  always #5 clk = !clk;

  wire [7:0] value;
  counter c1 (value, clk, reset);

  initial
     $monitor("At time %t, value = %h (%0d)",
              $time, value, value);
endmodule // test

Compile and run using this command:

$ iverilog -o mydesign counter_tb.v counter.v
$ vvp mydesign

This is the output:

At time                    0, value = xx (x)
At time 17, value = 00 (0)
At time 35, value = 01 (1)
At time 45, value = 02 (2)
At time 55, value = 03 (3)
At time 57, value = 00 (0)
At time 75, value = 01 (1)
At time 85, value = 02 (2)
At time 95, value = 03 (3)
At time 105, value = 04 (4)
At time 115, value = 05 (5)
At time 125, value = 06 (6)
At time 135, value = 07 (7)
At time 145, value = 08 (8)
At time 155, value = 09 (9)
At time 165, value = 0a (10)

There's further options in the short tutorial below.

Reference:

Know Your Audio, Jack

posted Apr 21, 2020, 4:35 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Apr 26, 2020, 10:30 PM ]

It turns out, there's variations to the simple jack. Plugging your earphone or mic to the wrong socket may produce surprising results.


There are 3 types of jacks: TS, TRS and TRRS. T = tip, R = ring, S = sleeve.

TS type jack does not support stereo sound and microphone. It means there is no left and right only mono. Both side of headphones will give you the same sound.

TRS type jack supports stereo sound but it does not support microphone. You can only listen to music but can not make calls with these type of headphones.

TRRS type jack supports both stereo and microphone functionality. But there are differences in implementation of TRRS.
One is called Open Mobile Terminal Platform (OMTP) used by Android phones.
The other is called CTIA used by:
  • Apple
  • PS4
  • Xbox One
  • Nintendo Switch
If you plugged an Apple earphone/mic set into an Android phone, chances are the microphone might not work.


Luckily, you can connect an OMTP headset to a CTIA jack by adapters below.

Rigid connector.

Flexible connector.

You can also use separate mic and earphones on a TRRS socket using a splitter. The outputs are labeled with mic and headphone.

Rigid splitter.

Flexible splitter.

Fast Storage on iMac

posted Apr 4, 2020, 12:45 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Apr 4, 2020, 1:37 AM ]

Experiments done during Movement Control Order.

All tests were run on AJA Video Systems Test Lite:

Speed of Internal PCIe SSD disk, 256GB. 90% full.

Speed of G-Technology Thunderbolt Drive, 4 TB HDD, connected to Displayport/Thunderbolt port. 80% full.

Speed of Sandisk Extreme SSD, 500GB, connected to USB port. Fresh out of the box.
Speed on Sandisk Fit, low-cost USB drive, 8GB blank disk.

This is a Fit drive... OK for mostly read, sometimes write use cases. On reads, it's still faster than a mechanical hard drive.


The values vary slightly when run repeatedly, but not by much.
Conclusion: nothing can beat internal PCIe.




Ubuntu New Install

posted Feb 4, 2020, 10:17 PM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Feb 4, 2020, 10:36 PM ]

Sometimes you need to make a fresh Ubuntu install.
For some apps, just download and install.  My of apps:
  1. Chrome
  2. Mendeley
  3. Dropbox
  4. Anaconda
  5. Inkscape
  6. GIMP
  7. Texmaker


For the harder ones, you need some commands to issue after reinstalling.

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt upgrade
$ ubuntu-drivers devices
$ sudo ubuntu-drivers autoinstall
$ nvidia-smi

Thu Feb  6 22:21:25 2020      
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.48.02    Driver Version: 440.48.02    CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:01:00.0  On |                  N/A |
| 37%   58C    P0    63W / 250W |    799MiB / 11175MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                              
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1335      G   /usr/lib/xorg/Xorg                            34MiB |
|    0      1380      G   /usr/bin/gnome-shell                          49MiB |
|    0      1634      G   /usr/lib/xorg/Xorg                           404MiB |
|    0      1778      G   /usr/bin/gnome-shell                         167MiB |
|    0      2183      G   ...AAAAAAAAAAAAAAgAAAAAAAAA --shared-files   118MiB |
+-----------------------------------------------------------------------------+

$ sudo reboot

$ sudo apt install wget
$ sudo apt install texlive texlive-fonts-extra texlive-science
$ sudo apt install texmaker inkscape gimp


Explainibility of ML Algorithms

posted Jan 26, 2020, 4:24 AM by MUHAMMAD MUN`IM AHMAD ZABIDI

Clean Up Latex Intermediate Files

posted Jan 24, 2020, 5:52 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Jan 24, 2020, 5:53 AM ]

To delete all .bak files, here's the commands:

$ cd top_level_dir
$ find . -name "*.bak" -type f -delete

If you're afraid of deleting other files, do a dry run first:

$ find . -name "*.bak" -type f -delete

Finally, when you want to delete all the junk and keep only .tex, .bib and .pdf files, here's the commands:

$ cd top_level_dir
$ find . -name "*.bak" -type f -delete
$ find . -name "*.log" -type f -delete
$ find . -name "*.out -type f -delete
$ find . -name "*.xml" -type f -delete
$ find . -name "*.pdfsync" -type f -delete
$ find . -name "*.gz" -type f -delete
$ find . -name "*.toc" -type f -delete

Bibliography and index related files

$ find . -name "*.blg" -type f -delete
$ find . -name "*.bcf" -type f -delete
$ find . -name "*.bbl" -type f -delete
$ find . -name "*.idx" -type f -delete

Beamer files

$ find . -name "*.nav" -type f -delete
$ find . -name "*.snm" -type f -delete

Or just put all the command in a script file clean.sh, then run

$ source clean.sh

The script file in Atom:







MFCC in Python

posted Dec 18, 2019, 1:04 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Dec 18, 2019, 1:20 AM ]

Easy with librosa.
The code below gives an array with dim (40,40).

import librosa

sound_clip, s = librosa.load(filename.wav)
mfcc=librosa.feature.mfcc(sound_clip, n_mfcc=40, n_mels=60)

Programming AudioVideo on the Raspberry Pi GPU

posted Nov 26, 2019, 1:30 AM by MUHAMMAD MUN`IM AHMAD ZABIDI   [ updated Nov 26, 2019, 1:31 AM ]

Neither Larman nor Rosenberg

posted Nov 6, 2019, 1:16 AM by MUHAMMAD MUN`IM AHMAD ZABIDI


My understanding of OOAD. Combines the approaches of Rosenberg and Larman.

References:
  1. Rosenberg, D. & Stephens, M.. Use Case Driven Object Modeling with UML: Theory and Practice. Apress. 2007.
  2. Larman, Craig. Applying UML and patterns: an introduction to object oriented analysis and design and interative development. Pearson Education, 2012. link

Python Spectrogram for 1-second Sound

posted Oct 23, 2019, 8:34 PM by MUHAMMAD MUN`IM AHMAD ZABIDI

First install pydub. Use the virtual environment and Anaconda for best results.

$ ls anaconda3/envs
$ source activate sci
$ conda install -c conda-forge pydub

Launch spyder and enter the following code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""

"""


#import the pyplot and wavfile modules
import matplotlib.pyplot as plot
from scipy.io import wavfile
from os import path
from pydub import AudioSegment

# Read the wav file (mono)
src = '/home/munim/Downloads/tailorbird1.mp3'
dst = 'tmp.wav'

sound = AudioSegment.from_mp3(src)
sound = sound.set_channels(1)
#onesecond = sound[-1000:] # last one second
onesecond = sound[:1000] # first one second

onesecond.export(dst, format='wav')
samplingFrequency, signalData = wavfile.read(dst)


print(samplingFrequency)
# Plot the signal read from wav file
plot.subplot(211)
plot.title('Spectrogram of file {}'.format(src))

plot.plot(signalData)
plot.xlabel('Sample')
plot.ylabel('Amplitude')
plot.subplot(212)
plot.specgram(signalData,Fs=samplingFrequency)
plot.xlabel('Time')
plot.ylabel('Frequency')
plot.show()


Here's the output:


References:

1-10 of 143

Comments