matlab取出示波器波形

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% 读取ch1的数据
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% 初始化变量。
filename_1 = ‘C:\Users\WANJI\Desktop\matlab\adc_test\ch2.txt’;
delimiter_1 = ‘\t’;

%% 每个文本行的格式字符串:
% 列1: 文本 (%s)
% 列2: 文本 (%s)
% 列3: 文本 (%s)
% 列4: 双精度值 (%f)
% 列5: 双精度值 (%f)
% 有关详细信息,请参阅 TEXTSCAN 文档。
formatSpec_1 = ‘%s%s%s%f%f%[^\n\r]’;

%% 打开文本文件。
fileID_1 = fopen(filename_1,’r’);

%% 根据格式字符串读取数据列。
% 该调用基于生成此代码所用的文件的结构。如果其他文件出现错误,请尝试通过导入工具重新生成代码。
dataArray_1 = textscan(fileID_1, formatSpec_1, ‘Delimiter’, delimiter_1, ‘ReturnOnError’, false);

%% 关闭文本文件。
fclose(fileID_1);

%% 将导入的数组分配给列变量名称
RecordLength_1 = dataArray_1{:, 1};
VarName2_1 = dataArray_1{:, 2};
Points_1 = dataArray_1{:, 3};
VarName4_1 = dataArray_1{:, 4};
VarName5_1 = dataArray_1{:, 5};

%% 清除临时变量
clearvars filename_1 delimiter_1 formatSpec_1 fileID_1 dataArray_1 ans_1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% 读取ch2的数据
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% 初始化变量。
filename_2 = ‘C:\Users\WANJI\Desktop\matlab\adc_test\ch3.txt’;
delimiter_2 = ‘\t’;

%% 每个文本行的格式字符串:
% 列1: 文本 (%s)
% 列2: 文本 (%s)
% 列3: 文本 (%s)
% 列4: 双精度值 (%f)
% 列5: 双精度值 (%f)
% 有关详细信息,请参阅 TEXTSCAN 文档。
formatSpec_2 = ‘%s%s%s%f%f%[^\n\r]’;

%% 打开文本文件。
fileID_2 = fopen(filename_2,’r’);

%% 根据格式字符串读取数据列。
% 该调用基于生成此代码所用的文件的结构。如果其他文件出现错误,请尝试通过导入工具重新生成代码。
dataArray_2 = textscan(fileID_2, formatSpec_2, ‘Delimiter’, delimiter_2, ‘ReturnOnError’, false);

%% 关闭文本文件。
fclose(fileID_2);

%% 将导入的数组分配给列变量名称
RecordLength_2 = dataArray_2{:, 1};
VarName2_2 = dataArray_2{:, 2};
Points_2 = dataArray_2{:, 3};
VarName4_2 = dataArray_2{:, 4};
VarName5_2 = dataArray_2{:, 5};

%% 清除临时变量
clearvars filename_2 delimiter_2 formatSpec_2 fileID_2 dataArray_2 ans_2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% 数据处理
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Data = VarName5_1 + VarName5_2

%% 显示示波器文件
figure(1)
plot(VarName4_1,VarName5_1,’r’)
hold on
plot(VarName4_2,VarName5_2,’b’)
hold off

figure(3)
plot(VarName4_2,Data,’b’)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% fft
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fs = 2500000000

n=size(Data)
%f1=fft(VarName5_2, n)
f2=fft(Data)
mag=abs(f2)

figure(2)
plot(mag(1:n))