📄 mult.m
字号:
function mult()
%
% Demonstrate the frequency spectrum of the output of a multiplier
% for equal magnitudes 500Hz and 1000Hz sinusoids
%
f1 = 500;
f2 = 1000;
% Step size between samples
tstep = 1e-4;
% Use the 1st 50ms of the input signals
t = 0:tstep:0.05;
%
% Generate the multiplier input signals
%
vin1=sin(2*pi*f1*t);
vin2=sin(2*pi*f2*t);
%
% Generate the multiplier output
%
vout = vin1.*vin2;
%
% apply a window function for better display of spectrum
% using the fft function
%
win = hamming (length(vout))';
%
% Obtain the spectrum using the fft function
y=abs(fft(vout.*win));
% Extract the appropriate fft vector to plot
fft_len = length(y);
n_freq = (0:fft_len-1)./(tstep*fft_len);
n_plot = n_freq(1:round(fft_len/2));
y_plot = y(1:round(fft_len/2));
%
% Plot the frequency spectrum
%
figure(1)
plot(n_plot,y_plot)
title(['Frequency spectrum of the product of two signals with frequencies ',num2str(f1), ' Hz and ' ,num2str(f2), ' Hz']);
xlabel('Frequency');
ylabel('FFT Magnitude');
grid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -