首先,我不确定自己在做什么是否正确。我对这些概念的理解也可能是一个问题。
这些是我们实验室活动中的说明:
1,创建一个振幅为(SeatNo * 0.1)的正弦曲线(sin 2 pi 50 * t),其采样频率为:
一种。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.比较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')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句