MATLAB:将位映射到载波

发布于 2024-10-30 16:32:24 字数 462 浏览 1 评论 0原文

我有一组位,如下所示,我需要在它们上面放置一个载波。问题是:这是否可以在不循环的情况下完成?

例如,假设您正在使用频移键控。如果该位为“1”,则信号应为频率为 10,000 Hz 的正弦波,如果该位为“0”,则信号应为频率为 8,000 Hz 的正弦波。

位数组:

bits = [0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1]

循环代码:

for i = 1:length(bits)
   if bits(i) == 1
      signal = [signal sin(2*pi*10000*t)]
   else
      signal = [signal sin(2*pi*8000*t)]
   end    
end

如果我可以在一次操作中执行这一切而不需要循环,那就太好了。

谢谢。

I have an array of bits, such as the one below, and I need to put a carrier wave on top of them. The question is: Is this possible to do without looping?

For example, suppose you are using Frequency-Shift-Keying. If the bit is a "1" then the signal should be a sine wave with a frequency of 10,000 Hz, and if the bit is a "0" then the signal should be a sine wave with a frequency of 8,000 Hz.

Bit-Array:

bits = [0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 0 1]

Looping Code:

for i = 1:length(bits)
   if bits(i) == 1
      signal = [signal sin(2*pi*10000*t)]
   else
      signal = [signal sin(2*pi*8000*t)]
   end    
end

It would be nice if I could perform this all in a single operation with no looping.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别闹i 2024-11-06 16:32:24

如果 t 是标量,那么您可以用单行矢量化解决方案替换 for 循环:

signal = sin(2*pi*t.*(8000+2000.*bits));

但是,如果您正在执行 频移键控,看来您应该扩展 01 中的每个 01 >bits 向量转换为具有给定持续时间和频率的正弦波。例如,要为每个 0 创建一个 8 kHz 下 4 个正弦周期(0.1 毫秒)的调制信号,为每个 1 创建 10 kHz 下 5 个正弦周期(0.1 毫秒)的调制信号,您可以像这样使用函数 KRON

t = 0:5e-6:4.95e-4;
signal = sin(2*pi.*(kron(bits,10000.*t)+kron(~bits,8000.*t)));

If t is a scalar, then you can replace your for loop with a single-line vectorized solution:

signal = sin(2*pi*t.*(8000+2000.*bits));

However, if you're doing frequency-shift keying, it seems like you should be expanding each 0 or 1 in your bits vector into a sine wave with a given duration and frequency. For example, to create a modulated signal with 4 sine periods (0.1 msec) at 8 kHz for each 0 and 5 sine periods (0.1 msec) at 10 kHz for each 1, you can use the function KRON like so:

t = 0:5e-6:4.95e-4;
signal = sin(2*pi.*(kron(bits,10000.*t)+kron(~bits,8000.*t)));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文