Problem : Vector length is different and fail to show the result of spectrum frequency.

1 次查看(过去 30 天)
Below is my code for spectrum frequency
It seems that i couldn't display the spectrum frequency code and I have no Idea why
2.JPG
fc=input('Enter the carrier signal freq in hz,fc=');
fm=input('Enter the modulating signal freq in hz,fm =');
m=input('Modulation index,m= ');
tm=(1/fm)*2;
t=0:1/(fc*1000):tm;
c=cos(2*pi*fc*t);%carrier signal
M=sin(2*pi*fm*t);% modulating signal
subplot(3,1,1);plot(t,c);
ylabel('amplitude');xlabel('time index');title('Carrier signal');
subplot(3,1,2);plot(t,M);
ylabel('amplitude');xlabel('time index');title('Modulating signal');
y=cos(2*pi*fc*t-(m.*cos(2*pi*fm*t)));
subplot(3,1,3);plot(t,y);
ylabel('amplitude');xlabel('time index');title('Frequency Modulated signal');
F = 1000; % sampling frequency
f0 = fc; % carrier
f1 = fm; % modulating tone
beta = m; % modulation index
% signal, spectrum
N = 1000;
t = (0:N-1)*(1/F); % delt = 1us
z = fftshift(fft(y))/N;
f = (-N/2:N/2-1)*(F/N);
% predicted sidebands for the positive frequencies only
n = 4;
sidamp = (1/2)*besselj(0:n,beta);
sidamp = [fliplr(sidamp(2:end)), sidamp];
sidf = (f0-n*f1):f1:(f0+n*f1);
figure(2)
subplot(2, 1, 1);
plot(f,abs(z))
xlim([-2*f0 2*f0])
subplot(2, 1 ,2 );plot(f,abs(z),sidf,sidamp,'o')
xlim([f0-f1*10 f0+f1*10]) % sidebands at the pos frequencies

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modulation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by