Octave 4.0 crashing on audiowrite - octave

I'm trying to split up the long line of audiowrite but when I do Octave 4.0 crashes I'm using Octave 4.0 (which is like matlab) on Ubuntu 16.04 64bit.
audio_prop='BitsPerSample',16,'Artist','artist rt','Title','title section rt','Comment','Comments section rt';
audiowrite('/tmp/test.wav',[sig_full_L(:) -1*sig_full_R(:)],44100,audio_prop)
Can I not split it up this way if not how can I split it up?
Someone asked for the full code so here it is (this causes octave 4.0 to crash)
fs =8000; % Sampling frequency
fs_rate=fs;
dursec=10; %%duration of signal in seconds
t=linspace(0,2*pi,dursec*fs);
freq=primes(fs/2*dursec);
freq=freq';
ya=zeros(1,length(t));
numfreq=numel(freq)
for ii=1:1:numel(freq)
ya = ya+sin(freq(ii,1)*t);
end
audio_prop='BitsPerSample',16,'Artist','artist rt','Title','title section rt','Comment','Comments section rt';
audiowrite('/tmp/test.flac',[ya(:) -1*ya(:)],44100,audio_prop)
I was told by the octave people to fill out a crash / bug report link below
https://savannah.gnu.org/bugs/index.php?47875

Here is one way to wrap a long list of arguments into a single variable,
in order to shorter lines or to allow for reuse in a further function.
First put the arguments in a cell array.
options = {"a", "b", 2};
Then use the cell array expansion, which is a bit hidden there :
Accessing multiple elements of a cell array with the ‘{’ and ‘}’
operators will result in a comma separated list of all the requested
elements
In our case,
options{:}
is interpreted as
"a", "b", 2
so calling
func(arg1, arg2, options{:})
is interpreted as
func(arg1, arg2, "a", "b", 2)
Which answers the question.

#ederag solved this for me. "Even the first line is wrong. Brackets ({})are missing around it. And it should be audio_prop{:} in the second line."
The code with the error should be:
audio_prop={'BitsPerSample',16,'Artist','artist rt','Title','title section rt','Comment','Comments section rt'};
audiowrite('/tmp/test.wav',[sig_full_L(:) -1*sig_full_R(:)],44100,audio_prop{:})

Related

How to write multiple function calls in multiple lines in PowerShell?

I'm currently playing around on PowerShell, and I'm wondering how I can call multiple functions after eachother, but giving them each their own line.
I currently have this:
$leet= $text.replace("a", "4").replace("e", "1").replace("e", "3");
But I want it more like this:
$leet= $text
.replace("a", "4")
.replace("e", "1")
.replace("e", "3");
But PowerShell doesn't really like the newlines, and it doesn't work either when I add the ` to the end of each line followed by another one.
So, am I missing something, or is this not possible in PowerShell?
As Jeroen Mostert notes you can get line continuation for free by specifying the operator (.) and then placing the whitespace between it and the right-hand operand:
$leet = $text.
Replace("a", "4").
Replace("e", "1").
Replace("e", "3")
(note that the last call, Replace("e", "3"), does nothing - all the e's have already been replaced by the preceding call)

How to access VHDL signal attributes in ModelSim via TCL?

I am developing a CPU in VHDL. I am using ModelSim for simulation and testing. In the simulation script I load a program from a binary file to the instruction memory. Now I want to automatically check if the program fits into memory and abort simulation if it doesn't. Since the memory is basically an array of std_logic_vectors, all I would have to do is read the corresponding signal attribute for use in a comparison. My problem is: How do I access a VHDL signal attribute in TCL inside ModelSim?
The closest I have gotten so far is to use the describe command:
describe sim/:tb:uut:imem:mem_array
which prints something like
# Array(0 to 255) [length 256] of
# Array(31 downto 0) [length 32] of
# VHDL standard subtype STD_LOGIC
Now, of course I could parse the length out of there via string operations. But that would not be a very generic solution. Ideally I would like to have something like this:
set mem_size [get_attribute sim/:tb:uut:imem:mem_array'length]
I have searched stackoverflow, googled up and down and searched through the commands in the command reference manual, but I could not find a solution. I am confident there must be a rather easy solution and I just lack the proper wording to successfully search for it. To me, this doesn't look overly specific and I am sure this could come in hand on many occasions when automating design testing. I am using version 10.6.
I would be very grateful if an experienced ModelSim user could help me out.
Disclaimer: I'm not a Tcl expert, so there's probably a more optimized solution out there.
There's a command called examine that you can use to get the value of obejcts.
I created a similar testbench here with a 256 x 32 array, the results were
VSIM> examine -radix hex sim/:tb:uut:imem:mem_array
# {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} {32'hXXXXXXXX} ...
This is the value of sim/:tb:uut:imem:mem_array at the last simulation step (i.e.,
now).
The command return a list of values for each match (you can use wildcards), so
in our case, it's a list with a single item. You can get the depth by counting
the number of elements it returns:
VSIM> llength [lindex [examine sim/:tb:uut:imem:mem_array] 0]
# 256
You can get the bit width of the first element by using examine -showbase -radix hex,
which will return 32'hFFFFFFFF, where 32'h is the part you want to parse. Wrapping
that into a function would look like
proc get_bit_width { signal } {
set first_element [lindex [lindex [examine -radix hex -showbase $signal] 0] 0]
# Replace everything after 'h, including 'h itself to return only the base
return [regsub "'h.*" $first_element ""]
}
Hope this gives some pointers!
So, I actually found an easy solution. While further studying of the command reference manual brought to light that it is only possible to access a few special signal attributes and length is not one of them, I noticed that ModelSim automatically adds a size object to its object database for the memory array. So I can easily use
set ms [examine sim/:tb:uut:imem:mem_array_size]
to obtain the size and then check if the program fits.
This is just perfect for me, elegant and easy.

How to create table in Octave with border?

I want to create a table which looks like this Table01.
Where each column is a vector.
I tried with Octave data frame package but it is not generating table as I expected (With border)
Previously I tried with [t,I_X,I_Y] = table(x,y) which is also not satisfactory.
How can I generate table like the sample I provided and store them in format pdf in a directory?
I imagine you want something similar to uitable in MATLAB. Unfortunately, I don't think that has been implemented yet. However, I think I've found a solution that might help you. Here's the output I get for an example matrix m=magic(4):
If that is what you want, then keep reading! So, first, install the miscellaneous package. If using Ubuntu, you can just do that with
apt-get install octave-miscellaneous
Now, all you have to do is (well,you might run into a small problem, but I'll adress that in a bit):
pkg load miscellaneous
m=magic(4);
textable(m,"file","/tmp/file.tex","clines","rlines");
And voilà, you have the matrix expressed in latex code in "/tmp/file.tex", that you can compile with pdflatex , or alternatively, just copy paste it into something like this to get an image of the table.
Potential problem you might run into. Note that this seems to apply in octave version 4.2.2 which is the one I'm using, so, maybe you wont encounter that problem with your version. When using textable, you might get an error of the style
error: value on right hand side of assignment is undefined
error: called from
textable at line 111 column 5
If that happens, this is because the function textable (whose code you can find in textable.m, you can just use $ locate textable on Ubuntu) seems to use an obsolete (or different) interface to the inputParser object that it uses internally. So, if that happens, just go to line 111 of textable.m and replace
p = inputParser;
p = p.addSwitch ("clines");
p = p.addSwitch ("rlines");
p = p.addParamValue ("math", "X", #ischar);
p = p.addParamValue ("file", "matrix.tex", #ischar);
p = p.addParamValue ("align", "r", #(x) any(strcmpi(x, {"l", "c", "r"})));
p = p.parse (varargin{:});
with
p = inputParser;
p.addSwitch ("clines");
p.addSwitch ("rlines");
p.addParamValue ("math", "X", #ischar);
p.addParamValue ("file", "matrix.tex", #ischar);
p.addParamValue ("align", "r", #(x) any(strcmpi(x, {"l", "c", "r"})));
p.parse (varargin{:});
and you're set to go.

Break on namespace function in gdb (llvm)

I'm trying to step through llvm's opt program (for an assignment) and the instructor suggested setting a breakpoint at runOnFunction. I see this in one of the files:
bool InstCombiner::runOnFunction(Function &F) { /* (Code removed for SO) */ }
but gdb does not seem to find the runOnFunction breakpoint. It occurred to me that the problem might be namespaces? I tried this but gdb never breaks, it just creates the fooOpt.s file:
(gdb) b runOnFunction
Function "runOnFunction" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (runOnFunction) pending.
(gdb) r -S -instcombine -debug -o ~/Desktop/fooOpt.s ~/Desktop/foo.s
I'm on a Mac so I don't have objdump but otool produces 5.6 million lines, wading through that for a starting point does not seem reasonable as runOnFunction appears more than once there.
Gdb has several builtin commands to find name of such functions. First is info functions, which can be used with optional regexp argument to grep all available functions, https://sourceware.org/gdb/current/onlinedocs/gdb/Symbols.html
info functions regexp
Print the names and data types of all defined functions whose names contain a match for regular expression regexp. Thus, ‘info fun step’ finds all functions whose names include step; ‘info fun ^step’ finds those whose names start with step. If a function name contains characters that conflict with the regular expression language (e.g. ‘operator*()’), they may be quoted with a backslash.
So, you can try info functions runOnFunction to get the name. Sometimes it can be useful to add quotes around name when doing break command.
The other way is to use rbreak command instead of break (b). rbreak will do regexp search in functions names and may define several breakpoints: https://sourceware.org/gdb/current/onlinedocs/gdb/Set-Breaks.html#Set-Breaks
rbreak regex
Set breakpoints on all functions matching the regular expression regex. This command sets an unconditional breakpoint on all matches, printing a list of all breakpoints it set. ...
The syntax of the regular expression is the standard one used with tools like grep. Note that this is different from the syntax used by shells, so for instance foo* matches all functions that include an fo followed by zero or more os. There is an implicit .* leading and trailing the regular expression you supply, so to match only functions that begin with foo, use ^foo.
(or even rbreak file:regex to limit search to single source file)
PS: if you want, you can turn on or off C++ function name demangling with set print demangle on or off (https://sourceware.org/gdb/current/onlinedocs/gdb/Debugging-C-Plus-Plus.html#Debugging-C-Plus-Plus). With demangling turned off it will be easier to copy function name to break command.

word2vec : find words similar in a case insensitive manner

I have access to word vectors on a text corpus of my interest. Now, the issue I am faced with is that these vectors are case sensitive, i.e for example "Him" is different from "him" is different from "HIM".
I would like to find words most similar to the word "Him" is a case insensitive manner. I use the distance.c program that comes bundled with the Google word2vec package. Here is where I am faced with an issue.
Should I pass as arguments "Him him HIM" to the distance.c executable. This would return the sent of words closed to the 3 words.
Or should I run the distance.c program separately with each of the 3 arguments ("Him" and "him" and "HIM"), and then put together these lists in a sensible way to arrive at the most similar words? Please suggest.
If you want to find similar words in a case-insensitive manner, you should convert all your word vectors to lowercase or uppercase, and then run the compiled version of distance.c.
This is fairly easy to do using standard shell tools.
For example, if your original data in a file called input.txt, the following will work on most Unix-like shells.
tr '[:upper:]' '[:lower:]' < input.txt > output.txt
You can transform the binary format to text, then manipulate as you see fit.