0

したがって、ここには 2 つの別個の関数があります。最初の関数では、変調したい信号を生成しています。最初の関数から出力を取得し、2 番目の関数で使用する必要があります。

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

出力信号を 2 番目の関数に正常に呼び出すことができましたが、信号の変調とグラフ化に問題が発生しています。

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-limit がTime(またはt_in、同じように見える) の最初の要素であり、最大 x-limit が の 2001 番目の要素であることを意味しTimeます。ただし、Time等しいため、201 個の要素のみが含まれ-0.010:0.0001:0.010ます (つまり、ステップ値 0.0001 で -0.01 から 0.01 までの要素が含まれます)。

Time配列のサイズは将来変更される可能性があるため、の最後の要素のインデックスに定数を使用しないことをお勧めします。Time(end)代わりに、建設を使用できます。インデックスとして使用される場合end、最後の配列インデックスを意味するためTime(end)、最後の配列要素です。

そして、rayryeng がすでに言ったplot(t_in,DSB,'g')ように、変調された信号をプロットします。

于 2016-10-06T10:46:21.740 に答える