-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_FFT_IQ.m
45 lines (39 loc) · 1.26 KB
/
plot_FFT_IQ.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function plot_FFT_IQ(x,n0,nf,fs,f0,title_of_plot)
%
% plot_FFT_IQ(x,n0,nf)
%
% Plots the FFT of sampled IQ data
%
% x -- input signal
% fs -- sampling frequency [MHz]
% f0 -- center frequency [MHz]
% n0 -- first sample (start time = n0/fs)
% nf -- block size for transform (signal duration = nf/fs)
% title_of_plot--title of plot (string) (optional)
%
%-This extracts a segment of x starting at n0, of length nf, and plots the FFT.
n0=round(n0); %round to integer. 1st sample = 1
nf=round(nf); %round to integer. Last Sample = 488
x_segment=x(n0:(n0+nf-1)); %extracts a small segment of data from IQ data
p=fftshift(fft(x_segment)); %FFT
z = 20*log10(abs(p)/max(abs(p))); %normalize
Low_freq=(f0-fs/2); %lowest frequency to plot
High_freq=(f0+fs/2); %highest frequency to plot
N=length(z); % num of samples in signal
freq=[0:1:N-1]*(fs)/N+Low_freq;
plot(freq,z);
axis tight
xlabel('Freqency [MHz]','FontSize', 14)
ylabel('Magnitude [dB down from max]','FontSize', 14)
grid on
set(gcf,'color','white');
if nargin==6
title(title_of_plot,'FontSize', 14)
else
title({'Spectrum',['Center frequency = ' num2str(f0) ' MHz'] },'FontSize', 14)
end
%Add line @ center freq
y1=get(gca,'ylim');
hold on;
plot([f0 f0],y1,'r-','linewidth',2);
hold off;