matlab实现傅里叶变换


本文目录




笔记

【1】list station mac address

1
2
$ sudo ls /sys/kernel/debug/ieee80211/phy0/netdev:wlan0/stations/
00:0f:34:9d:01:a0

【2】Parsing the CSI trace file

1
$ cd linux-80211n-csitool-supplementary/matlab

In MATLAB or Octave

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// use the sample_data or use the generated data 
csi_trace = read_bf_file('sample_data/log.all_csi.6.7.6');
```

```angular2
csi_entry = csi_trace{1} (Note the curly-braces {}, not parentheses ().)

csi_entry =

timestamp_low: 4 (In the sample trace, timestamp_low is invalid and always 4.)
bfee_count: 72
Nrx: 3
Ntx: 1
rssi_a: 33
rssi_b: 37
rssi_c: 41
noise: -127
agc: 38
perm: [3 2 1]
rate: 256
csi: [1x3x30 double]
  • bfee_count:a count of the total number of beamforming measurements that have been recorded by the driver and sent to the space

  • Nrx:represents the number of antennas used to receive the packet by this NIC

  • Ntx:represents the number of space/time streams transmitted

  • prem:The sample value of [3 2 1] implies that Antenna C was sent to RF Chain A, Antenna B to Chain B, and Antenna A to Chain C

  • csi:It is a Ntx x Nrx x 30 3-D matrix where the third dimension is across 30 subcarriers in the OFDM channel

    1
    >> csi = get_scaled_csi(csi_entry);     // we use the script get_scaled_cis.m to do this

Let’s look at the three different spatial paths on the 1x3 link we measured
(Running the code with the Nrx is not 3 and the Ntx is not 1,there is a problem;i use the squeeze() turns csi
in to a 3x30 matrix,but at first,the matrix is 1x3x30,we should turn the matrix shape)

The complete block of code is shown below.

1
2
3
4
5
6
7
csi_trace = read_bf_file('sample_data/log.all_csi.6.7.6');
csi_entry = csi_trace{1};
csi = get_scaled_csi(csi_entry);
plot(db(abs(squeeze(csi).')));
legend('RX Antenna A', 'RX Antenna B', 'RX Antenna C', 'Location', 'SouthEast' );
xlabel('Subcarrier index');
ylabel('SNR [dB]');

The result is shown below

avater

for the matrix shape is 3x3x30,i try to change the shape of the matrix into 1x3x30,so i can run the code correctly



The complete block of code is shown below.

1
2
3
4
5
6
7
8
9
csi_trace = read_bf_file('subcarrier_1snd.dat');
csi_entry = csi_trace{1}; % the matrix shape is 2x3x30
csi = get_scaled_csi(csi_entry);
csi = csi(1,:,:);
subplot(1,2,1);
plot(db(abs(squeeze(csi).')));
legend('RX Antenna A', 'RX Antenna B', 'RX Antenna C', 'Location', 'SouthEast' );
xlabel('Subcarrier index');
ylabel('SNR [dB]');

The result is shown below
avater

notice: The above data can be obtain from the Internet;In netx chapter,i will use the data that is got from the NIC


before we realize ft,we must know some knowledge.

分辨率、帧速率、码流、采样位深、采样率、比特率

傅里叶变换

用Matlab进行快速傅里叶变换

1
2
3
4
5
6
7
8
9
10
clear           % 清空变量区
Fs = 128; % 采样频率
T = 1/Fs; % 采样时间
L = 256; % 信号长度
t = (0:L-1)*T; % 将范围0-L,乘以T
x = 5 + 7*cos(2*pi*15*t - 30*pi/180) + 3*cos(2*pi*40*t - 90*pi/180); %cos为底原始信号
% 频率15HZ和频率40Hz
y = x + randn(size(t)); %添加噪声
figure
plot(t,y)



avatar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% 在上面的基础上
N = 2^nextpow2(L); %采样点数,采样点数越大,分辨的频率越精确,N>=L,超出的部分信号补为0
% nextpow2(L),返回一个数n,即2的n次方最接近于L

Y = fft(y,N)/N*2; %除以N乘以2才是真实幅值,N越大,幅值精度越高
% 参考其他文章 https://blog.csdn.net/jasondooc/article/details/50202389

f = Fs/N*(0:1:N-1); %频率

A = abs(Y); %幅值,如a+bi,幅值 = sqrt(a*a+b*b)

P = angle(Y); %相值

figure;

subplot(211);

plot(f(1:N/2),A(1:N/2)); %函数fft返回值的数据结构具有对称性,因此我们只取前一半

title('幅值频谱');

xlabel('频率(Hz)');

ylabel('幅值');

subplot(212);plot(f(1:N/2),P(1:N/2));

title('相位谱频');

xlabel('频率(Hz)');

ylabel('相位');

avatar