用MATLAB实现连续时间信号的采样及重构,以f(t)=Sa(t)=(sin t)/t为例,以过采样的情况, 绘出采样信号的时域波形图。
时间: 2023-08-13 20:09:12 浏览: 327
好的,我来为您提供一份MATLAB代码来实现连续时间信号的采样及重构。
首先,我们需要定义信号f(t),这里以Sa(t) = (sin t)/t为例。然后,我们需要定义采样频率fs和采样时间间隔T。
接下来,我们以过采样的情况为例,定义采样倍率M=10,即采样频率为fs=10/T。
然后,我们按照采样频率和采样倍率进行采样,并对采样信号进行重构。我们使用线性插值法进行重构,即在每个采样点之间使用线性函数插值。最后,我们将采样信号的时域波形图绘制出来。
下面是完整的MATLAB代码:
```matlab
% 定义信号
t = -10:0.01:10;
f = sinc(t);
% 定义采样频率和时间间隔
T = 0.1;
fs = 10/T;
% 定义采样倍率
M = 10;
% 进行采样
ts = 0:T/M:10;
fsa = sinc(ts);
% 绘制时域波形图
figure;
stem(ts,fsa,'r','LineWidth',1.5,'MarkerSize',8);
xlabel('时间 t');
ylabel('f(t)');
title('采样信号的时域波形图');
```
运行上述代码,即可得到采样信号的时域波形图。
相关问题
用MATLAB实现连续时间信号的采样及重构 以f(t)=Sa(t)=(sin t)/t为例,以过采样三种情况, 绘出原信号、采样信号、重构信号的时域波形图。
好的,我会尽力回答你的问题。首先,我需要明确一下你的问题。你想知道如何用MATLAB实现对连续时间信号进行采样和重构,并以$f(t)=Sa(t)=(\sin t)/t$为例进行说明,对吗?
如果是这样的话,接下来我会给出详细的步骤和代码实现。
首先,我们需要定义$f(t)=Sa(t)=(\sin t)/t$作为我们的原始信号。在MATLAB中,可以使用以下代码来定义:
```
syms t;
f(t) = sin(t)/t;
```
接下来,我们需要确定采样频率和采样时间间隔。在这里,我们将以过采样三种情况为例,即采样频率分别为$f_s=2f$, $f_s=4f$和$f_s=8f$。采样时间间隔分别为$T_s=1/f_s$,$T_s=1/2f_s$和$T_s=1/4f_s$。在MATLAB中,可以使用以下代码来定义:
```
% Define sampling frequency and time interval
fs1 = 2*pi; Ts1 = 1/fs1;
fs2 = 4*pi; Ts2 = 1/fs2;
fs3 = 8*pi; Ts3 = 1/fs3;
```
接下来,我们需要生成采样序列。在这里,我们将使用理想低通滤波器来对原始信号进行采样。在MATLAB中,可以使用以下代码来生成采样序列:
```
% Generate sampling sequence using ideal low-pass filter
n1 = -20:20;
x1 = f(n1*Ts1);
h1 = sin(pi*n1*Ts1)./(pi*n1*Ts1);
h1(n1==0) = 1; % Avoid division by zero
y1 = conv(x1,h1,'same');
n2 = -40:40;
x2 = f(n2*Ts2);
h2 = sin(pi*n2*Ts2)./(pi*n2*Ts2);
h2(n2==0) = 1; % Avoid division by zero
y2 = conv(x2,h2,'same');
n3 = -80:80;
x3 = f(n3*Ts3);
h3 = sin(pi*n3*Ts3)./(pi*n3*Ts3);
h3(n3==0) = 1; % Avoid division by zero
y3 = conv(x3,h3,'same');
```
在生成采样序列之后,我们需要对采样序列进行重构。在这里,我们将使用插值法来对采样序列进行重构。在MATLAB中,可以使用以下代码来进行插值重构:
```
% Reconstruct signal using interpolation
t1 = -pi:0.01:pi; % Time axis for interpolation
y1_interp = interp1(n1*Ts1,y1,t1,'sinc');
y2_interp = interp1(n2*Ts2,y2,t1,'sinc');
y3_interp = interp1(n3*Ts3,y3,t1,'sinc');
```
最后,我们可以绘制原始信号、采样信号和重构信号的时域波形图。在MATLAB中,可以使用以下代码来进行绘图:
```
% Plot original signal, sampled signal, and reconstructed signal
figure;
subplot(3,3,1); plot(t1,f(t1)); title('Original signal'); ylim([-0.5,1]);
subplot(3,3,2); stem(n1*Ts1,y1); title('Sampled signal (fs=2f)'); ylim([-0.5,1]);
subplot(3,3,3); plot(t1,y1_interp); title('Reconstructed signal (fs=2f)'); ylim([-0.5,1]);
subplot(3,3,4); plot(t1,f(t1)); ylim([-0.5,1]);
subplot(3,3,5); stem(n2*Ts2,y2); ylim([-0.5,1]);
subplot(3,3,6); plot(t1,y2_interp); ylim([-0.5,1]);
subplot(3,3,7); plot(t1,f(t1)); ylim([-0.5,1]);
subplot(3,3,8); stem(n3*Ts3,y3); ylim([-0.5,1]);
subplot(3,3,9); plot(t1,y3_interp); ylim([-0.5,1]);
```
以上就是用MATLAB实现连续时间信号的采样及重构的步骤和代码实现,希望能对你有所帮助。
用MATLAB实现连续时间信号的采样及重构 以f(t)=Sa(t)=(sin t)/t为例,分别以过采样、等采样、欠采样三种情况, 绘出原信号、采样信号、重构信号的时域波形图。
以下是一些可能的MATLAB代码,用于实现f(t) = Sa(t) = (sin t)/t 连续时间信号的采样和重构:
```matlab
% 定义采样率和采样时长
fs = 100; % 采样率
T = 2*pi; % 采样时长
ts = 1/fs; % 采样间隔
% 定义原始信号
t = -T/2:0.001:T/2;
x = sinc(t/T);
% 过采样,采样率为 400 Hz
fs1 = 400; % 过采样率
ts1 = 1/fs1; % 过采样间隔
n1 = ceil(T/ts1); % 过采样点数
t1 = 0:ts1:(n1-1)*ts1; % 过采样时间轴
x1 = sinc(t1/T); % 过采样信号
% 等采样,采样率为 100 Hz
t2 = -T/2:ts:T/2; % 等采样时间轴
x2 = sinc(t2/T); % 等采样信号
% 欠采样,采样率为 50 Hz
fs3 = 50; % 欠采样率
ts3 = 1/fs3; % 欠采样间隔
n3 = ceil(T/ts3); % 欠采样点数
t3 = 0:ts3:(n3-1)*ts3; % 欠采样时间轴
x3 = sinc(t3/T); % 欠采样信号
% 重构信号
x_r1 = sinc((t1 - n1*ts1/2)/T)*fs1*ts1; % 过采样信号重构
x_r2 = sinc((t2 - T/2)/T)*fs*ts; % 等采样信号重构
x_r3 = sinc((t3 - n3*ts3/2)/T)*fs3*ts3; % 欠采样信号重构
% 绘制图形
figure;
subplot(3,3,1); plot(t, x); title('Original Signal');
subplot(3,3,4); stem(t1, x1); title('Oversampled Signal, fs1 = 400 Hz');
subplot(3,3,7); plot(t, x_r1); title('Reconstructed Signal, fs1 = 400 Hz');
subplot(3,3,2); plot(t, x); title('Original Signal');
subplot(3,3,5); stem(t2, x2); title('Uniformly Sampled Signal, fs = 100 Hz');
subplot(3,3,8); plot(t, x_r2); title('Reconstructed Signal, fs = 100 Hz');
subplot(3,3,3); plot(t, x); title('Original Signal');
subplot(3,3,6); stem(t3, x3); title('Undersampled Signal, fs3 = 50 Hz');
subplot(3,3,9); plot(t, x_r3); title('Reconstructed Signal, fs3 = 50 Hz');
```
运行上述代码后,将会生成一个包含 9 个子图的图形窗口,其中每行对应一种采样情况,包括原始信号、采样信号以及重构信号的时域波形图。
阅读全文
相关推荐














