问题描述
我试图绘制一个正弦波,其中振幅随时间增加,频率也随时间增加.我绘制了一个正常的正弦波,如下所示,但是我无法更改幅度和频率.有任何想法吗?
I am trying to plot a sine wave where the amplitude increases over time and the frequecy increases over time as well. I draw a normal sine wave as shown below but I couldn't change the amplitude and frequency. Any Ideas?
t = [ 0 : 1 : 40 ]; % Time Samples
f = 500; % Input Signal Frequency
fs = 8000; % Sampling Frequency
x = sin(2*pi*f/fs*t); % Generate Sine Wave
figure(1);
stem(t,x,'r'); % View the samples
figure(2);
stem(t*1/fs*1000,x,'r'); % View the samples
hold on;
plot(t*1/fs*1000,x); %
推荐答案
我相信您所说的是调幅(AM)和调频(FM).基本上,AM是指改变正弦信号的幅度,并使用与时间有关的函数来改变此幅度. FM相似,只是频率变化而不是幅度变化.
I believe what you are speaking of is amplitude modulation (AM) and frequency modulation (FM). Basically, AM refers to varying the amplitude of your sinusoidal signal and varying this uses a function that is time-dependent. FM is similar, except the frequency varies instead of the amplitude.
鉴于时变信号A(t)
,AM通常表示为:
Given a time-varying signal A(t)
, AM is usually expressed as:
次要注意事项:以上实际上是双边带抑制载波(DSB-SC)调制,但是如果您想实现自己在问题中想要的东西,我们实际上需要这样做.同样,信号通常使用cos
而不是sin
来确保发送时的零相移.但是,因为您的原始代码使用了sin
,所以这也是我将要使用的.
Minor note: The above is actually double sideband suppressed carrier (DSB-SC) modulation but if you want to achieve what you are looking for in your question, we actually need to do it this way instead. Also, the signal customarily uses cos
instead of sin
to ensure zero-phase shift when transmitting. However, because your original code uses sin
, that's what I'll be using as well.
如果有任何通信理论家想要尝试纠正我,我将在此声明免责声明:)
I'm putting this disclaimer here in case any communications theorists want to try and correct me :)
类似地,FM通常表示为:
Similarly, FM is usually expressed as:
A(t)
是所谓的消息或调制信号,因为它会改变正弦波的幅度或频率.正弦波本身就是载波信号.使用AM和FM的原因是由于通信理论.在模拟通信系统中,为了将信号从一个点传输到另一个点,需要将消息移频或调制到频谱中的较高范围,以适应信号的频率响应.信号传播的通道或介质.
A(t)
is what is known as the message or modulating signal as it is varying the amplitude or frequency of the sinusoid. The sinusoid itself is what is known as the carrier signal. The reason why AM and FM are used is due to communication theory. In analog communication systems, in order to transmit a signal from one point to another, the message needs to be frequency shifted or modulated to a higher range in the frequency spectrum in order to suit the frequency response of the channel or medium that the signal travels in.
这样,只要将t
的值与正弦波的使用方式相同,您所要做的就是将A(t)
指定为您想要的任何信号.例如,假设您希望幅度或频率线性增加.在这种情况下,为A(t) = t
.请记住,您需要指定正弦波f_c
的频率,数据的采样周期或采样频率以及信号定义的时间范围.让我们将数据的采样频率称为f
.另外请记住,如果要正确显示曲线,则必须足够高.如果将其设置得太低,将会发生信号跳变的必要峰值和谷值,而该图看起来会很差的情况.
As such, all you have to do is specify A(t)
to be whichever signal you want, as long as your values of t
are used in the same way as your sinusoid. As an example, let's say that you want the amplitude or frequency to increase linearly. In this case, A(t) = t
. Bear in mind that you need to specify the frequency of the sinusoid f_c
, the sampling period or sampling frequency of your data as well as the time frame that your signal is defined as. Let's call the sampling frequency of your data as f
. Also bear in mind that this needs to be sufficiently high if you want the curve to be visualized properly. If you make this too low, what'll happen is that you will be skipping essential peaks and troughs of your signal and the graph will look poor.
因此,对于AM,您的代码可能看起来像这样:
Therefore, for AM your code may look something like this:
f = 24; %// Hz
f_c = 8; %// Hz
T = 1 / f; %// Sampling period from f
t = 0 : T : 5; %// Determine time values from 0 to 5 in steps of the sampling period
A = t; %// Define message
%// Define carrier signal
carrier = sin(2*pi*f_c*t);
%// Define AM signal
out = A.*carrier;
%// Plot carrier signal and modulated signal
figure;
plot(t, carrier, 'r', t, out, 'b');
grid;
上面的代码将载波和调制后的信号绘制在一起.
The above code will plot the carrier as well as the modulated signal together.
这就是我得到的:
如您所见,幅度随着时间的增加而增大.您还可以看到载波信号被消息信号A(t) = t
bounding (边界)限制.我已经将原始载波信号放在图表中作为辅助.您肯定可以看到,由于消息信号,载波的幅度正在变大.
As you can see, the amplitude gets higher as the time increases. You can also see that the carrier signal is being bounded by the message signal A(t) = t
. I've placed the original carrier signal in the plot as an aid. You can certainly see that the amplitude of the carrier is getting larger due to the message signal.
类似地,如果您想进行FM,则大多数代码是相同的.唯一不同的是,消息信号将在载波信号本身内部.因此:
Similarly, if you want to do FM, most of the code is the same. The only thing that'll be different is that the message signal will be inside the carrier signal itself. Therefore:
f = 100; %// Hz
f_c = 1; %// Hz
T = 1 / f; %// Sampling period from f
t = 0 : T : 5; %// Determine time values from 0 to 5 in steps of the sampling period
A = t; %// Define message
%// Define FM signal
out = sin(2*pi*(f_c + A).*t);
%// Plot modulated signal
figure;
plot(t, out, 'b');
grid;
请记住,我更改了f_c
和f
以便您正确看到更改.我也没有绘制载波信号,因此您不会分心,可以更清楚地看到结果.
Bear in mind that I changed f_c
and f
in order for you to properly see the changes. I also did not plot the carrier signal so you don't get distracted and you can see the results more clearly.
这就是我得到的:
您可以看到频率开始很低,然后由于消息信号A(t) = t
而开始逐渐增加.随着时间的增加,频率也会增加.
You can see that the frequency starts rather low, then starts to gradually increase itself due to the message signal A(t) = t
. As time increases, so does the frequency.
您可以使用不同的频率来获得不同的结果,但这应该足以让您入门.
You can play around with the different frequencies to get different results, but this should be enough to get you started.
祝你好运!
这篇关于随着时间的流逝,随着幅度和频率的增加而绘制正弦波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!