一个极其简单的程序如下:
%the input script
prompt={'输入载波频率:','输入被调制的信号频率:','如果信号为正弦信号请输入s,如果是余弦信号请输入c:'};
title=['the input of info about signal'];
line=1;
%def{'200','45'};
input=inputdlg(prompt,title,line)
%%
fs=1000;
temp1=input{1}
fc=str2num(temp1);
N=1000;
n=0:N-1;
t=n/fs;
temp2=input{2}
if(input{3}=='s')
x=sin(2*pi*str2num(temp2)*t);
else
x=cos(2*pi*str2num(temp2)*t);
end
subplot(221)
plot(t,x);
xlabel('t(s)');ylabel('x');
title('Original Signal')
axis([0 0.1 -1 1])
%
nfft=1024;
window=hamming(512);
noverlap=256;
dflag='none';
[pxx,f]=psd(x,nfft,fs,window,noverlap,dflag);
subplot(222)
plot(f,pxx)
xlabel('Frequency(HZ)');
ylabel('Power Spectrum(X)');
title('Original Signal')
grid
%
y=modulate(x,fc,fs,'pm');
subplot(223)
plot(t,y)
xlabel('t(s)');ylabel('y');
axis([0 0.1 -1 1]);
title('Modulated Signal')
%
[pxx,f]=psd(y,nfft,fs,window,noverlap,dflag);
subplot(224)
plot(f,pxx)
xlabel('Frequency(HZ)');
ylabel('Power Spectrum(X)');
title('Modulated Signal')
grid
运行结果为:
??? Index exceeds matrix dimensions.
Error in ==> main at 24
title('Original Signal')
急问各位能人高手,这是怎么回事?????????
多谢!!!