How to convert time domain to frequency domain

조회 수: 64 (최근 30일)
ong jia eek
ong jia eek 2019년 9월 30일
편집: Rumana Afrin 2022년 6월 14일
This is my code, I failed to convert time domain to frequency domain, as I not sure on how to create the right frequency for frequency domain graph
%FM generation
clc;
clear all;
close all;
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= ');
t=(1/fc)*20;
t=0:0.0001:t;
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');
fs=1000;
z=fft(y);
subplot(2,1,4);plot(t,z);
figure;
ylabel('amplitude');xlabel('frequency domain');title('Frequency Modulated signal');
  댓글 수: 1
Adam
Adam 2019년 9월 30일
You need to plot
abs(z)
or
abs(z).^2
if you prefer, rather than just z, which should be complex and will default to plotting the real part.

댓글을 달려면 로그인하십시오.

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 9월 30일
편집: Shubham Gupta 2019년 9월 30일
Replace the following line :
subplot(2,1,4);plot(t,z);
figure;
by the following code
nfft = length(y);
f = (0:1/nfft:1-1/nfft)*fs; % define frequency-domain
figure; % figure should be written before subplot to open new figure
subplot(2,1,1); % subplot(2,1,4) will give error beacause for a 2x1 vector valid indeces are 1&2, 4 is wrong
plot(f,z); % t (time-domain) is replace with f (frequency-domain)
Let me if you have any doubts
  댓글 수: 2
ong jia eek
ong jia eek 2019년 9월 30일
yes it is working but may I ask why the result shows as below?
1.JPG
Shubham Gupta
Shubham Gupta 2019년 10월 1일
I am glad it worked. In the above graph, every peak in y-axis shows that there is a signal of corresponding frequency shown in x-axis.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rumana Afrin
Rumana Afrin 2022년 6월 14일
편집: Rumana Afrin 2022년 6월 14일
%Parameters
y1 = A_norm*sin(2*pi*100*t);
y2 = A_norm*sin(2*pi*200*t);
y3 = A_norm*sin(2*pi*300*t);
y4 = A_norm*sin(2*pi*400*t);
y5 = A_norm*sin(2*pi*500*t);
y6 = A_norm*sin(2*pi*600*t);
y = [y1; y2; y3; y4; y5; y6];
%Frequency content
X = fft(y);
fft_abs = abs(X);
figure;
for i = 1:6
A_norm(i) = A_norm(:,i);
X(i) = fft(y(i));
fft_abs(i) = abs(X(i));
subplot(3,3,i)
plot(fft_abs(i))
xlabel('Frequency(kHz)')
ylabel('Magnitude')
title('Frequency domain')
end
Hi, I do not understand where have I done wrong. Where A_norm is

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by