试一下
%% 预处理
clear;clc;
T = 1; % 采样区间
t = -10:T/10000:10; % 时间序列
f = sin(pi*t)./(pi*t); % 原信号
%% 第一问
% 原连续时间信号波形
subplot(2,2,1)
plot(t,f)
title('Original Signal')
xlabel('Time (s)')
ylabel('Amplitude')
% Fs = fm
Fs = 1;
Ts = 1/Fs;
n = -10*T/Ts:1:10*T/Ts;
fs = sin(pi*n*Ts)./(pi*n*Ts);
subplot(2,2,2)
stem(n*Ts,fs,'LineStyle','-','Marker','o')
title('Sampling Frequency=1Hz')
xlabel('Time (s)')
ylabel('Amplitude')
% Fs = 2fm
Fs = 2;
Ts = 1/Fs;
n = -10*T/Ts:1:10*T/Ts;
fs = sin(pi*n*Ts)./(pi*n*Ts);
subplot(2,2,3)
stem(n*Ts,fs,'LineStyle','-','Marker','o')
title('Sampling Frequency=2Hz')
xlabel('Time (s)')
ylabel('Amplitude')
% Fs = 3fm
Fs = 3;
Ts = 1/Fs;
n = -10*T/Ts:1:10*T/Ts;
fs = sin(pi*n*Ts)./(pi*n*Ts);
subplot(2,2,4)
stem(n*Ts,fs,'LineStyle','-','Marker','o')
title('Sampling Frequency=3Hz')
xlabel('Time (s)')
ylabel('Amplitude')
%% 第二问
% 原连续信号幅度谱
F = fft(f);
freq = linspace(-5000,5000,length(t));
subplot(2,2,1)
plot(freq,abs(F))
title('Amplitude Spectrum of Original Signal')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
xlim([-5 5])
% 抽样信号幅度谱
Fs = 2;
Ts = 1/Fs;
n = -10*T/Ts:1:10*T/Ts;
fs = sin(pi*n*Ts)./(pi*n*Ts);
F_f = fft(fs);
freq = linspace(-5000,5000,length(fs));
subplot(2,2,2)
plot(freq,abs(F_f))
title('Amplitude Spectrum of Sampled Signal (Fs=2Hz)')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
xlim([-5 5])
%% 第三问
% 用理想低通滤波器重建信号
fc = 2*f_m;
wc = 2*pi*fc;
Tc = 1/fc;
t_recon = -10*T:Tc/10000:10*T;
s_recon = zeros(size(t_recon));
for i = 1:length(t_recon)
s_recon(i) = sum(fs.*sinc((t_recon(i)/Ts-n)*fc));
end
figure;
plot(t,f)
hold on
plot(t_recon,s_recon)
title('Reconstructed Signal (LPF)')
xlabel('Time (s)')
ylabel('Amplitude')
%% 第四问
% 用卷积的方法重建信号
h = wc/pi * sinc(wc*t);
s_recon = conv(fs,h,'same');
figure;
plot(t,f)
hold on
plot(t,s_recon)
title('Reconstructed Signal (Convolution)')
xlabel('Time (s)')
ylabel('Amplitude')
我是一名资深的IT专家,可以尽力回答您的问题。
首先,您需要了解Matlab的语法和基本概念,以便正确地解决问题。Matlab是一种广泛使用的数学软件,可用于科学计算、数据分析、可视化和算法开发等。
对于您的问题,我建议先从第二个问题入手。您可以尝试检查代码中是否存在语法错误或变量名错误。如果存在错误,可以尝试修改代码并重新运行。
接下来,对于第三个问题,我建议您在预处理数据时添加一些步骤,以便更好地处理数据。例如,您可以使用循环遍历数据,并使用函数对数据进行处理。
最后,对于第四个问题,我无法帮助您解决,因为您没有提供足够的信息。如果您有其他问题,请随时向我提问,我会尽力为您提供帮助。