0

所以我在这里有两个独立的功能。在第一个函数中,我正在生成一个我想要调制的信号。我必须从第一个函数中获取输出并在第二个函数中使用它。

function [output] = JoshGoldenHW3(amplitude,tau_in,t_in)


%Setting up Variables 
A = amplitude;      %The amplitude of the signal. = 1
Tau = tau_in;       %The period of the signal. = 0.010
Time = t_in;        %The time vector(Must be 2001). -0.010:0.0001:0.010


%Setting up the values for x of each period, as well as the slopes of the
%piecewise function
x = abs(mod(Time,Tau)); %Uses modulus function to figure out x value in period
x1 = 0.4*Tau;  %First slope change in period
x2 = 0.5*Tau;  %Second slope change in period
x3 = 0.9*Tau;  %Third slope change in period

%Calculating the slopes used in each period
slope1 = (A/(0.4*Tau));    %First slope calculation
slope2 = ((-A)/(0.1*Tau)); %Second slope calculation
slope3 = ((-A)/(0.4*Tau)); %Third slope calculation
slope4 = (A/(0.1*Tau));    %Fourth slope calculation

%This section defines the equations to be used for the period
eq1 = slope1*(x(x<x1)); 
eq2 = slope2*(x(x>=x1&x<x2)-(0.4*Tau)) + A;
eq3 = slope3*(x(x>=x2&x<x3)-(0.5*Tau));
eq4 = slope4*(x(x>=x3)-(0.9*Tau)) - A;


%Defining the function at each different range of x for each period
f(x<x1) = eq1;
f(x>=x1&x<x2) = eq2;
f(x>=x2&x<x3) = eq3;
f(x>=x3) = eq4;

%Plotting the graph of f(t) vs time.
plot(Time,f,'b-');
grid
xlabel('Time (Sec)');
ylabel('V(t)');
title('Signal');
axis([Time(1) Time(2001)  -2 2])
shg

output = f;

end

我能够成功地将输出信号调用到我的第二个函数,但现在我无法调制信号并绘制它。

function DSB = DSBMOD

amplitude = 1;
tau_in = 0.010; %Defining Tau
t_in = -0.010:0.0001:0.010; % Defining Time range
CarFreq = 27000; %Carrier Frequency
Fc = cos(2*pi*CarFreq*t); %Carrier Signal
Sig = JoshGoldenHW3(amplitude,tau_in,t_in); %Calling Signal from previous Function

%Modulating Signal
DSB = Sig.*Fc;

figure('units','normalized','outerposition',[0 0 1 1])

%Plotting Modulated Signal
subplot(4,3,1);
plot(t_in,Sig,'g')
axis([t_in(1) t_in(2001) -2 2])
title('Original Signal');
xlabel('Time (Seconds)');
ylabel('V(t) (Volts)');
grid
shg

%Plottng original Signal
plot(Time,Sig,'b-');
grid
xlabel('Time (Sec)');
ylabel('V(t)');
title('Signal');
axis([Time(1) Time(2001)  -2 2])
shg
end

我觉得我真的很接近,但我似乎无法弄清楚我做错了什么。我对使用 Matlab 比较陌生,所以如果你有更简单的方法来完成这个,我将不胜感激任何和所有的建议。

4

1 回答 1

1

编码

axis([xmin xmax ymin ymax])

设置当前坐标区的 x 轴和 y 轴范围。线

axis([Time(1) Time(2001)  -2 2])

表示最小 x 限制是 的第一个元素Time(或t_in,这似乎是相同的),最大 x 限制是 的第 2001 个元素Time。但是,Time它只包含 201 个元素,因为它等于-0.010:0.0001:0.010(即它包含从 -0.01 到 0.01 的元素,步长值为 0.0001)。

最好不要为最后一个元素的索引使用常量,Time因为数组的大小将来可能会发生变化。相反,您可以使用Time(end)构造。当用作索引时,end表示最后一个数组索引,因此Time(end)是最后一个数组元素。

并且,正如 rayryeng 已经说过的,plot(t_in,DSB,'g')将绘制调制信号

于 2016-10-06T10:46:21.740 回答