|
多通道采集图像绘制单通道数据采集及绘制
这里我们不做讲解有兴趣的可以在其它帖子学习(http://www.corecourse.cn/forum.php?mod=viewthread&tid=29199),这里我们以AD7606数据采集为例向大家介绍多通道数据采集及绘制。
打开cypress上位机,将USB2.0芯片固件烧写成功之后,发送命令帧- 55A50200004000F055A501000000FFF055A503000000F9F055A50000000000F0
复制代码
AD7606数据帧格式配置表:
寄存器名称 数据帧数据
DataNum 55 A5 02 00 00 40 00 F0
ChannelSel 55 A5 01 00 00 00 FF F0
ADC_Speed_Set 55 A5 03 00 00 00 F9 F0
RestartReq 55 A5 00 00 00 00 00 F0
在本节中我们的通道设置为55 A5 01 00 00 00 FF F0,其中FF表示为采集8个通道的ADC数据对应二进制为(8'b1111_1111)
- %====================================================================%
- %设置ADC采集数据有效位宽
- ADC_DATA_WIDTH = 16;
- %ADC采集电压范围±VOL_RANGE (V)
- VOL_RANGE = 5;
- %采样率(Hz)
- SAMPLE_RATE = 200000;
- %ADC采集电压分辨率 LSB
- LSB = VOL_RANGE*2/(2^ADC_DATA_WIDTH);
- %====================================================================%
- %读取文件数据,转换成波形显示
- fileID = fopen('C:\Users\Administrator\Desktop\2');
- src_data = fread(fileID);
- fclose(fileID);
- src_data_hex = src_data;
- DATA_NUM = length(src_data_hex);
- if(DATA_NUM > 1024*64)
- DATA_NUM = 1024*64;
- end
- voltage_code = 1:DATA_NUM/2;
- voltage_code = voltage_code';
- for i=1:1:DATA_NUM/2
- if src_data_hex(2*i-1)+src_data_hex(i*2)*256 > 2^(ADC_DATA_WIDTH-1)
- voltage_code(i) = src_data_hex(2*i-1)+src_data_hex(i*2)*256-2^ADC_DATA_WIDTH;
- else
- voltage_code(i) = src_data_hex(2*i-1)+src_data_hex(i*2)*256;
- end
- end
- %二进制ADC数据转换为电压值
- voltage = voltage_code*LSB - LSB/2;
- %ADC采样时间
- data_8_1 = voltage(1:8:end,1);
- data_num = length(data_8_1); %计算8组中一组的长度2048
- sample_t = 1:data_num;
- sample_t = sample_t';
- for i=1:1:data_num
- sample_t(i) = 1000000/SAMPLE_RATE * i;
- end
- subplot(4,2,1)
- plot(sample_t,voltage(1:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- title('ADC采集电压显示','Fontsize',12,'position',[12000,6])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第一通道')
- grid on
-
- subplot(4,2,2)
- plot(sample_t,voltage(2:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第二通道')
- grid on
- subplot(4,2,3)
- plot(sample_t,voltage(3:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第三通道')
- grid on
- subplot(4,2,4)
- plot(sample_t,voltage(4:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第四通道')
- grid on
- subplot(4,2,5)
- plot(sample_t,voltage(5:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第五通道')
- grid on
- subplot(4,2,6)
- plot(sample_t,voltage(6:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第六通道')
- grid on
- subplot(4,2,7)
- plot(sample_t,voltage(7:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第七通道')
- grid on
- subplot(4,2,8)
- plot(sample_t,voltage(8:8:end,1));
- axis([0 1000000/SAMPLE_RATE*data_num -VOL_RANGE VOL_RANGE])
- xlabel('采样时间/(us)','Fontsize',10,'position',[9700,-7])
- ylabel('电压/(V)','Fontsize',10)
- legend('第八通道')
- grid on
- %双figure图形
- figure
- L = data_num/2;
- NFFT = 2^nextpow2(L);
- Y = fft(voltage(1:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,1)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第一通道')
- Y = fft(voltage(2:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,2)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第二通道')
- Y = fft(voltage(3:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,3)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第三通道')
- Y = fft(voltage(4:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,4)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第四通道')
- Y = fft(voltage(5:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,5)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第五通道')
- Y = fft(voltage(6:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,6)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第六通道')
- Y = fft(voltage(7:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,7)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第七通道')
- Y = fft(voltage(8:8:end,1),NFFT)/L;
- Fs = SAMPLE_RATE;
- f = Fs/2*linspace(0,1,NFFT/2+1);
- len = max(f);
- data = 2*abs(Y(1:NFFT/2+1));
- subplot(4,2,8)
- plot(f,data);
- xlabel('Frequency (Hz)')
- ylabel('|Y(f)|')
- axis([0 len 0 5])
- legend('第八通道')
复制代码
MATLAB操作如下图1-1所示:
图1-1
将方框中的路径修改为数据文件保存路径,然后点击箭头指向位置运行就可以看到采集的数据是否正确。
matlab经过分析得到的波形如图1-2,1-3所示:
图1-2
图1-3
本次实验提供的信号源为2KHz,Vpp为5V的正弦波(正负2.5V),而且只对第二通道的数据提供信号源,与MATLAB分析出来的波形一致,说明我们本次实验成功。
串口数据采集的matlab文件使用以下文件,需要注意的是,由于matlab是绘制的8个通道的数据,所以通道设置命令必须是8个通道都采集(55 A5 01 00 00 00 FF F0)
uart_wave.m
(5.03 KB, 下载次数: 258)
|
|