?? sendtestdata_2.m
字號:
% send data , receive data and get its envolope
%
SampleRate = 44100;
frequency=1500
duration = 1 %daration time is 2 second 信號的持續(xù)時(shí)間
Ts=1/SampleRate;
t=0:Ts:(1-Ts);
%x=cos(frequency*pi*t).*exp(-2*t);
NumSamples = SampleRate*duration;
x = linspace(-1,1,NumSamples);
%LOGSPACE
figure(1)
plot(t,x)
title('The original signal waveform','FontSize',18);%clear AI
data = x';
AI = analoginput('winsound',0);
chan = addchannel(AI,1); %one channel
SampleRate = 44100
set(AI,'SampleRate',SampleRate);
set(AI,'SamplesPerTrigger',duration*SampleRate);
set(AI,'TriggerType','Manual');
start(AI); % 啟動接收信號通道,為接收信號做好準(zhǔn)備 上面1到16行 為輸入通道初始化
trigger(AI);
%data = getdata(AI);
%plot(data)
%waittilstop(AI,2)
%delete(AI)
%while(1)
%%Open the analog device and channels
AO = analogoutput('winsound',0);
chan = addchannel(AO,1);
%% Set the sample rate and how long we will send data for
%% 44,100 Hz, 1 seconds of data
%duration = 2;
%SampleRate = 44100;
set(AO,'SampleRate',SampleRate)
set(AO,'TriggerType','Manual')
NumSamples = SampleRate*duration;
%% Create a signal that we would like to send, 500 Hz sin wave
%x = linspace(0,2*pi*frequency,NumSamples);
%data = sin(x)'; %輸出數(shù)據(jù)為正弦信號'
%x = linspace(-1,1,NumSamples);%輸出數(shù)據(jù)為ramp信號'
%x=[x,x,x,x,x,x,x,x,x,x];
%x=[x,x,x,x,x,x,x,x,x,x];
%x=[x,x,x,x,x,x,x,x,x,x];
%x=[x,x,x,x,x,x,x,x,x,x];
%x=[x,x,x,x,x,x,x,x,x,x];
%data = x';
%
%data = getdata(AI); % received data
%figure(2)
%plot(data)
%waittilstop(AI,2)
%delete(AI)
%clear AI
%
%% Put the data in the buffer, start the device, and trigger
putdata(AO,data) % 輸出信號
start(AO)
trigger(AO) % 啟動輸出 28 到29 行為輸出通道初始化
data_re= getdata(AI); % receive data 接收數(shù)據(jù)到data_re中
waittilstop(AI,2)
delete(AI)
clear AI %關(guān)閉輸入
%% clean up, close down
%figure
%plot(data)
%ylabel('發(fā)送的輸出信號')
waittilstop(AO,30)
delete(AO)
clear AO %關(guān)閉輸出
figure(2)
plot(data_re)
ylabel('接收的輸入信號')
data_re=data_re;
[up,down] = envelope(t,data_re,'linear');
[tt,yy,kk]=maxima_1(t,data_re);
% Show the envelope alone
%--------------------------------------------
figure
plot(t,up); hold on;
%plot(t,down);
title('The envelope of the given signal data','FontSize',18);
hold off;
% Show the original signal and its envelope
%--------------------------------------------
figure
plot(t,data_re,'g-'); hold on;
plot(t,up,'r-.');
%plot(t,down,'r-.');
title('The envelope vs the given signal data','FontSize',18);
hold off;
%end
%result(n,1)=sqrt(mean(data_re.^2))
save test4.mat yy
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -