Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- M. Wasilewska kolokwium z PPSów Laby
- %}
- clear;
- close all;
- %=========================================================================
- % Zadanie 1
- % Rysowanie dwóch sinusów, zsumowanie ich i dodanie szumu
- % O parametrach
- % Sygnał 1:
- % f = 120 Hz
- % A1 - dow
- fs = 600;
- t=0:1/fs:10;
- % sygnał 1
- A1 = 0.7;
- f_1 = 120;
- sig_1 = A1*sin(2*pi*f_1*t);
- %sygnał 2
- A2 = 1.5;
- f_2 = 270;
- sig_2 = A2*sin(2*pi*f_2*t);
- % suma sinusów
- suma_sig = sig_1 + sig_2;
- % szum:
- % rand - szum równoramienny (od -1 do 1)
- % randn - szum gausowski - normalny (od -nies do niesk)
- rng('default');
- szum_nor = randn(1,length(suma_sig));
- %suma sinusów z szumem:
- sygnal = suma_sig + szum_nor;
- subplot 231
- plot(t,sygnal);
- title('suma sinusów z szumem');
- %=========================================================================
- % Zad 2
- % Widmo sumy sinusów z szumem
- length(sygnal)
- % dł sygnału wynosi 6001 więc bierzemy 2^13 = 8192
- transformata = fft(sygnal, 8192);
- % częstotliwość próbkowania sygnału
- f_transfo = 0:fs/length(transformata):fs-fs/length(transformata);
- subplot 232
- stem(f_transfo, abs(transformata));
- title('widmo sygnału');
- %=========================================================================
- % Zad 3
- % DO SPRAWDZENIA autokorelacja sumy sinusów z szumem, tmax = 0.4 s
- subplot 233
- tmax= 0.4;
- korelacja_sygnalu = xcorr(sygnal,sygnal,tmax*fs);
- t_korelacji = -tmax:1/fs:tmax;
- plot(t_korelacji,korelacja_sygnalu);
- xlabel('przesuniece [s]');
- ylabel('wautokorelacja');
- title('autokorelacja sygnału');
- %=========================================================================
- % Zad 4
- % Generowanie szumu normalnego o długościu sumy sinusów z szumem
- subplot 234
- rng('default');
- szum_nor = randn(1,length(suma_sig));
- plot(t,szum_nor);
- title('szum normalny o dł sumy sinusów');
- %=========================================================================
- % Zad 5
- % Korelacja dwóch sinusów? kmax = 300 próbek
- subplot 235
- kmax = 300;
- sample = -300:1:300;
- korelacja = xcorr(sig_1, sig_2, kmax);
- plot(sample, korelacja);
- title('korelacja sinusów');
- %=========================================================================
- % Zad EXTRA
- % Histogram sinusów z szumem
- subplot 236
- piki = 10;
- hist (sygnal,piki);
- xlabel('wartości próbek');
- ylabel('ilość próbek');
- title('histogram sinusów z szumem');
- %=========================================================================
- % Zad 1 GR B
- % Wczytaj sygnał i zdecymuj go co 4 raz
- figure
- [audio, f_audio] = audioread('mbi04czep.wav');
- %sygnał normalny
- subplot 211
- delta = 1/f_audio;
- t_audio = 0:delta:abs(delta*length(audio)-delta);
- plot(t_audio, audio);
- title('sygnał');
- %sygnał zdecymowany 4-krotnie
- subplot 212
- audio_dec = decimate(audio, 4);
- f_audio_dec = f_audio/4;
- delta_dec = 1/f_audio_dec;
- t_audio_dec = 0:delta_dec:abs(length(audio_dec)*delta_dec-delta_dec);
- plot(t_audio_dec,audio_dec);
- --------------------------------------------
- N = 8000;
- fp = 4000;
- t_max = (N-1)/fp;
- t = 0:1/fp:t_max;
- x1 = chirp(t, 50, t_max,800) + randn(1,N)
- ---------------------------------------------
- k_max = 450;
- xx2 = xcorr(x2, x2, k_max);
- kxx = -k_max : 1 : k_max;
- figure(4)
- plot(kxx, xx2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement