Facebook
From papillon, 10 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 218
  1. 1. Projektovati niskopropusni filter (dobijes fs,Wp,Ws,Rp,Rs)
  2. clear all
  3. clc
  4.  
  5. fs=44000;
  6. Wp=[2*1000/fs];
  7. Ws=[2*1300/fs];
  8. Rp=1;
  9. Rs=40;
  10.  
  11. d=fdesign.lowpass('Fst,Fp,Ast,Ap',Ws,Wp,Rs,Rp);
  12. f=design(d,'cheby2');
  13. info(f)
  14. fvtool(f)
  15. [Y,FS]=wavread('matlab.wav');
  16. t=0:1/fs:1/fs*(length(Y)-1);
  17. plot(t,Y)
  18. xlabel('Vrijeme [s]')
  19. ylabel('Amplituda')
  20. hold on
  21. izlaz=filter(f,Y);
  22. plot(t,izlaz,'r-')
  23. legend('Ulazni signal','Filtrirani signal')
  24.  
  25.  
  26. 2. Proizvoljan zvucni signal - linearno pojacavanje i inverzija
  27. clc
  28. clear all
  29. close all
  30.  
  31. [zvuk,fs] = audioread('sound.mp3');
  32. ramp = 0:1/(length(zvuk)-1):1;
  33. linearno_pojacanje = zvuk.*ramp';
  34. inverzija = zvuk .* (1 - ramp');
  35. t = 0:1/fs:1/fs*(length(zvuk)-1);
  36. subplot(211)
  37. plot(t,zvuk)
  38. title('Ulazni zvucni signal');
  39. axis([0 2 -1 1])
  40. subplot(212)
  41. plot(t,linearno_pojacanje)
  42. hold on
  43. plot(t, inverzija, 'g', 'LineWidth', 2);
  44. plot(t, ramp, 'r', 'LineWidth', 2);
  45. title('Linearno pojacanje i inverzija signala');
  46. xlabel('Vrijeme (s)');
  47. ylabel('Amplituda');
  48. legend('Linearno pojacanje', 'Inverzija', 'Ramp', 'Location', 'best');
  49. axis([0 2 -1 1]);
  50.  
  51.  
  52. 3. Ima pod a) sabrati ciste tonove frekvencije i b) visokopropusni filter
  53. % 1. a)
  54. Fs=4000;
  55. T=1/Fs;
  56. L=1000;
  57. t=(0:L-1)*T;
  58.  
  59. y=0.7*sin(2*pi*300*t)+sin(2*pi*700*t);
  60. subplot(211)
  61. plot(t(1:200),y(1:200))
  62. title('Sinusni signal');
  63. xlabel('Vrijeme');
  64. ylabel('Amplituda');
  65.  
  66. NFFT=2^nextpow2(L);
  67. Y=fft(y,NFFT)/L;
  68. f=Fs/2*linspace(0,1,NFFT/2+1);
  69. subplot(212)
  70. plot(f,2*abs(Y(1:NFFT/2+1)),'r')
  71. xlabel('Frekvencija');
  72. ylabel('Funkcija y');
  73.  
  74. %% b)
  75. clear all
  76. clc
  77.  
  78. fs=44000;
  79. Wp=[2*3000/fs];
  80. Ws=[2*2900/fs];
  81. Rp=1;
  82. Rs=40;
  83.  
  84. d=fdesign.highpass('Fst,Fp,Ast,Ap',Ws,Wp,Rs,Rp);
  85. f=design(d,'cheby2');
  86. info(f)
  87. fvtool(f)
  88. [Y,FS]=wavread('matlab.wav');
  89. t=0:1/fs:1/fs*(length(Y)-1);
  90. plot(t,Y)
  91. xlabel('Vrijeme [s]')
  92. ylabel('Amplituda')
  93. hold on
  94. izlaz=filter(f,Y);
  95. plot(t,izlaz,'r-')
  96. legend('Ulazni signal','Filtrirani signal')
  97.  
  98.  
  99. 4. Generisati cisti ton frekvencije ...
  100. % Step 1: Generate a clean tone of 100 Hz for 1 second at 3000 Hz sampling rate
  101. fs1 = 3000; % Sampling frequency for the tone
  102. t1 = 0:1/fs1:1-1/fs1; % Time vector for 1 second
  103. tone = sin(2*pi*100*t1); % Generate the 100 Hz tone
  104.  
  105. % Step 2: Generate white noise for 2 seconds at 1000 Hz sampling rate
  106. fs2 = 1000; % Sampling frequency for the noise
  107. t2 = 0:1/fs2:2-1/fs2; % Time vector for 2 seconds
  108. noise = randn(size(t2)); % Generate white noise
  109.  
  110. % Step 3: Combine the clean tone and the white noise
  111. % Ensure both signals are of the same length by padding the shorter one with zeros
  112. if length(tone) < length(noise)
  113.      t zeros(1, length(noise) - length(tone))];
  114. elseif length(noise) < length(tone)
  115.     noise = [noise zeros(1, length(tone) - length(noise))];
  116. end
  117.  
  118. combined_signal = tone + noise;
  119.  
  120. % Step 4: Mix the combined signal with a sinusoidal signal
  121. t_combined = 0:1/fs1:(length(combined_signal)-1)/fs1; % Time vector for combined signal
  122. sinusoid = 0.5 * sin(2 * pi * t_combined); % Generate the sinusoidal signal
  123. mixed_signal = combined_signal + sinusoid;
  124.  
  125. % Step 5: Display all the sound signals
  126. subplot(4, 1, 1);
  127. plot(t1, tone);
  128. title('100 Hz Tone');
  129.  
  130. subplot(4, 1, 2);
  131. plot(t2, noise);
  132. title('White Noise');
  133.  
  134. subplot(4, 1, 3);
  135. plot(t_combined, combined_signal);
  136. title('Combined Signal');
  137.  
  138. subplot(4, 1, 4);
  139. plot(t_combined, mixed_signal);
  140. title('Mixed Signal');
  141.  
  142. % Play the sounds
  143. sound(tone, fs1);
  144. pause(1);
  145. sound(noise, fs2);
  146. pause(2);
  147. sound(combined_signal, fs1);
  148. pause(length(combined_signal)/fs1);
  149. sound(mixed_signal, fs1);
  150.  
  151.  
  152. 5. Spojiti zvučne signale upotrebom operatora konkatanacije toms.wav i tenor-sax.wav i prikazati ih upotrebom naredbe plot.
  153.  
  154. [zvuk 1,fs]=wavread( 'toms.wav' );
  155. [zvuk2,fs]=wavread( 'tenorsax.wav');
  156.  spojeni = [zvuk 1; zvuk2];
  157. t=0:1/fs:1/fs* (length(spojeni)-1);
  158. plot(t,spojeni)
  159. xlabel('Vrijeme[s]')
  160. ylabel('Amplituda')
  161.  
  162.  
  163. 6. % Izvršiti miksanje zvučnog signala toms.wav sa sinusnim signalom.x=0.5sin(2pi t).
  164. Prikazati ulazne i izlazni zvučni signal.
  165.  
  166. zvuk1= 'toms.way';
  167. [y, FS]= wavread(zvuk1);
  168. t=0:1/Fs:1/Fs* (length(y)-1);
  169. sinusnisignal = 0.5*sin(2*pi*t)';
  170. novisignal = y + sinusnisignal;
  171. subplot(3,1,1), plot(t,y, 'linewidth',2)
  172. title('Ulazni signal' );
  173. ylabel('Amplituda' )
  174. subplot(3,1,2), plot(t,sinusnisignal, 'r', 'linewidth',2)
  175. title('Sinusni signal' );
  176. ylabel('Amplituda')
  177. subplot(3,1,3), plot(t,novisignal, 'g', 'linewidth',2)
  178. title('Miksani signal' );
  179. xlabel('Vrijeme[s]')
  180. ylabel('Amplituda')
  181.