% 绘制三角调频连续波
clc;
clear all;
close all;
% 测试三角调频连续波FFT以及菲涅尔频率
% B = 400.e6; % 400MHz 带宽
% T = 10.e-6; % 10us 调制周期
% mu = 4 .* pi * B / T;
% delt = linspace(-T/2,T/2,10001); % 1ns 采样间隔
% fc = 9.e9; % 9GHz 载频
% triangle = tripuls(delt,T);
% triangle1 = triangle.*B;
% tri_fre = triangle.*B; %triangle_frequency tri_fre
% figure
% % plot(delt*1e6,triangle);
% % plot(delt,triangle);
% % plot(delt*1e6,triangle1);
% plot(delt,triangle1);
% axis xy
%
% Ichannal = cos(0.5.*tri_fre.*delt);
% Qchannal = sin(0.5.*tri_fre.*delt);
% LFM = Ichannal + sqrt(-1) .* Qchannal; % complex signal
% LFMFFT = fftshift(fft(LFM));
% figure
% plot(Ichannal);
% axis xy
% figure
% plot(Qchannal);
% axis xy
% figure
% plot(abs(LFMFFT));
% axis xy
%函数中频率带宽显示的就是菲涅尔频谱
close all
clear all
eps = 0.000001;
%Enter pulse width and bandwidth
B = 400.0e6; %400 MHZ bandwidth
T = 10.e-6; %10 micro second pulse;
% Compute alpha
mu = 4. * pi * B / T;
% Determine sampling times
delt = linspace(-T/2., T/2., 10001); % 1 nano sceond sampling interval
len = length(delt);
len_up = round(len/2);
len_down = len - len_up;
% Compute the complex LFM representation
% 三角波上调频信号
delt_up = delt(1:len_up);
Ichannal_up = cos(mu .* delt_up.^2 / 2.); % Real part
Qchannal_up = sin(mu .* delt_up.^2 / 2.); % Imaginary Part
Ichannal = Ichannal_up;
Qchannal = Qchannal_up;
LFM = Ichannal + sqrt(-1) .* Qchannal; % complex signal
%Compute the FFT of the LFM waveform
LFMFFT_up = fftshift(fft(LFM,len));
LFMFFT = LFMFFT_up;
% Plot the real and Immaginary parts and the spectrum
freqlimit = 0.5 / 1.e-9;% the sampling interval 1 nano-second
freq = linspace(-freqlimit/1.e6,freqlimit/1.e6,10001);
figure(1)
plot(delt_up*1e6,Ichannal,'k');
axis([-1 1 -1 1])
grid
xlabel('Time - microsecs')
ylabel('Real part')
title('T = 10 Microsecond, B = 400 MHz')
figure(2)
plot(delt_up*1e6,Qchannal,'k');
axis([-1 1 -1 1])
grid
xlabel('Time - microsecs')
ylabel('Imaginary part')
title('T = 10 Microsecond, B = 400 MHz')
figure(3)
plot(freq, abs(LFMFFT),'k');
%axis tight
grid
xlabel('Frequency - MHz')
ylabel('Amplitude spectrum')
title('Spectrum for an LFM waveform and T = 10 Microsecond, B = 400 MHZ')
% 三角波下调频信号
delt_down = delt(len_up+1:len);
Ichannal_down = cos(-mu .* delt_down.^2 / 2.); % Real part
Qchannal_down = sin(-mu .* delt_down.^2 / 2.); % Imaginary Part
Ichannal = Ichannal_down;
Qchannal = Qchannal_down;
LFM = Ichannal + sqrt(-1) .* Qchannal; % complex signal
%Compute the FFT of the LFM waveform
LFMFFT_down = fftshift(fft(LFM,len));
LFMFFT = LFMFFT_down;
% Plot the real and Immaginary parts and the spectrum
freqlimit = 0.5 / 1.e-9;% the sampling interval 1 nano-second
freq = linspace(-freqlimit/1.e6,freqlimit/1.e6,10001);
figure(4)
plot(delt_down*1e6,Ichannal,'k');
axis([-1 1 -1 1])
grid
xlabel('Time - microsecs')
ylabel('Real part')
title('T = 10 Microsecond, B = 400 MHz')
figure(5)
plot(delt_down*1e6,Qchannal,'k');
axis([-1 1 -1 1])
grid
xlabel('Time - microsecs')
ylabel('Imaginary part')
title('T = 10 Microsecond, B = 400 MHz')
figure(6)
plot(freq, abs(LFMFFT),'k');
%axis tight
grid
xlabel('Frequency - MHz')
ylabel('Amplitude spectrum')
title('Spectrum for an LFM waveform and T = 10 Microsecond, B = 400 MHZ')
% 完整的三角波调频连续波信号
Ichannal = [Ichannal_up Ichannal_down];
Qchannal = [Qchannal_up Qchannal_down];
LFMFFT = abs(LFMFFT_up) + abs(LFMFFT_down);
% Plot the real and Immaginary parts and the spectrum
freqlimit = 0.5 / 1.e-9;% the sampling interval 1 nano-second
freq = linspace(-freqlimit/1.e6,freqlimit/1.e6,10001);
figure(7)
plot(delt*1e6,Ichannal,'k');
axis([-1 1 -1 1])
grid
xlabel('Time - microsecs')
ylabel('Real part')
title('T = 10 Microsecond, B = 400 MHz')
figure(8)
plot(delt*1e6,Qchannal,'k');
axis([-1 1 -1 1])
grid
xlabel('Time - microsecs')
ylabel('Imaginary part')
title('T = 10 Microsecond, B = 400 MHz')
figure(9)
plot(freq, abs(LFMFFT),'k');
%axis tight
grid
xlabel('Frequency - MHz')
ylabel('Amplitude spectrum')
title('Spectrum for an LFM waveform and T = 10 Microsecond, B = 400 MHZ')