%% Øving 6, Digital signalbehandling, Henning Schei % %% Oppgave 1 % a) Nx= 28; f = linspace(0,1,10000); X = (1 - (power(0.9*exp(1j*2*pi*f), Nx)))./(1- (0.9*exp(1j*2*pi*f))); plot (f, abs(X)); title 'Magnutide response' xlabel 'Frequency' % b) n = 0:Nx-1; x = power(0.9,n); N = [Nx/4, Nx/2, Nx, 2*Nx ]; X1 = fft(x,N(1)); X2 = fft(x,N(2)); X3 = fft(x,N(3)); X4 = fft(x, N(4)); % d) figure subplot(2,2,1) hold on plot(f,abs(X)); freq= linspace(0,1, length(X1)); stem(freq,abs(X1)); title 'Magnitude DTFT and DFT with length = 7' subplot(2,2,2) hold on plot(f,abs(X)); freq= linspace(0,1, length(X2)); stem(freq,abs(X2)); title 'Magnitude DTFT and DFT with length = 14' subplot(2,2,3) plot(f,abs(X)); hold on freq= linspace(0,1, length(X3)); stem(freq,abs(X3)); title 'Magnitude DTFT and DFT with length = 28' subplot(2,2,4) plot(f,abs(X)); hold on freq= linspace(0,1, length(X4)); stem(freq,abs(X4)); title 'Magnitude DTFT and DFT with length = 56' %% Oppgave 2 % a) clear all Nh = 9; Nx = 28; n = 0:Nx-1; h = ones(1,Nh); x = power(0.9,n); y = conv(x,h); Ny = 0:(length(x) + length(h) -2); figure stem(Ny,y) title 'Time domain convolution of x[n] and h[n]' xlabel 'n' ylabel 'y[n]' % b) % Computing y[n] via the frecuency domain N = (1/2)*(Nx + Nh -1); X = fft(x, N); H = fft(h, N); Y = X .* H; n = 0:N-1; y = ifft(Y, N); figure stem(n,y) Ny = Nx + Nh -1; % Plotting with different values of $N_y$; N_set = [Ny/4, Ny/2, Ny, 2*Ny]; for i=1:length(N_set) DFT_IFT(x,h, N_set(i)); end % DFT-lengths must at lest be equal to the length of Ny to avoid time % domain alaiasing, as the plots show. clear all %% Oppgave 3 % b) f1 = 7/40; f2 = 9/40; n = 0:100-1; x = sin(2*pi*f1*n) + sin(2*pi*f2*n); N = 1024; X = fft(x,N); f = linspace(0,0.5, length(X)); plot(f,abs(X)); % Repeating with different segment lengths of n n_ = [1000, 30, 10]; figure for i=1:3 n = 0:n_(i) -1; x = sin(2*pi*f1*n) + sin(2*pi*f2*n); N = 1024; X = fft(x,N); f = linspace(0,0.5, length(X)); subplot(2,2,i) plot(f,abs(X)); xlabel 'f' title (['DFT of x[n] with length n = ' num2str(n_(i))]) end % c) Repeating b) with segment length N = 100 and different DFT lengths DFT_length=[256, 128]; n= 0:100-1; N = DFT_length(1); x = sin(2*pi*f1*n) + sin(2*pi*f2*n); X = fft(x,N); f = linspace(0,0.5, length(X)); figure subplot(2,1,1) plot(f,abs(X)); xlabel 'f' title 'DFT- length = 256' N = DFT_length(2); x = sin(2*pi*f1*n) + sin(2*pi*f2*n); X = fft(x,N); f = linspace(0,0.5, length(X)); subplot(2,1,2) plot(f,abs(X)) xlabel 'f' title 'DFT- length = 128'
Comments