⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendtestdata_2.m

📁 从声卡SPEAK 端 输出1HZ 锯齿波。 MATLAB编程
💻 M
字号:
% send data , receive data and get its envolope
% 
SampleRate = 44100;
frequency=1500
duration = 1   %daration time is 2 second   信号的持续时间
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);          % 启动接收信号通道,为接收信号做好准备   上面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)';                    %输出数据为正弦信号'
%x = linspace(-1,1,NumSamples);%输出数据为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    接收数据到data_re中   
waittilstop(AI,2)
delete(AI)
clear AI         %关闭输入
%% clean up, close down
%figure
%plot(data)
%ylabel('发送的输出信号')
waittilstop(AO,30)
delete(AO)
clear AO         %关闭输出
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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -