简体   繁体   English

从另一个函数处理.m文件

[英]Manipulating an .m file from another function

So i Created an .m file that has a sawtooth signal wave that i am trying to modulate. 所以我创建了一个.m文件,它有一个我试图调制的锯齿波信号波。 I have no Problem producing the wave form but when i try to take the .m file and multiply it by "c" MATLAB returns the original waveform. 我没有问题产生波形但是当我尝试获取.m文件并将其乘以“c”时,MATLAB返回原始波形。 This specific program is using the Double Side Band Modulation Technique. 该特定程序使用双边带调制技术。 The first piece is my waveform. 第一部分是我的波形。

function y = Signal
% Signal Summary of this function goes here
n = 23; % Number of Harmonics
t = 0:.0002:n; % incremental value
y = sawtooth(t,.2); % Wave creation
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time');
title('Sawtooth Wave');

end

This next piece is where i am trying to call the .m file, multiply it by 'c' and plot the resulting function. 下一篇文章是我试图调用.m文件,将其乘以'c'并绘制结果函数。

function [ DSBModulation ] = DSB( DSBModulation )
% Program for DSB-AM

n = 23; 
fc = 100;
t = 0:.0002:n;
sig = Signal; % this is how im trying to call the .m file so i can manipulate it

c = cos((2*pi*fc*t)); % using this as the modulating function
u(sig) = (sawtooth(t,.2)).*c; % Multiplying the signal
plot(t,u(sig)); %Displaying the Signal

end 

The result of the signal generation is stored in the variable sig on the following line of the DSB function: 信号生成的结果存储在DSB函数的以下行的变量sig

sig = Signal;

Further operation to modulate the generated signal should thus make use of that sig variable instead of trying to use the local sawtooth variable defined in the scope of Signal . 因此,调制所生成的信号的进一步操作应该使用该sig变量,而不是尝试使用在Signal范围内定义的局部sawtooth变量。 Then you should also note that the notation u(sig) in Matlab represents a vector u which is indexed by the values in sig , rather than the mathematical notion of a function u of the variable sig . 那么你还应该注意到Matlab中的符号u(sig)表示一个向量u ,它由sig的值索引,而不是变量sig的函数u的数学概念。

So to compute your modulated signal vector you would thus use: 因此,要计算调制信号矢量,您将使用:

u = sig.*c; % Multiplying the signal 

Finally, to plot the results on the same figure you could use the hold command , or otherwise use separate figure (otherwise your second plot command will erase the graph of the first plot ): 最后,要在同一个图上绘制结果,您可以使用hold命令 ,或者使用单独的figure (否则您的第二个plot命令将删除第一个plot ):

close all;
plot(t,u); %Displaying the Signal
hold on; plot(t,sig,'r','LineWidth',3); % Overlay the unmodulated signal for reference

ylabel ('Amplitude');
xlabel ('Time');

Which should give you the following result: 哪个应该给你以下结果:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM