Digital Signal Processing Reference
In-Depth Information
A.6 HOW TO SUCCESSFULLY COPY-AND-PASTE M-CODE
M-code can usually be copied directly from a pdf copy of the topic, although a number of minor, easily
correctible problems can occur. Two characters, the symbol for raising a number to a power, the circumflex
ˆ , and the symbol for vector or matrix transposition, the apostrophe or single quote mark ' , are coded for
pdf using characters that are non-native to m-code. While these two symbols may look proper in the pdf
file, when pasted into the Command line of MATLAB, they will appear in red.
A first way to avoid this copying problem, of course, is simply to use the m-code files described
above to copy m-code from. This is probably the most time-efficient method of handling the problem—
avoiding it altogether.
A second method to correct the circumflex-and-single-quote problem, if you do want to copy
directly from a pdf document, is to simply replace each offending character (circumflex or single quote) by
the equivalent one typed from your keyboard. When proper, all such characters will appear in black rather
than red in MATLAB. In LabVIEW, the pre-compiler will throw an error at the first such character and
cite the line and column number of its location. Simply manually retype/replace each offending character.
Since there are usually no more than a few such characters, manually replacing/retyping is quite fast.
Yet a third way (which is usually more time consuming than the two methods described above) to
correct the circumflex and apostrophe is to use the function Reformat , which is supplied with the software
package.To use it, all the copied code from the pdf file is reformatted by hand into one horizontal line, with
delimiters (commas or semicolons) inserted (if not already present) where lines have been concatenated.
For example, suppose you had copied
n = 0:1:4;
y = 2.ˆn
stem(n,y);
where the circumflex is the improper version for use in m-code. We reformat the code into one
horizontal line, adding a comma after the second line (a semicolon suppresses computed output on the
Command line, while a comma does not), and enclose this string with apostrophes (or single quotes), as
shown, where Reformat corrects the improper circumflex and eval evaluates the string, i.e., runs the code.
eval(Reformat('n=0:1:4;y=2.ˆn;stem(n,y)'))
Occasionally, when copying from the pdf file, essential blank spaces are dropped in the copied
result and it is necessary to identify where this has happened and restore the missing space. A common
place that this occurs is after a “for” statement. The usual error returned when trying to run the code is
that there is an unmatched “end” statement or that there has been an improper use of the reserved word
“end”. This is caused by the elision of the “for” statement with the ensuing code and is easily corrected
by restoring the missing blank space after the “for” statement. Note that the function Reformat does not
correct for this problem.
A.7 LEARNING TO USE M-CODE
While the intent of this topic is to teach the principles of digital signal processing rather than the use
of m-code per se, the reader will find that the scripts provided in the text and with the software package
will provide many examples of m-code programming starting with simple scripts and functions early in
the topic to much more involved scripts later in the topic, including scripts for use with MATLAB that
make extensive use of MATLAB objects such as push buttons, edit boxes, drop-down menus, etc.
Search WWH ::




Custom Search