如何增加绘制的样本数量?

How do I increase the number of samples plotted?

首先,我不完全确定我做的是否正确哈哈。 这也可能是我对概念理解的问题。

这些是我们实验室中的说明 activity:

1.Create 一个正弦曲线 (sin 2pi50*t),振幅为 (SeatNo *0.1),采样频率为:

一个。 8000 Hz 并绘制图形以显示最多 200 个样本。

c。 4050 Hz 并绘制图形以显示多达 200 个样本。

这是我的尝试:

amp = 12*0.1; %amplitude
%%%%%%%%%%%%%%%%%%%%
%     Number 1     %
%%%%%%%%%%%%%%%%%%%%
%sinusoidal wave
figure(1);
n = 200; %samples

%plot a
subplot(2,2,1);
fs = 8000; %sampling frequency
a = num1(fs, amp, n);
plot(a);
title('Plot 1a');

%plot c
subplot(2,2,3);
fs = 4050; %sampling frequency
c = num1(fs, amp, n);
plot(c);
title('Plot 1c');

%%%%%%%%%%%%%%%%%%%%
%     Number 1     %
%%%%%%%%%%%%%%%%%%%%
function y = num1(fs, amp, n)
%solves for the sinusoidal signal using the given
    t = (1/fs)*n;
    t = linspace(0, numSec, n);
    y = amp*sin(2*pi*50*t);
end

下面是我不明白该怎么做的事情:

2.Compare 1a和1c中信号的长度。如果需要,在较短信号的末尾执行零填充,以便它们具有相同的长度和

一个。添加两个信号并绘制 250 个样本。

我已经有 sigadd 功能,并且已经添加了信号,但它是 200 个样本。我如何让它绘制 250 个样本?

关于比较 1a 和 1c 中信号长度的部分对我来说没有意义。它们可以是您想要的任何长度。在我的示例代码中,我将每个信号设为 1000 点长,以便始终有大量点可用于绘图。如果你想得到一个向量的长度,你可以使用长度函数。

要添加两个信号,它们应该是相同的采样率,所以在我的示例代码中,我使用 interp1 将较高采样率信号下采样到与较低信号相同的采样率。

为了控制绘制多少点,我创建了一个名为 k 的变量,用于控制绘制哪些点。

这是执行要求的代码:

amp = 12*0.1; %amplitude

%create a
fs_a = 8000; %sampling frequency
t_a = (0:999) / fs_a;
a = amp*sin(2*pi*50*t_a);

%create c
fs_c = 4050; %sampling frequency
t_c = (0:999) / fs_c;
c = amp*sin(2*pi*50*t_c);

% plot a and c
k = 1:200;
figure(1)
plot(t_a(k), a(k), '+-', t_c(k), c(k), 'o-');
xlabel('Time (s)')
grid on
legend('1a', '1c')

% Add a and c
% resample a a the sample rate for c (4050 Hz)
a_resampled = interp1(t_a, a, t_c);
length_a_plus_c = min([length(c), length(a_resampled)]);
a_plus_c = a_resampled(1:length_a_plus_c) + c(1:length_a_plus_c);

% plot a + c
figure(2)
k = 1:250;
plot(t_c(k), a_plus_c(k), 'o-')
grid on
xlabel('Time (s)')
title('a + c')

看起来创建此分配是为了区分根据时间或样本索引求和信号之间的差异。这是我想出的一些图表,它们使用类似的重采样技术来实现累积信号所需的 250 个样本长度。

关于样本索引的总和:

clf;
%Configuring Signal 1%
Sampling_Frequency = 8000;
Number_Of_Samples = 200;
Amplitude = 12*0.1;

Sampling_Period = 1/Sampling_Frequency;
t = (0:Sampling_Period:Sampling_Period*(Number_Of_Samples-1));
Signal_1 = Amplitude.*sin(2*pi*50*t);
subplot(3,1,1); plot(t,Signal_1,'Marker','.');
title("Signal 1: 50Hz Sinusoid Samples at " + num2str(Sampling_Frequency) + "Hz");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

%Configuring Signal 2%
Sampling_Frequency = 4050;
Number_Of_Samples = 200;
Amplitude = 12*0.1;

Sampling_Period = 1/Sampling_Frequency;
t = (0:Sampling_Period:Sampling_Period*(Number_Of_Samples-1));
Signal_2 = Amplitude.*sin(2*pi*50*t);
subplot(3,1,2); plot(t,Signal_2,'Marker','.');
title("Signal 2: 50Hz Sinusoid Samples at " + num2str(Sampling_Frequency) + "Hz");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

%Adding signals with respect to samples%
Cumulative_Signal = Signal_1 + Signal_2;
Samples_Vector = (0:199); Interpolated_Samples_Vector = linspace(0,199,250);
Cumulative_Signal = interp1(Samples_Vector,Cumulative_Signal,Interpolated_Samples_Vector);
subplot(3,1,3); plot(Cumulative_Signal,'Marker','.');
title("Summed with Respect to Samples: Cumulative Signal (Signal 1 + Signal 2)");
xlabel("Sample [n]"); ylabel("Amplitude");
xlim([0 250]);

关于时间的求和:

clf;
%Configuring Signal 1%
Sampling_Frequency = 8000;
Number_Of_Samples = 200;
Amplitude = 12*0.1;

Sampling_Period = 1/Sampling_Frequency;
t = (0:Sampling_Period:Sampling_Period*(Number_Of_Samples-1));
Signal_1 = Amplitude.*sin(2*pi*50*t);
subplot(3,1,1); plot(t,Signal_1,'Marker','.');
title("Signal 1: 50Hz Sinusoid Samples at " + num2str(Sampling_Frequency) + "Hz");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

%Configuring Signal 2%
Sampling_Frequency = 4050;
Number_Of_Samples = 200;
Amplitude = 12*0.1;

Sampling_Period = 1/Sampling_Frequency;
t = (0:Sampling_Period:Sampling_Period*(Number_Of_Samples-1));
Signal_2 = Amplitude.*sin(2*pi*50*t);
subplot(3,1,2); plot(t,Signal_2,'Marker','.');
title("Signal 2: 50Hz Sinusoid Samples at " + num2str(Sampling_Frequency) + "Hz");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

%Adding signals with respect to time%
Signal_1 = [Signal_1 zeros(1,200)];
Signal_1 = Signal_1(1:2:end);
Samples_Vector = (0:199); Interpolated_Samples_Vector = linspace(0,199,250);
Signal_1 = interp1(Samples_Vector,Signal_1,Interpolated_Samples_Vector);
Signal_2 = interp1(Samples_Vector,Signal_2,Interpolated_Samples_Vector);
End_Time = Sampling_Period*(Number_Of_Samples-1);
t = linspace(0,End_Time,250);
Cumulative_Signal = Signal_1 + Signal_2;
subplot(3,1,3); plot(t,Cumulative_Signal,'Marker','.');
title("Summed with Respect to Time: Cumulative Signal (Signal 1 + Signal 2)");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

关于时间但起始样本量不同的求和:

clf;
%Configuring Signal 1%
Sampling_Frequency = 8000;
Number_Of_Samples = 200;
Amplitude = 12*0.1;

Sampling_Period = 1/Sampling_Frequency;
t = (0:Sampling_Period:Sampling_Period*(Number_Of_Samples-1));
Signal_1 = Amplitude.*sin(2*pi*50*t);
subplot(3,1,1); plot(t,Signal_1,'Marker','.');
title("Signal 1: 50Hz Sinusoid Samples at " + num2str(Sampling_Frequency) + "Hz (" + num2str(Number_Of_Samples) + " samples)");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

%Configuring Signal 2%
Sampling_Frequency = 4050;
Number_Of_Samples = 100;
Amplitude = 12*0.1;

Sampling_Period = 1/Sampling_Frequency;
t = (0:Sampling_Period:Sampling_Period*(Number_Of_Samples-1));
Signal_2 = Amplitude.*sin(2*pi*50*t);
subplot(3,1,2); plot(t,Signal_2,'Marker','.');
title("Signal 2: 50Hz Sinusoid Samples at " + num2str(Sampling_Frequency) + "Hz (" + num2str(Number_Of_Samples) + " samples)");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

Signal_1 = Signal_1(1:2:end);
Cummulative_Signal = Signal_1 + Signal_2;
Samples_Vector = (0:99); Interpolated_Samples_Vector = linspace(0,99,250);
Cummulative_Signal = interp1(Samples_Vector,Cummulative_Signal,Interpolated_Samples_Vector);
End_Time = Sampling_Period*(Number_Of_Samples-1);
t = linspace(0,End_Time,250);
subplot(3,1,3); plot(t,Cummulative_Signal,'Marker','.');
title("Summed with Respect to Time");
xlabel("Time (s)"); ylabel("Amplitude");
xlim([0 0.05]);

RNA 使用 MATLAB R2019b