Last active
August 29, 2015 14:17
-
-
Save bambuchaAdm/1a67d2548d62762b4584 to your computer and use it in GitHub Desktop.
CPS - 2015-03-24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| N = 10; | |
| x = rand(1,N); | |
| X = x * matrixW(N); | |
| M = N-1; | |
| y = x(1:M); | |
| Y = y * matrixW(M); | |
| P = 5; | |
| k = 0:N-1; | |
| subplot(P,2,1) | |
| plot(k, x, 'bo-'); | |
| title('X'); | |
| subplot(P,2,3); | |
| plot(k, real(X),'bo'); | |
| title('Re(X)'); | |
| grid on; | |
| subplot(P,2,5); | |
| plot(k, imag(X),'bo'); | |
| title('Im(X)'); | |
| grid on; | |
| subplot(P,2,7); | |
| plot(k, abs(X),'bo'); | |
| title('Abs(X)'); | |
| grid on; | |
| subplot(P,2,9); | |
| plot(k, angle(X),'bo'); | |
| title('Angle(X)'); | |
| grid on; | |
| k = 0:M-1; | |
| subplot(P,2,2) | |
| plot(k, y, 'bo-'); | |
| title('Y'); | |
| subplot(P,2,4); | |
| plot(k, real(Y),'bo'); | |
| title('Re(Y)'); | |
| grid on; | |
| subplot(P,2,6); | |
| plot(k, imag(Y),'bo'); | |
| title('Im(Y)'); | |
| grid on; | |
| subplot(P,2,8); | |
| plot(k, abs(Y),'bo'); | |
| title('Abs(y)'); | |
| grid on; | |
| subplot(P,2,10); | |
| plot(k, angle(Y),'bo'); | |
| title('Angle(Y)'); | |
| grid on; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % m-plik skryptowy: definicja_DFT.m | |
| % | |
| % Laboratorium: | |
| % Cyfrowe Przetwarzanie Sygnalow | |
| % Katedra Elektroniki, WIEiT, AGH | |
| % | |
| % Dane liczbowe sa wziete z przykladu z wykladu | |
| % | |
| % Opracowanie: P.Korohoda, 13/03/2015; | |
| % Modyfikacje: P.Korohoda, 23/03/2015; | |
| clc; clear; close all; | |
| Dt=1e-3; | |
| %x=[1;0;-1;0;1;0], % dla porownania z poprzednim przykladem; | |
| x=[2,1,0,1,2,1,0,1].', | |
| N=length(x); | |
| n=0:N-1; | |
| k=0:N-1; k=k(:); | |
| kn=k*n, | |
| w_N=exp(-j*2*pi/N), | |
| W=w_N.^kn, | |
| ReW=real(W), | |
| ImW=imag(W), | |
| PW=angle(W)/pi, | |
| AW=abs(W), | |
| X=W*x, | |
| IW=w_N.^(-kn), | |
| x1=(1/N)*IW*X, | |
| err=max(abs(x-x1)), | |
| figure(1); | |
| subplot(1,2,1); | |
| plot(real(W(:)),imag(W(:)),'bo'); grid on; axis equal; | |
| subplot(1,2,2); | |
| plot(real(IW(:)),imag(IW(:)),'bo'); grid on; axis equal; | |
| % KONIEC PLIKU; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % m-plik skryptowy: DFT_przyklad_sygnalu.m | |
| % | |
| % Laboratorium: | |
| % Cyfrowe Przetwarzanie Sygnalow | |
| % Katedra Elektroniki, WIEiT, AGH | |
| % | |
| % Dane "realistyczne" | |
| % | |
| % Opracowanie: P.Korohoda, 13/03/2015; | |
| % Modyfikacje: P.Korohoda, 23/03/2015; | |
| clc; clear; close all; | |
| N=2^10; | |
| n=0:N-1; k=0:N-1; k=k(:); | |
| kn=k*n; | |
| w_N=exp(-j*2*pi/N); | |
| W=w_N.^kn; | |
| fp=1200; | |
| Dt=1/fp; df=fp/N; t=0:Dt:(N-1)*Dt; | |
| f=k*df; | |
| k0=300; % wybieramy indeks wskazujacy na numer wartosci "f"; | |
| f1=k(end-k0)*df, % trafiamy w punkt na osi "f"; | |
| %f1=((k(end-k0)+k(end-k0+1))/2)*df, % dokladnie w srodku miedzy punktami; | |
| dP=-pi/4; % dla dP=0 otrzymujemy nieprzesuniety cosinus, dla dP=-pi/2 jest sinus; | |
| x=cos(2*pi*f1*t+dP); x=x(:); | |
| ta=0:Dt/100:t(end)/2; | |
| xa=cos(2*pi*f1*ta+dP); | |
| X=W*x; | |
| IW=inv(W); | |
| x1=real(IW*X); % nie dzielimy przez N, poniewaz wyznaczylismy macierz odwrotna do W; | |
| err=max(abs(x1-x)), | |
| k1=find(abs(X)>0.001); | |
| figure(1); | |
| subplot(1,2,1); | |
| plot(real(W(:)),imag(W(:)),'b.'); grid on; axis equal; | |
| subplot(1,2,2); | |
| plot(real(IW(:)),imag(IW(:)),'b.'); grid on; axis equal; | |
| figure(2); | |
| plot(ta,xa,'r-'); grid on; hold on; | |
| plot(t,x,'b.-'); | |
| figure(3); | |
| subplot(2,2,1); | |
| plot(f,real(X),'b.'); grid on; hold on; | |
| plot([fp/2,fp/2],[min(real(X)),max(real(X))],'k','linewidth',2); | |
| subplot(2,2,3); | |
| plot(f,imag(X),'b.'); grid on; hold on; | |
| plot([fp/2,fp/2],[min(imag(X)),max(imag(X))],'k','linewidth',2); | |
| subplot(2,2,2); | |
| plot(f,abs(X),'b.'); grid on; hold on; | |
| plot([fp/2,fp/2],[min(abs(X)),max(abs(X))],'k','linewidth',2); | |
| subplot(2,2,4); | |
| plot(f,angle(X)/pi,'b.'); grid on; hold on; | |
| plot([fp/2,fp/2],[min(angle(X)/pi),max(angle(X)/pi)],'k','linewidth',2); | |
| plot(f(k1),angle(X(k1))/pi,'ro'); | |
| % KONIEC PLIKU; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [ W ] = matrixW( N ) | |
| %MATRIXW Summary of this function goes here | |
| % Detailed explanation goes here | |
| n = 0:N-1; | |
| W = exp(2*pi*j / N) .^ (n' * n); | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment