Error in plot(t,[y x]).. can anyone help me with this code i am trying matched filter of rectangular pulse to awgn signal..firstly i am convolving these two signals ande then taking and then matching. what is wrong in this code

5 vues (au cours des 30 derniers jours)
clear; % sampling frequency fs = 1e9; % time duration for pulse of start and end td = 10e-9; % number of steps in linspace N = 513; % width of rect pulse w= 1e-9; % time t = linspace(-td,td,N); dt = t(2)-t(1); T = t(end)-t(1) + (t(2)-t(1)); f = 1/T * (-(N-1)/2 : (N-1)/2); %square pulse subplot(3,2,1) y = rectpuls(t,w); plot(t,y) xlabel('Time') ylabel('Amplitude') title('rectangular pulse') grid on; %fourier transform of square pulse: ATsinc(fT) %where f is a frequency variable. A is the amplitude of the pulse, %assumed to be 1 subplot(3,2,2) Y = w*fft(y); sz = size (y) Yplot = fftshift(Y); plot(f,abs(Yplot)) xlabel('frequency') ylabel('Amplitude') title('fft=sinc func') grid on;
% noise added with signal x = awgn(y,10,'measured'); subplot(3,2,3) plot(t,[y x]) legend('Original Signal','Signal with AWGN') title('signal and noise') grid on % convolution at multiplier s1=fft(x); s2=fft(y); y2=conv(s1,s2) subplot(3,2,4) plot(y2) title('convolution of FFT') grid on % matched filter output y3=ifft(y2); subplot(3,2,5) plot(y3) title('matched filter output') grid on

Réponse acceptée

Prajit T R
Prajit T R le 29 Juin 2018
Hi
The only error in your code is in the line 'plot(t,[y x])'. If you want to plot the signal and noise in the same subplot, you should use 'hold on' and 'hold off'.
I am attaching the corrected code here. Next time kindly submit codes in the right format and attach error messages so that it will be easier for people in the community to answer your question.
clear;
% sampling frequency
fs = 1e9;
% time duration for pulse of start and end
td = 10e-9;
% number of steps in linspace
N = 513;
% width of rect pulse
w= 1e-9;
% time
t = linspace(-td,td,N);
dt = t(2)-t(1);
T = t(end)-t(1) + (t(2)-t(1));
f = 1/T * (-(N-1)/2 : (N-1)/2);
%square pulse
subplot(3,2,1)
y = rectpuls(t,w);
plot(t,y)
xlabel('Time')
ylabel('Amplitude')
title('rectangular pulse')
grid on;
%fourier transform of square pulse: ATsinc(fT)
%where f is a frequency variable. A is the amplitude of the pulse,
%assumed to be 1
subplot(3,2,2)
Y = w*fft(y);
sz = size(y)
Yplot = fftshift(Y);
plot(f,abs(Yplot))
xlabel('frequency')
ylabel('Amplitude')
title('fft=sinc func')
grid on;
% noise added with signal
x = awgn(y,10,'measured');
subplot(3,2,3)
plot(t,y)
hold on
plot(t,x)
hold off
legend('Original Signal','Signal with AWGN')
title('signal and noise')
grid on
% convolution at multiplier
s1=fft(x);
s2=fft(y);
y2=conv(s1,s2)
subplot(3,2,4)
plot(y2)
title('convolution of FFT')
grid on
% matched filter output
y3=ifft(y2);
subplot(3,2,5)
plot(y3)
title('matched filter output')
grid on
Note that the legend in subplot 3 might be obstructing the view of the signals. You can enlarge the figure to view it properly, and move the legend using your mouse.
Hope this helps
Prajit
  1 commentaire
CHAIDEOT
CHAIDEOT le 3 Juil 2018
Thanks prajit, I appreciate your help and error message will be displayed properly from next time .

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Parametric Spectral Estimation dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by