5 views (last 30 days)

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

Prajit T R
on 29 Jun 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

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.