You need to add the command \selectfont to "activate" the line spacing changes:
If you dislike the extra spacing below the listing, you can also set belowskip=0pt.
When listings breaks a line that is too long, it inserts some space at the beginning of the new line(s). You can remove this space by setting breakindent=0pt in \lstset:
Here's a solution that makes use of the general number highlighting approach presented in Listings: color numbers only out of keywords.
We need to make some changes to the OutputOther hook from that solution, because in this case you want to override the default style no matter whether you are in a comment or not. The new hook looks like:
You can wrap the code listing in a figure environment as demonstrated below.
f1 = Cos[2*Pi*freq1*t];
freq = 1 + 2*t;
f2 = Cos[2*Pi*Integrate[freq, t]*t];
The Matlab language definition only defines ' as string delimiter by default. But you can also make " one by adding the following line to the listing's options:
m is a special delimiter type for Matlab code defined as
[...] a special type for Ada and Matlab and
possibly other languages where the string delimiters are also used for ...
The label change can be done, e.g., by loading the package with required square symbol and applying this symbol. The package name is bbding and the symbol name \SquareCastShadowBottomRight (see the code snippet below marked by Q1). But there is a conflict with the package marvosym used in your code (the \Cross command is defined in both packages). Therefore, ...
There were multiple problems in this code:
We do not want to escape any character, if used as an input and, as @David Carlisle mentioned, the input for lsinputlistings needs to be expanded.
The optional structure is, as @egreg mentioned, better delegated to xparse.
For getting an optional command I used the DeclareExpandableDocumentCommand from (i think) ...
You cannot have page breaks in a figure environment, so don't place the listing in a figure. The lstlisting environment has a caption parameter that you can use to add the caption.
Regarding the frame, you first have frame=single, then you have a second \lstset with frame=bottomrule, meaning you only get a line at end of the listing. Remove the second \...