MATLAB:将位映射到载波
我有一组位,如下所示,我需要在它们上面放置一个载波。问题是:这是否可以在不循环的情况下完成?
例如,假设您正在使用频移键控。如果该位为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 t 是标量,那么您可以用单行矢量化解决方案替换 for 循环:
但是,如果您正在执行 频移键控,看来您应该扩展
0
或1
中的每个0
或1
>bits 向量转换为具有给定持续时间和频率的正弦波。例如,要为每个0
创建一个 8 kHz 下 4 个正弦周期(0.1 毫秒)的调制信号,为每个1
创建 10 kHz 下 5 个正弦周期(0.1 毫秒)的调制信号,您可以像这样使用函数 KRON :If
t
is a scalar, then you can replace your for loop with a single-line vectorized solution:However, if you're doing frequency-shift keying, it seems like you should be expanding each
0
or1
in yourbits
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 each0
and 5 sine periods (0.1 msec) at 10 kHz for each1
, you can use the function KRON like so: