Baixe o app para aproveitar ainda mais
Prévia do material em texto
O primeiro trabalho que o docente mandou realizar a representação de un sinal senoidal continuo e discreto: 1° criei um ficheiro ‘sinal_sample.sce’ com o seguinte código // dados do sinal f = 1000; //frequencia entrada Hz fs = 2000; // frequencia de amostragem Hz // gerar sinal 'continuo' com 10 periodos. Para isso: // alta discretizacao (taxa de 100*f) // T=10, le, 10 periodos do sinal tempo = (0:1/(10*fs):10/f); sinal = sin(2*%pi*f*tempo); // geracao onda senoidal em uma //display(); // sinal continuo subplot(2,1,1) title('Sinal continuo senoidal','fontsize',5,'color','blue') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo,sinal,'b') //hold; // sinal discreto //stem //plot2d3(tempo,sinal) //stem subplot(2,1,2) title('Sinal Discreto senoidal','fontsize',5) xlabel('Tempo','fontsize',3) ylabel('Frequencia','fontsize',3) plot2d3(tempo,sinal) Obtive como resposta deste sinal : O segundo a trabalho foi criar : 1.declare um eixo temporal discreto t de dimensão N = 1024 para t1 = 0, …,tN = 2 segundos, utilizando a função linspace (faça um estudo rápido dela). Qual o intervalo de tempo entre cada amostra em segundos ? N = 1024; // amostras t1 = 0; // tempo inicial t2 = 2; // tempo final alpha = 2 ; f0 = 10; // Frequencia amp = 4.3 // amplitude tempo = linspace(t1,t2,N); 2.Construa agora uma função s(t) = sin(x) onde x = ω0 t . Se quisermos um seno de frequência f0 = 10 Hz, como fazer? Queremos aumentar a amplitude da função s(t) para um valor A = 4.3. st = amp * sin(2*%pi*f0*tempo); 3. vamos agora construir um nova função g(t) = exp(- α t), onde α = 2 . Determine o vector g . // g(t) = exp(- alpha* t) gt = exp(-alpha .* tempo ); 4. Determine agora a função h(t) = g(t)s(t)ht = gt .*st. //flipup //ht_inv = ht($:-1:1,:); //fliplr ht_inv = ht(:,$:-1:1); tempo_inv = linspace(-t2,-t1,N); // Expansao do sinal tempo_exp = tempo*2; // Compressao od sinal tempo_comp = tempo/2; 5. utilizando a função plot represente os vetores s(t) , g(t) e h(t) , primeiro em duas figuras separadas, depois no mesmo gráfico e a função subplot. Coloque legendas nos eixos do tempo e amplitude e títulos no vários gráfico: subplot(2,3,1) title('Sinal senoidal','fontsize',5,'color','blue') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo,st) subplot(2,3,2) title('Sinal exponencial','fontsize',5,'color','b') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo,gt,'color','r') subplot(2,3,3) title('Sinal senoidal x Sinal exponencial','fontsize',5,'color','b') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo,ht,'color','grey') subplot(2,3,4) title('Sinal invertido (espelhado)','fontsize',5,'color','b') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo_inv,ht_inv,'color','grey') subplot(2,3,5) title('Expansao','fontsize',5,'color','b') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo_exp,ht,'color','grey') subplot(2,3,6) title('Compressao','fontsize',5,'color','b') xlabel('Tempo','fontsize',3,'color','b') ylabel('Frequencia','fontsize',3,'color','b') plot(tempo_comp,ht,'color','grey') Resultado foi Agora para utilizaçao do convolução N=10; t1=0; t2=10; tempo2 = linspace(t1,t2,N); // u[n] un1 = ones(0:9); //u[n-3] un2 = [zeros(0:2),ones(0:6)]; //plot2d3(tempo,un) xn = un1 - un2; h1 = 0.8.^(0:9); y1 = conv(h1,xn); bar(y1,0.2); Pente de dirac Cria a se a função // n0 localizacao // n1 tempo inicial // n2 tempo final function [x, n]=dirac_unit(n1, n2, n0) amo = n2 - n1 +1; n = linspace(n1,n2,amo); x = n - n0 >=0; x = bool2s(x); endfunction depois cria um ficheiro para utilizar esta função criada exec('dirac_unit.sci') n0= 0; n = 10; amo= n - n0 +1; tempo = linspace(n0,n,amo); y = dirac_unit(0,10,2) ; title('Pente de dirac ','fontsize',5) ylabel('Frequencia','fontsize',3) xlabel('Tempo','fontsize',3) plot2d3(tempo,y); e encontra teste resultado Exemplo de FFT clc; clf; N=100 ; t1 = -20 ;// tempo incial tn = 20; tempo = linspace(t1,tn,N); complexo = -0.1 + 0.3*%i; xn = exp(complexo*tempo); y = fft(xn); A = real(y); B = imag(y); mag = abs(y); x1 = atan(imag(y),real(y)); phase = x1*(180/%pi); disp('The FFT sequence is '); disp(y); disp('the magnitude response is'); disp(mag); disp('the phase response is'); disp(phase); z=ifft(y); disp('the result IFFT sequence is'); disp(z); subplot(3,2,1); plot2d3(xn); title('input sequence'); subplot(3,2,2); plot2d3(A); title('FFT real sequence'); subplot(3,2,3); plot2d3(B); title('FFT imaginary sequence'); subplot(3,2,4); title('magnitede response'); plot2d3(mag); subplot(3,2,5); title('phase response'); plot2d3(phase); subplot(3,2,6); title('IFFT sequence'); plot2d3(z); Exemplo DFT clc; clf; N=100 ; t1 = -20 ;// tempo incial tn = 20; tempo = linspace(t1,tn,N); complexo = -0.1 + 0.3*%i; xn = exp(complexo*tempo); for k=1:N y(k)=0 for n=1:N y(k)=y(k)+xn(n).*exp(-%i*2*%pi*(k-1)*(n-1)/N); A= real(y); B=imag(y); end; end; mag=abs(y); x1=atan(imag(y),real(y)); phase = x1*(180/%pi); for k=1:N y(n)=0 for n=1:N y(n)=y(n)+(1/N)*(y(k).*exp(%i*2*%pi*(k-1)*(n-1)/N)); C=real(xn) end; end; subplot(4,2,1); plot2d3(xn); title('input sequence'); subplot(4,2,2); plot2d3(y); title('resultant DFT sequence'); subplot(4,2,3); plot2d3(A); title('real value'); subplot(4,2,4); plot2d3(B); title('imaginary value'); subplot(4,2,5); plot2d3(mag); title('magnite responce'); subplot(4,2,6); plot2d3(phase); title('phase responce'); subplot(4,2,7); plot2d3(C); title('resultant IDFT sequence'); Circuito representação da fase e amplitude
Compartilhar