由于我是matlab的新手,我请你原谅这是否是一个非常基本的问题,但是想尝试一下。 我创建了名为Assgn_Modulation的.m文件名,包括函数[sm] = modulation(ss,fc,mtype),我想要做的是将整个函数本身包括变量等传递给新的.m文件中的新函数调用Assgn_Whitenoise包括函数[w] = white_noise(No,sm)。
function [w]= white_noise(No,sm)
[sm]= modulation(ss,2500,1)
Fs=44100;
total= length(ss)/ Fs
t=linspace(0,total,length(ss));
t=t';
No= input('Power of noise=');
w=awgn(sm,No);
plot(t,w)
end
但是,我收到下面显示的错误,因此我无法相互调用该函数。
Undefined function or variable 'modulation'.
Error in Assgn_WhiteNoise (line 3)
[sm]= modulation(ss,2500,1)
EDIT =
首先,我通过matlab调制了一个audiowave(ss),调制了audiowave(sm)然后我想在调制波(sm)中加入白噪声,在这个函数下产生噪声信号(w)[w] = white_noise (不,SM)。但是我必须定义sm来进行操作 编写此代码[sm] = modulation(ss,fc,1)根本不起作用。
我在下面引用的代码没有问题,但我想要做的是在另一个名为function [w] = white_noise(No,sm)的函数中使用它的输出sm。
'function [sm]= modulation(ss,fc,mtype)
[ss,Fs]= audioread('C:\Users\furka\Documents\MATLAB\sample.wav'); %audio waveform to be modulated is loaded.
Fs %sampling frequency is 44.1kHz for the audio waveform.
totalTime= length(ss)/ Fs
t=linspace(0,totalTime,length(ss));
t=t'; %so that linspace return row vector to convert it to column ,transpose is taken for matching.
%modulating signal
subplot(3,1,1)
plot(t,ss)
title('Modulating signal(sample.wav)');
xlabel('Time(Seconds)');
ylabel('Magnitude');
xlim([0.01 0.03]);
%Carrier Signal
fc= input('Carrier Frequency='); %carrier frequency will be determined by the user
subplot(3,1,2)
plot(t,cos(2*pi*fc*t))
title('Carrier signal');
xlabel('Time(Seconds)');
ylabel('Magnitude');
xlim([0.01 0.03]);
mtype= menu('Modulation type?','dsb','dsbsc','ssb','fm'); %modulation type will be determined by the user
%modulated signal
%DSB MODULATION
if mtype==1
ka= 0.7;
sm= ss.*(1+ka*cos(2*pi*fc*t));
subplot(3,1,3)
plot(t,sm)
xlim([0.01 0.03]);
title('Doubleside band modulation');
xlabel('time(seconds)');
ylabel('Magnitude');
%DSBSC MODULATION
elseif mtype==2 %if doublesideband suppress carrier is selected the statements below will be carried out.
sm = ss.*cos(2*pi*fc*t);
subplot(3,1,3)
plot(t,sm)
xlim([0.01 0.03]);
title('Doubleside band suppress carrier modulation');
xlabel('time(seconds)');
ylabel('Magnitude');
%SSB MODULATION
elseif mtype==3
sm=0.5*[ss.*cos(2*pi*fc*t)-hilbert(ss).*sin(2*pi*fc*t)];
subplot(3,1,3)
plot(t,sm)
xlim([0.01 0.03]);
title('singleside band modulation');
xlabel('time(seconds)');
ylabel('Magnitude');
%FM MODULATION
elseif mtype==4
kf=0.1; %frequency sensitivity.
sm= cos(2*pi*fc*t + 2*pi*kf*trapz(t,ss));
subplot(3,1,3)
plot(t,sm)
xlim([0.01 0.03]);
title('Frequency modulation');
xlabel('time(seconds)');
ylabel('Magnitude');
end
end
'