spectrogram os sent and received signal
2 次查看(过去 30 天)
显示 更早的评论
Hello
i tried to estimate the range of target by using fft
i had a problem in plot the spectrogram of sent and receives signal which should have the same spectrom but the defference is in delay, but i got always different specrom as you see in figure 5
how can solve this problem ?
how can fill zeros in front of received signal ?
the right way is that the sent and received should start from the same frequency but the received has time delay![s.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231426/s.png)
![s.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231426/s.png)
clc;
close all;
clear all;
%% parameters
fs = 100e3; % sampling frequency
fc = 20e3; % carrier frequency
Ts = 1/fs; % sampling period
BW = 10e3; % bandwidth
T = 50e-3; % period
c = 340; % speed of sound in air
N = T/Ts; %N is uded for the length of FFT
ff = linspace(-fs/2,fs/2,2*N); %frequency vector of FFT
numRep = 50; % to get contiues wave we want to repaeate the chirp 50 times
%% Tx Signal
tu = 0:Ts:T-Ts; %time range of the upsweep
td = T:-Ts:0; %time range of the downsweep
tt = [tu td]; %time range of the chirp
% generate Tx signal
TxSig = cos((2*pi*(fc-BW/2)*tt)+(pi*BW*(tt.^2)/T)); %transmitted signal
TxSig = TxSig + randn(size(TxSig));
RepTxSig = repmat(TxSig,[1,numRep]); %repeat the transmitted signal 50 times to get FMCW wave
% plot Tx signal in time domain
figure();
plot(tt,TxSig); %plot the transmitted signal
grid on;
title('Transmitted Signal')
xlabel('Time (Seconds)'); ylabel('Amplitude');
% plot spectrogram for Tx signal
figure();
[St,Ft,t,Pt] = spectrogram(RepTxSig,256,128,256,fs); %to get the relation between the time with frequency and power density.
surf(t,Ft,10*log10(Pt),'edgecolor','none'); axis tight; %to get the graph 3D
view(0,90); %to get the top projection of 3D grath
title('Spectrogram for Tx Signal')
xlabel('Time (Seconds)'); ylabel('freq. (Hz)');
% plot Tx signal in freq. domain
fftTx = fftshift(fft(RepTxSig,2*N));
fftTxdb = 20*log10(abs(fftTx));
figure();
plot(ff,fftTxdb-max(fftTxdb))
axis tight;
grid on;
title('FFT of Transmitted Signal')
xlabel('freq. (Hz)'); ylabel('Amplitude (dB)');
%% Rx Signal with target range and delay
R = 3.5;
to = 2*R/c;
% offset
K = to/Ts;
tu = (K*Ts)-to:Ts:T-Ts;
td = T:-Ts:0;
tr = [tu td];
% generate Rx signal
RxSig = cos((2*pi*(fc-BW/2)*(tr-to))+(pi*BW*((tr-to).^2)/T));
figure();
plot(tr,RxSig);
grid on;
title('Received Signal')
xlabel('Time (Seconds)'); ylabel('Amplitude');
% plot spectrogram for Tx signal and Rx signal
figure();
[Sr,Fr,t,Pr] = spectrogram(RepRxSig,256,128,256,fs);
surf(t,Fr,10*log10(Pr),'edgecolor','none'); axis tight;
view(0,90);
title('Spectrogram for Tx Signal and Rx Signal')
xlabel('Time (Seconds)'); ylabel('Hz');
caxis([-60 -30])
colorbar
hold on
[St,Ft,t,Pt] = spectrogram(RepTxSig,256,128,256,fs);
surf(t,Ft,10*log10(Pt),'edgecolor','none');
% plot Rx signal in freq. domain
fftRx = fftshift(fft(RepRxSig,2*N));
fftRxdb = 20*log10(abs(fftRx));
figure();
plot(ff,fftRxdb-max(fftRxdb))
axis tight;
grid on;
title('FFT of Received Signal')
xlabel('freq. (Hz)'); ylabel('Amplitude (dB)');
%% Mixing
MixSig = RepTxSig.*RepRxSig;
figure();
plot(MixSig);
grid on;
title('Mixed Signal')
%% Range detection
Y = fftshift(fft(MixSig,2*N));
Ydb = 20*log10(abs(Y));
figure;
plot(ff,Ydb-max(Ydb))
axis tight;
grid on;
title('FFT of Mixed Signal')
xlabel('freq. (Hz)'); ylabel('Amplitude (dB)');
ind=find(Ydb(N+1:2*N)==max(Ydb(N+1:2*N)));
f1=ff(N+ind);
ind=find(Ydb(1:N)==max(Ydb(1:N)));
f2=-ff(ind);
fb=(f1+f2)/2; % estimating shift frequency
estR = c*fb*T/(2*BW) % estimated range of the target
%% end
![spectro.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231427/spectro.png)
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!