Dsp

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Dsp as PDF for free.

More details

  • Words: 655
  • Pages: 12
ramp input: y=input('Enter the length of the ramp sequence:'); t=1:1:y; subplot(1,1,1); stem(t,t); ylabel('Amplitude'); xlabel('|a|n'); title('Ramp Signal');

sine wave: t=0:.01:pi; y=sin(2*pi*t); subplot(1,1,1); stem(t,y); ylabel('Amplitude'); xlabel('|a|n'); title('Sine Signal'); step signals: n=input('Enter the N value:'); t=0:1:n-1; y=ones(1,n); subplot(1,1,1); stem(t,y); ylabel('Amplitude'); xlabel('|a|n'); title('Step Signal'); cosine wave

t=0:.01:pi; y=cos(2*pi*t); subplot(1,1,1); stem(t,y); ylabel('Amplitude'); xlabel('|a|n'); title('cosine Signal'); exponential wave: n=input('Enter the value:'); t=0:1:n-1;

page1..

a=input('Enter the value of a:'); y=exp(a*t); subplot(1,1,1); stem(t,y); ylabel('amplitude'); xlabel('|a|n'); title('Exponential Signal');

impulse input: t=-4:1:4; y=[zeros(1,4),ones(1,1),zeros(1,4)]; subplot(1,1,1); stem(t,y); ylabel('amplitude'); xlabel('|a|n'); title('Unit Impulse Signal'); circular convolution: clc; clear all; close all; x=[1,2,3]; h=[2,3,1]; x=x'; h=h'; z=[h,circshift(h,1),circshift(h,2),circshift(h,3)]; y=z*x; subplot(3,3,1); stem(x); subplot(3,3,2); stem(h); subplot(3,3,3); stem(y); xlabel('sequence'); ylabel('amp----->');

linear convolution x=[1,2,1]; h=[1,2]; y=conv(x,h); subplot(3,1,1); stem(x); subplot(3,1,2); stem(h);

page2..

subplot(3,1,3); stem(y); xlabel('sequence---->'); ylabel('amp------->');

deconvolution x=[1,2,1]; h=[1,2]; y=deconv(x,h); subplot(3,1,1); stem(x); subplot(3,1,2); stem(h); subplot(3,1,3); stem(y); xlabel('sequence---->'); ylabel('amp------->');

Sampling: fs1=50; t1=0:1/fs1:1; y1=5*sin(2*pi*5*t1); stem(t1,y1); title('sampling theorem'); aliasing: Clear all: t=-10:1:10; T=4; Fm=1/T; x=cos(2*pi*fm*t); fs1=1.6*fm; fs2=2*fm; n1=-4:1:4; xn1=cos(2*pi*n1*fm/fs1); Subplot (2,2,1); Plot (t,x);

page3..

xlabel('time in sec'); ylabel('x(t)'); title ('continous tine signal'); subplot (2,2,2); stem(n1,xn1); hold on; subplot(2,2,2); plot(n1,xn1); xlabel('n'); ylabel('x(n)'); title('discrete signal with fsfm'); fft clc; clear all; close all; xn=[1 1 1]; N=16; xk=fft(xn,N); magxk=abs(xk); avgxk=angle(xk); k=0:1:N-1; subplot(2,1,1);

page4..

stem(k,magxk); xlabel('k'); ylabel('|x(k)|'); subplot(2,1,2); stem(k,avgxk); xlabel('k'); ylabel('avgx(k)')

ifft: clc; clear all; close all; xn=[1 1 1]; N=16; xk=ifft(xn,N); magxk=abs(xk); avgxk=angle(xk); k=0:1:N-1; subplot(2,1,1); stem(k,magxk); xlabel('k'); ylabel('|x(k)|'); subplot(2,1,2); stem(k,avgxk); xlabel('k'); ylabel('avgx(k)'); Kaiser window clc; clear all; close all; alpha=0.1; alphas=44; ws=30;wp=20; wsf=100; B=ws-wp; wc=0.5*(ws+wp); wcr=wc*2*pi/wsf; D=(alphas-7.95)/14.36; N=ceil((wsf*D/B)+1); alpha=(N-1)/2; gamma=(0.5842*(alphas-21)^(0.4)+0.07886*(alphas-21));

page5…

n=0:1:N-1; hd=sin(wcr*(n-alpha))/(pi*(n-alpha)); bd(alpha+1)=0.5; wk=(kaiser(N,gamma)); hn=hd*wk; w=0:0.01:pi; h=freqz(hn,1,w); subplot(2,1,1); plot(w/pi,20*log10(abs(h))); title('Kaiser window'); ylabel('magnitude in db'); xlabel('normalised frequency'); subplot(2,1,2); plot(w/pi,angle(h)); ylabel('magnitude in db'); xlabel('normalised frequency');

windows: clc; clear all; close all; figure(1); wc=0.5*pi; N=10; alpha=(N-10)/2; eps=0.001; h=0:1:N-1; hd=sin(wc*(h-alpha+eps))/(pi*(h-alpha+eps)); wr=boxcar(N); hn=hd*wr; w=0:0.01:pi; h=freqz(hn,1,w); plot(w/pi,abs(h)); hold on; figure(2); wh=hanning(N); hn=wh*hd; w=0:0.01:pi; h=freqz(hn,1,w); plot(w/pi,abs(h),'-'); grid; ylabel('magnitude');

page6…

xlabel('normalised frequency'); hold off; figure(3); whn=hamming(N); hn=hd*whn; w=0:0.01:pi; hn=freqz(hn,1,w); plot(w/pi,abs(h),'-'); grid; hold off; figure(4); wb=blackman(N); hn=hd*wb; w=0:0.01:pi; hn=freqz(hn,1,w); plot(w/pi,abs(h),'-'); grid; ylabel('magnitude'); xlabel('normalised frequency'); hold off;

butterworth bandpass filter clc; clear all; close all; alphap=2; alphas=20; wp=[0.2*pi,0.4*pi]; ws=[0.1*pi,0.5*pi]; [n,wn]=buttord(wp/pi,ws/pi,alphap,alphas); [b,a]=butter(n,wn); w=0:0.01:pi; [b,pb]=freqz(b,a,w); m=20*log(abs(b)); an=angle(b); subplot(2,1,1); plot(pb/pi,m); grid; xlabel('normalised frequency'); ylabel('gain in db');

page7…

title('Butterworth band pass filter'); subplot(2,1,2); plot(pb/pi,an); grid; xlabel('normalised frequency'); ylabel('phase in radians');

butterworth highpass filter clc; clear all; close all; alphap=0.4; alphas=30; fp=400; fs=800; F=2000; omp=2*fp/F;oms=2*fs/F; [n,wn]=buttord(omp,oms,alphap,alphas); [b,a]=butter(n,wn,'high'); w=0:0.01:pi; [n,om]=freqz(b,a,w); m=abs(n); an=angle(n); subplot(2,1,1); plot(om/pi,20*log(m)); grid; title('Butterworth high pass filter'); ylabel('gain in db'); xlabel('normalized frequency'); subplot(2,1,2); plot(om/pi,an); grid; ylabel('phase radius'); xlabel('normalized frequency');

band pass band reject filter clc; clear all; close all; alphap=2; alphas=20; wp=[0.2*pi,0.4*pi];

page8..

ws=[0.1*pi,0.5*pi]; [n,wn]=buttord(wp/pi,ws/pi,alphap,alphas); [b,a]=butter(n,wn,'stop'); w=0:0.01:pi; [b,pb]=freqz(b,a,w); m=20*log(abs(b)); an=angle(b); subplot(2,1,1); plot(pb/pi,m); grid; title('Butterworth band reject filter'); xlabel('normalised frequency'); ylabel('gain in db'); subplot(2,1,2); plot(pb/pi,an); grid; xlabel('normalised frequency'); ylabel('phase in radians');

butterworth low passfilter clc; clear all; close all; alphap=0.4; alphas=30; fp=400; fs=800; F=2000; omp=2*fp/F;oms=2*fs/F; [n,wn]=buttord(omp,oms,alphap,alphas); [b,a]=butter(n,wn); w=0:0.01:pi; [n,om]=freqz(b,a,w,'whole'); m=abs(n); an=angle(n); subplot(2,1,1); plot(om/pi,20*log(m)); grid; title('Butterworth low pass filter'); xlabel('normalized frequency'); ylabel('gain in db');

page9…

subplot(2,1,2); plot(om/pi,an); grid; ylabel('phase radius'); xlabel('normalized frequency');

chebychev type1-bandpassfilter: clc; clear all; close all; alphap=2; alphas=20; wp=[0.2*pi,0.4*pi]; ws=[0.1*pi,0.5*pi]; [n,wn]=buttord(wp/pi,ws/pi,alphap,alphas); [b,a]=cheby1(n,alphap,wn); w=0:0.01:pi; [b,pb]=freqz(b,a,w); m=20*log(abs(b)); an=angle(b); subplot(2,1,1); plot(pb/pi,m); grid; title('Chebychev type-1 band pass flter'); xlabel('normalised frequency'); ylabel('gain in db'); subplot(2,1,2); plot(pb/pi,an); grid; xlabel('normalised frequency'); ylabel('phase in radians');

chebychev type1-lowpassfilter: clc; clear all; close all; alphap=1; alphas=15; wp=0.2*pi; ws=0.3*pi;

page10…

[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas); [b,a]=cheby1(n,alphap,wn); w=0:0.01:pi; [b,pb]=freqz(b,a,w); m=20*log(abs(b)); an=angle(b); subplot(2,1,1); plot(pb/pi,m); grid; xlabel('normalised frequency'); ylabel('gain in db'); title('Chebychev type-1 low pass flter'); subplot(2,1,2); plot(pb/pi,an); grid; xlabel('normalised frequency'); ylabel('phase in radians');

chebychev type2-bandrejectfilter: clc; clear all; close all; alphap=2; alphas=20; wp=[0.2*pi,0.4*pi]; ws=[0.1*pi,0.5*pi]; [n,wn]=cheb2ord(wp/pi,ws/pi,alphap,alphas); [b,a]=cheby2(n,alphas,wn,'stop'); w=0:0.01:pi; [b,pb]=freqz(b,a,w); m=20*log(abs(b)); an=angle(b); subplot(2,1,1); plot(pb/pi,m); grid; title('Chebychev type-2 band reject filter'); xlabel('normalised frequency'); ylabel('gain in db'); subplot(2,1,2); plot(pb/pi,an); grid; xlabel('normalised frequency');

page11…

ylabel('phase in radians');

chebychev type2-lowpassfilter: clc; clear all; close all; alphap=1; alphas=20; wp=0.2*pi; ws=0.3*pi; [n,wn]=cheb2ord(wp/pi,ws/pi,alphap,alphas); [b,a]=cheby2(n,alphas,wn); w=0:0.01:pi; [b,pb]=freqz(b,a,w); m=20*log(abs(b)); an=angle(b); subplot(2,1,1); plot(pb/pi,m); grid; xlabel('normalised frequency'); ylabel('gain in db'); title('Chebychev type-2 low pass flter'); subplot(2,1,2); plot(pb/pi,an); grid; xlabel('normalised frequency'); ylabel('phase in radians');

page12…

Related Documents

Dsp
June 2020 21
Dsp
June 2020 14
Dsp
October 2019 36
Dsp
April 2020 22
Dsp
November 2019 28
Dsp
November 2019 31