- 1. Projektovati niskopropusni filter (dobijes fs,Wp,Ws,Rp,Rs)
- clear all
- clc
- fs=44000;
- Wp=[2*1000/fs];
- Ws=[2*1300/fs];
- Rp=1;
- Rs=40;
- d=fdesign.lowpass('Fst,Fp,Ast,Ap',Ws,Wp,Rs,Rp);
- f=design(d,'cheby2');
- info(f)
- fvtool(f)
- [Y,FS]=wavread('matlab.wav');
- t=0:1/fs:1/fs*(length(Y)-1);
- plot(t,Y)
- xlabel('Vrijeme [s]')
- ylabel('Amplituda')
- hold on
- izlaz=filter(f,Y);
- plot(t,izlaz,'r-')
- legend('Ulazni signal','Filtrirani signal')
- 2. Proizvoljan zvucni signal - linearno pojacavanje i inverzija
- clc
- clear all
- close all
- [zvuk,fs] = audioread('sound.mp3');
- ramp = 0:1/(length(zvuk)-1):1;
- linearno_pojacanje = zvuk.*ramp';
- inverzija = zvuk .* (1 - ramp');
- t = 0:1/fs:1/fs*(length(zvuk)-1);
- subplot(211)
- plot(t,zvuk)
- title('Ulazni zvucni signal');
- axis([0 2 -1 1])
- subplot(212)
- plot(t,linearno_pojacanje)
- hold on
- plot(t, inverzija, 'g', 'LineWidth', 2);
- plot(t, ramp, 'r', 'LineWidth', 2);
- title('Linearno pojacanje i inverzija signala');
- xlabel('Vrijeme (s)');
- ylabel('Amplituda');
- legend('Linearno pojacanje', 'Inverzija', 'Ramp', 'Location', 'best');
- axis([0 2 -1 1]);
- 3. Ima pod a) sabrati ciste tonove frekvencije i b) visokopropusni filter
- % 1. a)
- Fs=4000;
- T=1/Fs;
- L=1000;
- t=(0:L-1)*T;
- y=0.7*sin(2*pi*300*t)+sin(2*pi*700*t);
- subplot(211)
- plot(t(1:200),y(1:200))
- title('Sinusni signal');
- xlabel('Vrijeme');
- ylabel('Amplituda');
- NFFT=2^nextpow2(L);
- Y=fft(y,NFFT)/L;
- f=Fs/2*linspace(0,1,NFFT/2+1);
- subplot(212)
- plot(f,2*abs(Y(1:NFFT/2+1)),'r')
- xlabel('Frekvencija');
- ylabel('Funkcija y');
- %% b)
- clear all
- clc
- fs=44000;
- Wp=[2*3000/fs];
- Ws=[2*2900/fs];
- Rp=1;
- Rs=40;
- d=fdesign.highpass('Fst,Fp,Ast,Ap',Ws,Wp,Rs,Rp);
- f=design(d,'cheby2');
- info(f)
- fvtool(f)
- [Y,FS]=wavread('matlab.wav');
- t=0:1/fs:1/fs*(length(Y)-1);
- plot(t,Y)
- xlabel('Vrijeme [s]')
- ylabel('Amplituda')
- hold on
- izlaz=filter(f,Y);
- plot(t,izlaz,'r-')
- legend('Ulazni signal','Filtrirani signal')
- 4. Generisati cisti ton frekvencije ...
- % Step 1: Generate a clean tone of 100 Hz for 1 second at 3000 Hz sampling rate
- fs1 = 3000; % Sampling frequency for the tone
- t1 = 0:1/fs1:1-1/fs1; % Time vector for 1 second
- tone = sin(2*pi*100*t1); % Generate the 100 Hz tone
- % Step 2: Generate white noise for 2 seconds at 1000 Hz sampling rate
- fs2 = 1000; % Sampling frequency for the noise
- t2 = 0:1/fs2:2-1/fs2; % Time vector for 2 seconds
- noise = randn(size(t2)); % Generate white noise
- % Step 3: Combine the clean tone and the white noise
- % Ensure both signals are of the same length by padding the shorter one with zeros
- if length(tone) < length(noise)
- t zeros(1, length(noise) - length(tone))];
- elseif length(noise) < length(tone)
- noise = [noise zeros(1, length(tone) - length(noise))];
- end
- combined_signal = tone + noise;
- % Step 4: Mix the combined signal with a sinusoidal signal
- t_combined = 0:1/fs1:(length(combined_signal)-1)/fs1; % Time vector for combined signal
- sinusoid = 0.5 * sin(2 * pi * t_combined); % Generate the sinusoidal signal
- mixed_signal = combined_signal + sinusoid;
- % Step 5: Display all the sound signals
- subplot(4, 1, 1);
- plot(t1, tone);
- title('100 Hz Tone');
- subplot(4, 1, 2);
- plot(t2, noise);
- title('White Noise');
- subplot(4, 1, 3);
- plot(t_combined, combined_signal);
- title('Combined Signal');
- subplot(4, 1, 4);
- plot(t_combined, mixed_signal);
- title('Mixed Signal');
- % Play the sounds
- sound(tone, fs1);
- pause(1);
- sound(noise, fs2);
- pause(2);
- sound(combined_signal, fs1);
- pause(length(combined_signal)/fs1);
- sound(mixed_signal, fs1);
- 5. Spojiti zvučne signale upotrebom operatora konkatanacije toms.wav i tenor-sax.wav i prikazati ih upotrebom naredbe plot.
- [zvuk 1,fs]=wavread( 'toms.wav' );
- [zvuk2,fs]=wavread( 'tenorsax.wav');
- spojeni = [zvuk 1; zvuk2];
- t=0:1/fs:1/fs* (length(spojeni)-1);
- plot(t,spojeni)
- xlabel('Vrijeme[s]')
- ylabel('Amplituda')
- 6. % Izvršiti miksanje zvučnog signala toms.wav sa sinusnim signalom.x=0.5sin(2pi t).
- Prikazati ulazne i izlazni zvučni signal.
- zvuk1= 'toms.way';
- [y, FS]= wavread(zvuk1);
- t=0:1/Fs:1/Fs* (length(y)-1);
- sinusnisignal = 0.5*sin(2*pi*t)';
- novisignal = y + sinusnisignal;
- subplot(3,1,1), plot(t,y, 'linewidth',2)
- title('Ulazni signal' );
- ylabel('Amplituda' )
- subplot(3,1,2), plot(t,sinusnisignal, 'r', 'linewidth',2)
- title('Sinusni signal' );
- ylabel('Amplituda')
- subplot(3,1,3), plot(t,novisignal, 'g', 'linewidth',2)
- title('Miksani signal' );
- xlabel('Vrijeme[s]')
- ylabel('Amplituda')