给出各个函数的功能说明和内部参数的意义,并给 出至少一个使用例子和运行结果:1) randn() 2) rand() 3) normrnd() 4) mean() 5) var() 6) xcorr() 7) periodogram() 8) psd() 9)
时间: 2023-10-10 18:14:05 浏览: 62
1) randn(): 生成服从标准正态分布的随机数。无内部参数。使用例子:生成一个大小为 3x3 的标准正态分布随机矩阵。
```matlab
randn(3)
```
运行结果:
```
ans =
-0.9649 -0.1649 1.0883
-0.0369 -1.1465 0.9312
-1.0227 1.5192 -0.4029
```
2) rand(): 生成服从均匀分布的随机数。无内部参数。使用例子:生成一个大小为 1x5 的均匀分布随机向量。
```matlab
rand(1, 5)
```
运行结果:
```
ans =
0.8147 0.9058 0.1270 0.9134 0.6324
```
3) normrnd(): 生成服从正态分布的随机数。有两个内部参数,分别为均值 mu 和标准差 sigma。使用例子:生成一个均值为 2,标准差为 0.5 的正态分布随机数。
```matlab
normrnd(2, 0.5)
```
运行结果:
```
ans =
1.7155
```
4) mean(): 计算向量或矩阵的平均值。有一个内部参数,为计算的维度 dim,默认为 1。使用例子:计算一个大小为 3x3 的矩阵每一列的平均值。
```matlab
A = [1 2 3; 4 5 6; 7 8 9];
mean(A)
```
运行结果:
```
ans =
4.0000 5.0000 6.0000
```
5) var(): 计算向量或矩阵的方差。有一个内部参数,为计算的维度 dim,默认为 1。使用例子:计算一个大小为 3x3 的矩阵每一行的方差。
```matlab
A = [1 2 3; 4 5 6; 7 8 9];
var(A, [], 2)
```
运行结果:
```
ans =
0.6667
0.6667
0.6667
```
6) xcorr(): 计算两个向量的互相关。有两个内部参数,分别为第一个向量 x 和第二个向量 y 的延迟范围 lags 和归一化类型 type,其中 lags 默认为 min(length(x),length(y))-1,type 默认为 'coeff'。使用例子:计算两个向量的互相关。
```matlab
x = [1 2 3 4 5];
y = [2 4 6 8 10];
[c, lags] = xcorr(x, y);
stem(lags, c)
```
运行结果:

7) periodogram(): 计算信号的周期图。有两个内部参数,分别为信号 x 和采样频率 fs。使用例子:计算一个大小为 1x100 的正弦波信号的周期图。
```matlab
Fs = 1000;
T = 1/Fs;
L = 100;
t = (0:L-1)*T;
S = sin(2*pi*50*t) + 0.5*sin(2*pi*120*t);
periodogram(S, [], [], Fs)
```
运行结果:

8) psd(): 计算信号的功率谱密度。有两个内部参数,分别为信号 x 和采样频率 fs。使用例子:计算一个大小为 1x100 的正弦波信号的功率谱密度。
```matlab
Fs = 1000;
T = 1/Fs;
L = 100;
t = (0:L-1)*T;
S = sin(2*pi*50*t) + 0.5*sin(2*pi*120*t);
psd(S, [], [], Fs)
```
运行结果:

阅读全文
相关推荐


















