实验五
(1):
第1关:循环结构
x=[]; %定义一个空矩阵,用于存放获得的整数
% ********** Begin ********** %
for i=1:1000
if rem(i,13)==2
x=[x,i];
end
end
% ********** End ********** %
disp(num2str(x(20:30)))
第2关:符号替换
%已知变量x和数学函数f,g,用fg和gf分别表示f(f(x))和g(f(x))
pkg load symbolic
% ********** Begin ********** %
syms x;
syms f;
syms g;
syms fg;
syms gf;
f = x*sin(x)/((x+5)*sqrt(x*x-2));
g=tan(x);
fg=subs(f,x,g);
gf=subs(g,x,f);
% ********** End ********** %
disp(fg)
disp(gf)
第3关:Fibonacci数列计算
pkg load symbolic
a=sym([1,1]);%a(1)=a(2)=1
%Fibonacci的最高项a(120)
% ********** Begin ********** %
for i=3:120
a(i)=a(i-1)+a(i-2);
end
% ********** End ********** %
disp(a(100:120))
第4关:序列稳态值
pkg load symbolic
x1=sym(1);
x2=x1/2+3/(2*x1);
e=10^(-14);
%求取达到e精度的稳态值steady_value和n
% ********** Begin ********** %
n=2;
while double(abs(x1-x2))>e
x1=sym(x2);
x2=x1/2+3/(2*x1);
n=n+1;
end
steady_value=x2;
% ********** End ********** %
disp(num2str(n))
disp(steady_value)
第5关:分段函数
D=str2num(input('','s'));
h=str2num(input('','s'));
x=str2num(input('','s'));
% ********** Begin ********** %
y=h.*(x>D)+h./(D.*x).*((x<=D)&(x>=-D))-h.*(x<-D);
% ********** End ********** %
disp(num2str(y))
(2):
第1关:二维图形的绘制
%%%%%%%%%%%%%%%%%%
%请不要修改
warning('off','all');
graphics_toolkit('gnuplot')
%%%%%%%%%%%%%%%%%%
m1=0:0.1:5;
m2=0:0.2:10;
m3=0:0.15:7.5;
y1=cos(m1);
y2=sin(m2);
y3=cos(m1).+sin(m3);
figure (1)
subplot(1,2,1);
%%%%%%%%% Begin %%%%%%%%%
x=[m1;m2;m3]';
y=[y1;y2;y3]';
plot(x,y);
title('figure 1');
%%%%%%%%% End %%%%%%%%%
subplot(1,2,2);
%%%%%%%%% Begin %%%%%%%%%
plotyy(m1,y1,m2,y2);
title('figure 2');
%%%%%%%%% End %%%%%%%%%
%用于生成图像,请不要修改
sa=pwd;
print(1,'-djpeg','./picture/step1/picture1.jpg');
run('./task1/test1.m');
system('python3 ./task1/test1py.py');
第2关:三维图形和隐函数的绘制
%%%%%%%%%%%%%%%%%%
%请不要修改
warning('off','all');
graphics_toolkit('gnuplot')
%%%%%%%%%%%%%%%%%%
figure (1)
subplot(1,2,1);
%%%%%%%%% Begin %%%%%%%%%
x1 = -16:0.5:16;
y1 = -10:0.5:10;
[x,y]=meshgrid(x1,y1);
z=sin(sqrt(x.^2+y.^2));
mesh(x,y,z);
%%%%%%%%% End %%%%%%%%%
subplot(1,2,2);
%%%%%%%%% Begin %%%%%%%%%
ezplot('x^3+y^3-4*x*y+1/6');
%%%%%%%%% End %%%%%%%%%
%画图显示部分,请不要修改
sa=pwd;
print(1,'-djpeg','./picture/step2/picture2.jpg');
run('./task2/test2.m');
system('python3 ./task2/test2py.py');
(3):
第1关:什么是卷积
%%%%%%%%%%%%%%%
%%请不要改动
warning('off','all');
graphics_toolkit('gnuplot')
pkg load image
addpath(genpath(pwd));
%%%%%%%%%%%%%%%%%%
figure(1)
%%%%%%%%% Begin %%%%%%%%%
ifelse = @(a,b,c) (a~=0)*b + (a==0)*c;
h = @(x,lx,ux) ifelse(x<lx,0,ifelse(x>ux,0,x/(4*pi)));
x = -2*pi:0.1:2*pi;
y = sin(x);
g=zeros(size(x));
for i=1:size(x,2)
for j=1:size(x,2)
g(i)=g(i)+y(j)*h(i-j,-1.57,1.57);
end
end
stem(x,g);title('f*h');
%%%%%%%%% End %%%%%%%%%
%print(1,'-djpeg','./pictures/step1/picture1.jpg');
%run('./task1/test1.m');
%system('python3 ./task1/test1py.py');
disp(g(1,1:3));
实验六:
(1)时域卷积法求解系统零状态响应实训
第一关:
C
C
第二关:
%sampling simulation(Quantization)
warning('off','all')
graphics_toolkit('gnuplot')
%以上语句请勿修改
% 参数设置
delta_t = 0.01;
end_t = 20;
t = 0:delta_t:end_t;
%********* begin *********%
lambda1 = 0;%更改输入激励信号模式参数(u(t)对应lambda1=0)
lambda2 = 1;%更改单位冲激响应模式参数(e^(-t)u(t)对应lambda2=-1)
% 输入激励信号
f_t = exp(lambda1*t);
% 系统单位冲激响应
h_t = exp(lambda2*t);
% 求系统零状态响应,即时域卷积运算
yf_t = conv(f_t, h_t);
%********* end *********%
% 对零状态响应作图
figure;grid on;box on;
plot(0:delta_t:end_t, yf_t(1:(end_t/delta_t+1)),'-.');
xlabel('Time');ylabel('Amplitude');
sa=pwd;
print(1,'./src/step1/outputfiles/output.png','-dpng');
run('./src/step1/Time_Conv_Computing.m');
system('python3 ./src/step1/test.py');
(2)语音信号单音干扰滤波实训
第一关:
C
第二关代码:
%sampling simulation(Quantization)
warning('off','all')
graphics_toolkit('gnuplot')
%以上语句请勿修改
[voice,fs] = audioread('./src/step1/origin.wav');%原始语音读入,采样率25KHz
subplot(3,2,1);t=0:1/fs:(length(voice)-1)/fs;figure(1);plot(t,voice);
%title('时域原始语音信号');
subplot(3,2,3);y=-fs/2:fs/length(voice):fs/2-fs/length(voice);plot(y,abs(fftshift(fft(voice))));
%title('频域原始语音信号');
noise=5000; %单音干扰频率Hz
latitude=0.01; %单音干扰幅度
noised_voice = voice+latitude*sin(2*pi*noise*t)';%叠加噪音
subplot(3,2,2);plot(t,noised_voice);
%title('时域加噪语音信号');
subplot(3,2,4);plot(y,abs(fftshift(fft(noised_voice))));
%title('频域加噪语音信号');
%%************************* begin ******************************
fc1 = 8000; % 设置低通滤波器参数(实际通带为[-4000,4000]Hz)
lowpass_filter = zeros(size(voice)); % 初始化滤波器(全阻带)
for i = round((-fc1/2+fs/2)/fs*length(voice)):round((fc1/2+fs/2)/fs*length(voice))
lowpass_filter(i) = 1; % 设置通带为1
end
% 频域滤波处理
denoise_voice = ifft(ifftshift(fftshift(fft(noised_voice)) .* lowpass_filter));
subplot(3,2,5);
plot(y, abs(fftshift(fft(denoise_voice))); % 绘制滤波后的频域信号
%%*********************************** end***********************
sa=pwd;
print(1,'./src/step1/outputfiles/output.png','-dpng');
%run('./src/step1/voice.m');
(3)雷达多普勒频移信号的时域抽样实训
第一关:
C
第二关代码:
%sampling simulation(Quantization)
warning('off','all')
graphics_toolkit('gnuplot')
fd = 200;% 运动目标回波多普勒频率 Hz
%********* begin *********%
PRF = 400; % 运动目标回波信号抽样频率 Hz
dT = 1/PRF; % 对运动目标回波信号的抽样间隔 seconds
N = 20; % 对运动目标回波信号的抽样点数
wd = 2*pi*fd; % 运动目标回波信号角频率
%********* end *********%
% 抽样信号轮廓图
x = cos(wd*(0:N-1));
figure;stem(real(x));hold on; plot(real(x),'--');
xlabel('Time');ylabel('Amplitude');
sa=pwd;
print(1,'./src/step1/outputfiles/output.png','-dpng');
if PRF>=2*fd
fprintf("The picture you output is exactly the same as the standard picture")
else
fprintf("The picture you output is different from the standard picture")
end