# how to solve a Plotting FFT problem

1 Ansicht (letzte 30 Tage)
Mohamed Ashraf am 18 Feb. 2018
Beantwortet: John BG am 18 Feb. 2018
I have this code for generating a signal and plotting it in time domain and frequency domain but the plot in the frequency domain has a problem as I suppose frequency to be 1000 but it plots around it not the 1000 and not the 500 and -500 can any body help??
Code:
if true
%First,generating a signal and plotting it
f=input('Enter Signal Frequency=');
amp_signal=input('Enter ampliude of transmitted Signal Frequency=');
signal=amp_signal*(sin(2*pi*f*t));
%Frequency Domain of transmitted signal
trans_signal_fft= fft(signal);
trans_signal_fft = fftshift(trans_signal_fft);
f_axis = linspace((-f),(f),length(trans_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,trans_signal_fft);
grid on;
title('Transmitted signal in frequency domain')
end
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

John BG am 18 Feb. 2018
Hi Mohamed
if the time vector does not have a small enough step the output will show a shifted frequency, or not even show any frequency at all. Try the following
f=1000;
amp_signal=1;
t=[0:1/(2*f):1];
just on 2 samples per cycle, and it's not clear what is the input. Don't work on the edge, try to get as many samples as reasonably possible per cycle. .
Using 4 samples per cycle
.
t=[0:1/(4*f):.5]; .
and here you have the input tone.
Bear in mind that it would make sense to plot amplitude and phase, or real in imaginary, just plugging the complex fft into plot is not the way to proceed, choose what you want to plot.
thanks in advance for time and attention
John BG
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Pulsed Waveforms in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!