<< Chapter < Page | Chapter >> Page > |
break;
end
end
LabVIEW MathScript supports the relational and logical operators listed below.
Relational Operators
Symbol | Meaning |
<= | less than equal |
< | less than |
>= | greater than equal |
> | greater than |
== | equal |
~= | not equal |
Logical Operators
Symbol | Meaning |
& | AND |
OR | |
~ | NOT |
The MathScript feature allows one to include .m files, which can be created using any text editor. To activate the LabVIEW MathScript interactive window, select Tools → MathScript Window from the main menu. To open the LabVIEW MathScript text editor, click the Script tab of the LabVIEW MathScript Window (see [link] ). After typing the .m file textual code, save it and click on the Run script button (green arrow) to run it.
For instance, to write a program to compute the average (mean) of a vector x, the program should use as its input the vector x and return the average value. To write this program, follow the steps outlined below.
Type the following in the empty script:
x=1:10
L=length(x);
sum=0;
for j=1:L
sum=sum+x(j);
end
y=sum/L % the average of x
From the Editor pull-down menu, go to File → Save Script As and enter average.m for the file name. Then click on the Run script button to run the program. [link] shows the LabVIEW MathScript interactive window after running the program.
Assuming the computer used has a sound card, one can use the function sound to play back speech or audio files through its speakers. That is, sound(y,FS) sends the signal in a vector y (with sample frequency FS) out to the speaker. Stereo sounds are played on platforms that support them, with y being an N-by-2 matrix.
Try the following code and listen to a 400 Hz tone:
>>t=0:1/8000:1;
>>x=cos(2*pi*400*t);
>>sound(x,8000);
Now generate a noise signal by typing:
>>noise=randn(1,8000); % generate 8000 samples of noise
>>sound(noise,8000);
The function randn generates Gaussian noise with zero mean and unit variance.
One can load or store data using the commands load and save. To save the vector x of the above code in the file data.mat , type:
>>save data x
Note that LabVIEW MathScript data files have the extension .mat. To retrieve the data saved, type:
>>load data
The vector x gets loaded in memory. To see memory contents, use the command
whos
,
>>whos
Variable Dimension Type x 1x8000 double array
The command
whos
gives a list of all the variables currently in memory, along with their dimensions. In the above example, x contains 8000 samples.
To clear up memory after loading a file, type
clear all
when done. This is important because if one does not clear all the variables, one could experience conflicts with other programs using the same variables.
With LabVIEW MathScript, one can read data from different file types (such as .wav, .jpeg and .bmp) and load them in a vector.
To read an audio data file with .wav extension, use the following command:
>>[y Fs]=wavread(‘filename’)
This command reads a wave file specified by the string filename and returns the sampled data in y with the sampling rate of Fs (in hertz).
Notification Switch
Would you like to follow the 'An interactive approach to signals and systems laboratory' conversation and receive update notifications?