usinf fft shift i need only to display the positive part of the spectrum

12 ビュー (過去 30 日間)
Mohamed Ashraf
Mohamed Ashraf 2018 年 2 月 20 日
回答済み: wallflower 2020 年 12 月 7 日
I would like to display only the positive part of the frequency domain
if true
%
fs=1e5; %Sampling Frequency
t=0:1/(fs):0.001; %Time at which signal displays
%First,generating a signal
f=1e4;%Signal is 10kHz
amp_signal=1;
signal=amp_signal*(sin(2*pi*f*t));
%Frequency Domain of transmitted signal
transmited_signal_fft=fft(signal);
transmited_signal_fft=fftshift(transmited_signal_fft);
f_axis=linspace(-fs/2,fs/2,length(transmited_signal_fft));
%Plotting Signal
figure;
subplot(2,1,1);
plot(t,signal);
grid on;
title('Transmitted signal in time domain')
%Display transmitted signal in frequency domain
subplot(2,1,2);
plot(f_axis,abs(transmited_signal_fft)/length(signal));
grid on;
title('Transmitted signal in frequency domain')
end
Thanks in advance

採用された回答

Star Strider
Star Strider 2018 年 2 月 21 日
Try this:
fs=1e5; %Sampling Frequency
t=0:1/(fs):0.001; %Time at which signal displays
%First,generating a signal
f=1e4;%Signal is 10kHz
Fn = f/2; % Nyquist Freqency (Added)
amp_signal=1;
signal=amp_signal*(sin(2*pi*f*t));
L = length(signal); % Added
%Frequency Domain of transmitted signal
transmited_signal_fft=fft(signal);
f_axis = linspace(0, 1, fix(L/2)+1)*Fn; % Changed
Iv = 1:length(f_axis); % Index Vector (Added)
% % transmited_signal_fft=fftshift(transmited_signal_fft); % (Commented-Out)
% % f_axis=linspace(-fs/2,fs/2,length(transmited_signal_fft)); % (Commented-Out)
%Plotting Signal
figure;
subplot(2,1,1);
plot(t,signal);
grid on;
title('Transmitted signal in time domain')
%Display transmitted signal in frequency domain
subplot(2,1,2);
plot(f_axis, 2*abs(transmited_signal_fft(Iv))/L); % Changed
grid on;
title('Transmitted signal in frequency domain')
See this version of the documentation for details: fft (link).
  2 件のコメント
Mohamed Ashraf
Mohamed Ashraf 2018 年 2 月 21 日
the nyquist frequency should be double the message not half of it
Nyquist Frequency:the minimum rate at which a signal can be sampled without introducing errors, which is twice the highest frequency present in the signal.
Star Strider
Star Strider 2018 年 2 月 21 日
The nyquist frequency is one-half the sampling frequency. It should be fs/2, and I thought I typed it as such.

サインインしてコメントする。

その他の回答 (2 件)

Abhishek Ballaney
Abhishek Ballaney 2018 年 2 月 21 日
https://in.mathworks.com/help/matlab/ref/fft.html

wallflower
wallflower 2020 年 12 月 7 日
Hi,
Did you find the answer?

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by