Clear Filters
Clear Filters

problem in drawing the frequency spectrum of frequency modulated signal in matlab

3 views (last 30 days)
here is the coding, the output of the frequency spectrum has no value... the error is
Index exceeds the number of array elements. Index must not exceed 1001.
Error in frequency_modulation (line 39)
plot(f(9500:10500),Vfm_f(9500:10500));
can anyone check? thank you so much.
fs=100000; %sampling frequency
ts = 1/fs ; % time interval between sample point
t = 0 : ts :0.02; % scale of time, maximun=0.02
N= size(t,2);
fm=100;
Vm=2*sin(2*pi*100*t);
fc=10000;
Vc=10*cos(2*pi*10000*t);
Vfm= 10*cos(2*pi*fc*t + 2*sin(2*pi*fm*t)); %modulated signal= Vfm
subplot(4,1,1);
plot(t,Vc);
ylabel('Amplitude (V)');
xlabel('Time(s)');
title('Carrier Signal Time Domain Representation');
grid on;
subplot(4,1,2);
plot(t,Vm);
ylabel('Amplitube (V)');
xlabel('Time (s)');
title('Message signal Time Domain Representation');
grid on;
subplot(4,1,3);
plot(t,Vfm);
ylabel('Amplitube (V)');
xlabel('Time (s)');
title('Frequency Modulated Signal Time Domain Representation');
grid on;
f=fs*(0:N/2)/N;
Vfm_f = (2/N)*abs(fft(Vfm,N));
subplot(4,1,4);
plot(f(9500:10500),Vfm_f(9500:10500));
ylabel('Amplitube (V)');
xlabel('Frequency(Hz)');
title('Frequency Modulated Signal Frequency Representation');
grid on;

Accepted Answer

Chunru
Chunru on 11 Dec 2021
fs=100000; %sampling frequency
ts = 1/fs ; % time interval between sample point
t = 0 : ts :0.02; % scale of time, maximun=0.02
N= size(t,2);
fm=100;
Vm=2*sin(2*pi*100*t);
fc=10000;
Vc=10*cos(2*pi*10000*t);
Vfm= 10*cos(2*pi*fc*t + 2*sin(2*pi*fm*t)); %modulated signal= Vfm
subplot(4,1,1);
plot(t,Vc);
ylabel('Amplitude (V)');
xlabel('Time(s)');
title('Carrier Signal Time Domain Representation');
grid on;
subplot(4,1,2);
plot(t,Vm);
ylabel('Amplitube (V)');
xlabel('Time (s)');
title('Message signal Time Domain Representation');
grid on;
subplot(4,1,3);
plot(t,Vfm);
ylabel('Amplitube (V)');
xlabel('Time (s)');
title('Frequency Modulated Signal Time Domain Representation');
grid on;
f=fs*(0:N/2)/N;
Vfm_f = (2/N)*abs(fft(Vfm,N));
Vfm_f=Vfm_f(1:floor(N/2)+1); % take the half: positive frequency
subplot(4,1,4);
plot(f,Vfm_f);
xlim([5000 15000])
ylabel('Amplitube (V)');
xlabel('Frequency(Hz)');
title('Frequency Modulated Signal Frequency Representation');
grid on;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!