Convolution of Signals Hw2prob1: 'N' 'Amplitude' 'Signal HN'
Convolution of Signals Hw2prob1: 'N' 'Amplitude' 'Signal HN'
figure
stem(n,hn)
xlabel('n');
ylabel('Amplitude');
title('Signal hn')
xn = (1/2).^n;
figure
stem(n,xn)
xlabel('n');
ylabel('Amplitude');
title('Signal xn')
yn=conv(xn,hn)
figure
stem(yn)
xlabel('n');
ylabel('Amplitude');
title('Signal yn')
Plotting functions
Signal 1
syms t
x=exp(-2*t);
x=(x).*(heaviside(t))
ezplot(x,[-1 5 0 1.5])
figure
h=exp(-t).*cos(t).*t;
h=(h).*(heaviside(5*pi*t));
ezplot(h,[-1 5 0 1.5])
Signal 2
figure
plot(t,x2+x1)
title('x1+x2')
figure
plot(t,x2.*x1)
title(' x1*x2')
Square signals
repeating_segment = [ zeros(1, 100) ones(1, 100)];
num_periods = 10;
square_waveform = []; % empty variable
for k = 1 : num_periods
square_waveform = [square_waveform repeating_segment];
end
plot(square_waveform);
ylim([-0.1 1.1])
Triangular Signal
n = [n1:n2];
x = [(n-n0) == 0];
end
figure(1)
y=impseq(0,-5,5)+impseq(3,-5,5)
stem([-5:5],y)
figure(2)
syms t
k=heaviside(t+1)-heaviside(t-3);
ezplot(k,[-5 5 0 2])
figure(3)
w=impseq(0,-5,5)+(1/2).*impseq(1,-5,5)+(1/2^2).*impseq(2,-
5,5)+(1/2^3).*impseq(3,-5,5)+(1/2^4).*impseq(4,-5,5)
stem([-5:5],w)
figure(4)
syms t
x=(exp(-t)).*(heaviside(t))
ezplot(x,[-1 5 0 1.5])
Frequency Analysis
t=-1:0.001:1;
x=sin(2*pi*50*t);
%x=sin(2*pi*50*t)+sin(2*pi*75*t);
%x=sin(2*pi*20*t)+4*cos(2*pi*50*t)+2*sin(2*pi*100*t)+7*randn(size(t));
figure
plot(t(1001:1200),x(1:200))
grid
title('Sin(2\pi50t)')
xlabel('Time, s')
figure
X=abs(fft(x));
X2=fftshift(X);
f=-499.9:1000/2001:500;
plot(f,X2);
grid
title(' Frequency domain representation of Sin(2\pi50t)')
xlabel('Frequency, Hz.')
Bass Guitar example
%http://eleceng.dit.ie/dorran/matlab/bass.wav
N = length(mag_ft);
freq_scale = 0: fs/(N-1):fs;
figure(3)
plot(freq_scale, mag_ft);
ylabel('Magnitude/Amplitude')
xlabel('Frequency (Hz)')
figure(5)
plot(bass_guitar);
ylabel('Amplitude')
xlabel('Sample Number')
figure(6)
plot(freq_scale, mags)
ylabel('Magnitude/Amplitude')
xlabel('Frequency (Hz)')