core llvm compile dsp2
이전 댓글 표시
AIM: Computing the DFT coefficient X(k) using Goertzel Algorithm.
MATLAB Code: clc; close all; N=205; % DFT length n=0:N-1; x=sin(2*pi*n*697/8000)+sin(2*pi*n*1209/8000); if length(x)<N xz=[x zeros(1,N-length(x))]; else xz=x; end x1=[xz 0]; k=[18 20 22 24 31 34 38]; for i=1:7 W(i)=exp(-j*2*pi*k(i)/N); den(i,: ) = [1 -2*cos(2*pi*k(i)/N)]; vk(i,:)=filter(1, den(i,:), x1); Xk(i)=vk(i,N+1)-W(i)*vk(i,N); end stem(k,abs(Xk), 'filled'); xlabel('k'); ylabel('|X(k)|'); title('DFT at K=18,20,22,24,31,38');
AIM: Designing an FIR filter of given specifications and providing its impulse and frequency response
MATLAB Code: clc; close all; Fp=2000; %Fp=2KHz Fs=5000; %Fs=5KHz Ft=20000; %Ft=20KHz wp=(2*pi*Fp)/Ft; ws=(2*pi*Fs)/Ft; trwidth=ws-wp; %Transition Width M=ceil(6.2*pi/trwidth)+2; %Filter Length tau=(M-1)/2; wc=(wp+ws)/2; n=0:M-1; hd=(sin(wc*(n-tau)))./(pi*(n-tau)); hd(tau+1)=0.35; whan=hann(M)'; h=hd.*whan; w=0:0.02:pi; Hw=freqz(h,1,w); MagHw=abs(Hw); %Magnitude Response HwdB=20*log10(MagHw/max(MagHw)); %In Decibels subplot(2,2,1); stem(n,hd,'filled'); axis([-1 M -0.15 0.5]); xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n,whan,'filled'); axis([-1 M -0.1 1.2]); xlabel('n'); ylabel('w(n)'); title('Hann Window'); subplot(2,2,3); stem(n,h,'filled'); axis([-1 M -0.15 0.5]); xlabel('n'); ylabel('w(n)'); title('Practical Impulse Response'); subplot(2,2,4); plot(w/pi,HwdB); axis([0 1 -100 10]); xlabel('Frequency (in pi units)'); ylabel('dB'); title('Magnitude Response');
AIM: Designing a length-21 digital differentiator using a given hamming window.
MATLAB Code: clc; close all; M=21; %Hamming Window Length=21 tau=(M-1)/2; n=0:M-1; hd=((cos(pi*(n-tau)))./(n-tau))-((sin(pi*(n-tau)))./(pi*(n-tau).^2)); hd(tau+1)=0; whamm=hamming(M)'; h=hd.*whamm; w=0:0.01:pi; Hw=freqz(h,1,w); Hrw=exp(-j*(pi/2-10*w)).*Hw; subplot(2,2,1); stem(n,hd,'filled'); axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n,whamm,'filled'); axis([-1 M -0.2 1.2]); xlabel('n'); ylabel('w(n)'); title('Hamming Window'); subplot(2,2,3); stem(n,h,'filled'); axis([-1 M -1.2 1.2]); xlabel('n'); ylabel('h(n)'); title('Practical Impulse Response'); subplot(2,2,4); plot(w,Hrw); axis([0 pi 0 pi]); xlabel('Frequency'); ylabel('Amplitude'); title('Amplitude Response');
AIM: Designing a length-25 hilbert transformer using a given hamming window.
MATLAB Code: clc; close all; M=25; %Hamming Window Length=25 tau=(M-1)/2; n=0:M-1; hd=(2./(pi*(n-tau))).*(sin(pi*(n-tau)/2).^2); hd(tau+1)=0; whamm=hamming(M)'; h=hd.*whamm; w=-pi:0.01:pi; Hw=freqz(h,1,w); Hrw=exp(-j*(pi/2-12*w)).*Hw; subplot(2,2,1); stem(n,hd,'filled'); axis([-1 M -0.8 1]); xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n,whamm,'filled'); axis([-1 M -0.2 1.2]); xlabel('n'); ylabel('w(n)'); title('Hamming Window'); subplot(2,2,3); stem(n,h,'filled'); axis([-1 M -0.8 1]); xlabel('n'); ylabel('h(n)'); title('Practical Impulse Response'); subplot(2,2,4); plot(w/pi,Hrw); axis([-1 1 -1.2 1.2]); xlabel('Frequency in pi Units'); ylabel('Amplitude'); title('Amplitude Response');
AIM: Designing a Butterworth Filter with given specifications.
MATLAB Code: clc; close all; T=1; wp=0.3*pi; ws=0.8*pi; Ap=1; As=40; Wp= (2 /T) *tan (wp/ 2) ; %analog pass band edge freq Ws= (2/T) *tan (ws / 2 ) ; %analog stop band edge freq R=(10^(0.1*Ap) -1) / (10^(0.1*As)-1) ; N=ceil ( (1/2)* (log10 (R) / (log10 (Wp/Ws)))) Wc=Wp/((10^(0.1*Ap) -1)^(1/ (2*N))); [b,a] = butter (N, Wc , 'low' , 's' ) ; Hs=tf (b,a) [numd, dend]= bilinear(b, a, 1/T) ; Hz=tf (numd , dend, T) w=0:0.01:pi; Hw=freqz (numd, dend, w) ; subplot (121) ; plot (w, abs (Hw)) ; xlabel ('frequency') ; ylabel ('magnitude'); subplot (122) ; plot (w, 20*log10 (abs (Hw))) ; xlabel('frequency'); ylabel('Magnitude (dB)');
댓글 수: 3
Pochita
2023년 11월 20일
Pochita
2023년 11월 20일
Steven Lord
2023년 11월 20일
There doesn't seem to be any question in here. If you're looking to share code that others may find useful, take a look at the MATLAB Central File Exchange (under the MATLAB Central drop-down near the top of this page.)
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!