T-61.3010 DSP Course assigment Spring 2007 ERROR CODES 0 ** Pikatarkistus ============================================================ 000 -- Harjoitustyösi/nne on palautettu toukokuun viimeisinä päivinä ennen deadlinea. Tässä vaiheessa kesää 19.6.2007 tulokset on saatava OODIin, joten olen vain ylimalkaisesti vilkaissut työn läpi ja hyväksynyt sen. Koodista 001/002/003 näet vielä "työn tasosi". Olen töissä heinäkuun loppuun asti ja jos sinulla on pienintäkään kiinnostusta saada oikeaa palautetta työstä, niin ota yhteyttä t613010@cis.hut.fi. Kaikki alla olevat virhekoodit ja kommentit ovat annettu harjoitustöille, jotka palautettiin huhtikuussa ja toukokuun alkupuolella ja joita ehdin tarkistaa hieman laajemmin. Ne on lueteltu tehtäväosioittain. Niistä voi olla hyötyä myös omassa reflektiossa. Yleisimmät koodit lukumäärineen: lkm KOODI // M=86 ------------------- 23 400 // Q4ssä biisin Piste esitti kaksi eri naista 22 100 // Q1ssä Matlabin ikävä piirre skaalata väriasteikko 17 600 // Ota sivunumerointi käyttöön dokkarissa 12 270 // LaTeXin käytöstä 11 339 // Q3.4ssä viiveen etsintä 10 214 // Q2ssa ei ollutkaan jaksollinen Fourier-sarja 9 210 // Q2 Tarkka taajuus parhaiten jakson käänteisluvusta 8 230 // Q2 Suhde suuri - ei kovin tarkkaa syntetisointi 8 110 // Q1 Heikko äänitys 7 613 // LaTeXin käytöstä 7 342 // Q3.4 speksit ja vasteet desibeleihin 5 4 eri koodia 4 6 eri koodia 3 4 eri koodia 2 35 eri koodia 1 26 eri koodia Tähän mennessä yksin palautettuja töitä on 54 ja parityönä palautettuja 45, joista tulee 144 opiskelijaa. Bumerangeja töistä on tullut 7 yksilötyölle ja 11 parityölle. Pinossa näyttää olevan nyt 70 työtä, jonka tarkistamiseen "hyvin" kuluisi noin kaksi työpäivää (netto). 001 -- Nopea vilkaisu: hyvin tehty, ei liene liiemmin kommentoivaa. 002 -- Nopea vilkaisu: ok, joitain kommentteja olisi tulossa. 003 -- Nopea vilkaisu: läpi, mutta jos teet jatkossa jotain Matlabilla tai DSP-juttuja, niin kannattaa katsoa virheet läpi ja korjata ne. 1 ** Q1 puhesignaali / speech signal ============================================================ 100 -- The colors of the spectrogram have been "saturated". Not a bug, not an error but a typical feature/problem in Matlab. We would like to use the whole color scale but the spectrogram is, e.g., "totally red" (if using default "jet" colormap). Why? The spectogram is plotted from short-time spectra. Now if there is a short part of speech signal which is zero (or very quiet) in a time window, then the energy of spectral components are zero (or very small). Here we get the minimum value Emin. When there exists also spectral components which are large, the largest one is Emax. Most of the time windows are relatively close to values of Emax. Solution: specgram(...); colorbar; caxis([bot top]); % normally about caxis([-50 30]) colorbar You can also change the colormap by colormap(gray); 110 -- Recording with quiet level, the signal varies typically between -0.1 .. +0.1, even the capable range would be -1 .. +1. If recorded with 8 bits per sample, the quantization levels are prominent. May cause troubles, if amplified etc. In Windows there is probably "MIC Boost" behind the "Advanced" button in the audio (recording) panel. Or then just speak louder. 111 -- Recording with too high level, some parts of the signals are cut (less than -1 or more than +1), when the capable range is -1 .. +1. Do not speak so loud, decrease mic volume or do not speak so close. 112 -- Recording with too quiet level, the signal varies typically between -0.01 .. +0.01, even the capable range would be -1 .. +1. If recorded with 8 bits per sample, the quantization levels are very prominent. This will cause troubles in the following problems. In Windows there is probably "MIC Boost" behind the "Advanced" button in the audio (recording) panel. Or then just speak louder. 113 -- Hmm.. What could be the reason for steady 3 kHz, or 8 kHz, or 16 kHz noise component shown in the spectrogram?!? Is it from computer (tuuletin?)? 114 -- Kuva 1: "äänispektri" -> "aaltomuoto", spectrum refers to the transform (Fourier) domain. Kuva 3: "perustaajuus" (Hz) -> "perusjakso" (s) 115 -- Q1. "Epäilyttävän" matala perustaajuus alle 50 Hz?! Onhan oikeasti pala vokaaliäännettä sanan keskeltä eikä mitään muuta hyrinää?! 116 -- Q1, aikatason kuvaajaan 40 ms pätkä. Saattaa helpottaa perusjakson etsimistä, eikä mene vahingossa valitsemaan "vääriä" perusjaksoja. 120 -- Amplitude spectrum of the signal is |X(e^jw)|, that is, abs(fft(x)). Because taking absolute value, or values should be non-negative. You have drawn either real(fft(x)) or fft(x), in latter case Matlab automatically ignores complex part (?). 130 -- The spectral resolution is not large and therefore it is not wise to estimate the fundamental frequency only by looking the first peak in the spectrum. Consider a case of 40 ms signal with fs=22050 Hz. Then we have 882 samples. When computing DFT, it has also 882 spectral components with equal intervals in the frequency domain, i.e., delta = 2pi/882 ~=~ fs/882 ~ 25 Hz. So, X = fft(x), X[0] refers 0 Hz, X[1] 25 Hz, X[2] 50 Hz, ... If your real fundamental frequency (T_0 = 1/f_0 from waveform x(t) ) is 135 Hz, then it shown as two "high" peaks at 125 Hz (X[5]) and 150 Hz (X[6]). See [B31] in Example problem materia in Spring 2007. One solution: Compute f_0 from first peak, from fourth peak divided by for, form 10th peak divided by 10, etc., see http://www.cis.hut.fi/Opinnot/T-61.3010/Demo/esim2.shtml 131 -- Q1.4 Fundamental frequency f_0 = 1/T_0: All frequencies of the signal can be expressed as multiplies of f_0. See http://www.cis.hut.fi/Opinnot/T-61.3010/Demo/esim2.shtml 132 -- Q1.3 Fundamental period T_0: the signal repeats itself every T_0, i.e., x(t) == x(t+T_0). Now in case of quasi-periodic speech signal, x(t) ~~ x(t+T_0). See also 131 and http://www.cis.hut.fi/Opinnot/T-61.3010/Demo/esim2.shtml 133 -- fft(x2, 50000) komento täydentää x2-vektorin nollilla 50000 merkkiä pitkäksi, jolloin taajuusresoluutio "kasvaa" ja deltaksi tulee fs/50000. Oikeasti fft-komento pidentää x2:n vielä lähimpään 2^N:ään, tässä tapauksessa 2^10:een eli 64 kiloon. 140 -- Mukana myös 50 Hz:n verkkovirtahäiriö, joka tulee "huonolaatuisesta" äänityksestä. 141 -- You have extracted "a vowel" from that silent part of the signal, your "vowel" is just quantization noise (silence) without any signal. Therefore you will get bad results. Choose a vowel from that part of signal where the signal is actually present. 160 -- "both channels were almost identical" <==> you probably used a mono microphone 161 -- Kuva 3, 1/140 s jakso on selvä, vaikka itse 140 Hz:n kosinia ei välttämättä näykkään signaalissa 162 -- Jos verkkovirtahäiriön (50 Hz) kosinia ei olisi, niin kuvan 2 neljä isompaa huippua menisivät yhtä korkealle, jolloin huomaisi, että puheäänen oikea perusjakso on isojen huippujen välinen matka eli noin 0.01 sekuntia (100 Hz). Sekä Q1 ja Q2 sinänsä ihan ok tehty, jos/kun ajattelee, että verkkohäiriö on osa tutkittavaa signaalia. 2 ** Q2 Fourier-sarja ============================================================ 210 -- You could have used a bit different (more exact) fundamental frequency. Now the synthesized signal has smaller/larger frequency than the original one, that is, the periods of original and synthesized signals are not the same. A more exact fundamental frequency would improve (decrease) the error ratio. Nähdään siis siitä kuvaajasta, jossa sekä alkuperäinen että syntetisoitu: huiput eivät pysy toistensa suhteen samoissa kohdissa. 211 -- Fundamental frequency f_0 is shown in error e[n], because you have not used exactly correct f_0. 212 -- Fourier-series is applied for a very low-quality signal, see 112 or 111. 213 -- You can avoid for-loops in Matlab, for instance, energy=sum([2 5 -3 1].^2), gives 2^2 + 5^2 + (-3)^2 + 1^2 214 -- Q2: Your \hat{x} is NOT a Fourier series because you have not used f_0 and its harmonics 1f_0, 2f_0, 3f_0, 4f_0, ... This implies that your synthesized signal is not periodic! Your fundamental frequency may not be correctly estimated, see "One solution" in 130 above. Then you should write, for instance, using 1st (fundamenta), 2nd, 4th, 7th, and 9th harmonic: for k = [1 2 4 7 9] xi = A(k) * cos(2*pi*k*f_0*t + theta(k)); ... end or define your frequencies f = [1 2 4 7 9] * f_0; You probably can receive "better" (or "worse") results by not having a Fourier series. See 215 below. 215 -- Q2: Your \hat{x} is a Fourier series but the fundamental frequency of that is not the same as the fundamental frequency of the signal. You may receive "better" (or "worse") results in this way compare to the "real" Fourier series, see 214 above. 220 -- Scaling, by L.K. x[n] = 1/N SUM_k X[k] e^(j 2pi kn/N) = ... = (X[0]+X[N/2])/N + 2/N SUM_(k=1)^(N/2-1) ... |X[k]| cos(2pi kn/N + th_k) So, theoretically you multiply by 2/N to get signal from Fourier-components. Here it is enough to scale with your own magic constant because when using only a few sinusoidals you must anyway compensate the missing energy. 221 -- You can avoid for-loops in several ways in Matlab, see 213, 405. However, in new versions for-loops are implemented quite efficiently and it is sometimes easier to read the code with for-loops. However, whenever executing a long for-loop you should initialize your variables (with zeros) to that length of the size of for-loop. Consider the following code: for m = [1 : 100000] ky(m) = 3*m; end Matlab starts m = 1, and ky(1) = 3. In the following round m = 2, it first reserves two memory blocks for ky, copies ky(1) and writes ky(2) = 6. Next m = 3, it reserves three memory blocks for ky, copies ky(1:2) and writes ky(3) = 9. And so on. In each round there are heavy memory operations, and Matlab get stuck. However, if you initialize ky = zeros(100000,1); then each for-loop just assigns ky(m) = 3*m; and it is quick operation. The elegant way of doing this would be directly ky = 3 * [1 : 100000]; 222 -- Q2: How to choose which spectral components to take? Start from those with largest energy, i.e., highest peak. Not necessary five first harmonics. 223 -- Q2: Fourier-hässäkästä puuttui A_i-kertoimet, joilla saadaan yksittäisille sinusoideille suhteelliset korkeudet. 224 -- Q2: Fourier-hässäkästä ylimääräistä, mistä syystä syntetisointi ei onnistunut "alkuunkaan". 230 -- Q2: Ratio (SUM e^2 / SUM x^2) is large (bad thing). Probably the phases of the sinusoidals are not correctly chosen. 231 -- Q2: Ratio (SUM e^2 / SUM x^2) is large (bad thing). Koko signaali on vähän eri vaiheessa, huiput ei satu kohdalleen. Erilaisia kikkoja siirtää kaikkia Fourier-komponentteja ajassa saman verran: Jos A_k cos(2pi k f_0 n / f_s + theta_k) ja vektori n: n = [0 : M-1], niin aloitetaankin n-vektori eri kohdasta kuin nollasta. Jos vaikkapa 0.001 sekuntia myöhässä, ja f_s = 1000 Hz, niin 10 merkkiä myöhässä, niin n = [10 : M+9]. Kutakin vaihekulmaa voi myös lisätä lineaarivaiheisella suotimella h[n] = delta[n-10], analysis of whether the specifications are met, is also to be done in decibels. There was an "incorrect" example line in Q3.4: plot(w, abs(H1), '-', w, abs(H2), '-.'); This was not meant to be copied directly. Instead, it should be plot(w, 20*log10(abs(H1)), '-', w, 20*log10(abs(H2)), '-.'); followed by specifications speksit(Wp, Ws, Rp, Rs, fT); 343 -- Q3.4 Comparison between IIR, FIR *and* specifications missing. Show that filters met (or not) specifications, for instance, by drawing IIR and FIR magnitude response (in decibels because specs given in dB), and adding speksit.m. See 342 above. 344 -- Butterworth has monotonic magnitude response. (Chebychev I has monotonic stopband magnitude response.) If Rs = 5 dB chosen (min stopband attenuation), then -5 dB is at Ws, but in the stopband the attenuation is stronger and stronger when omega growing. In omega=pi attenuation is 0, that is, -oo dB. Eli vaikka olet valinnut estokaistan minimivaimennukseksi Rs=5 tai Rs=20 dB, niin todellisuudessa se vaimennus on Butterworthin (tai Cheb I) tapauksessa paljon enemmän. Ongelma on siinä, että jos nyt samoilla spekseillä vaihdatkin vaikkapa elliptiseen suotimeen, joka "nuolee" tuota Rs-tasoa, niin vaimennus ei ehkä olekaan tarpeeksi hyvä. Useat vastaajat dokumentoivat, että 20 dB ei ollut subjektiivisesti vielä riittävä vaimennus vaan vasta 40 dB. 345 -- Command fir1: fir1(order, cut-off, windowtype). Window is by default hamming. If using another, help fir1, help blackman | hann | bartlet | rectwin. For example, [B] = fir1(10, 0.3, blackman(11)); 346 -- read "help speksit", speksit(Wp, Ws, Rp, Rs, 'high', fT); 347 -- IIR/FIR specifications are NOT met in the implementation. Probably too heavy requirements for the stopband? Note also that fixed FIR windows (Hamming, Blackman, ...) have a fixed value for stopband attenuation. 348 -- Q3.1 "taajuuksia 1 .. 5000 hertsiin". Huomaa, että 0 Hz on "tasavirtakomponentti" eli signaalin keskiarvo. Yleensä kannattaa keskiarvoistaa pois, käsittääkseni näissä signaaleissa ei välttämättä ole poistettu. Ei vaikuta kuultavaan tulokseen mitenkään, koska vain värähtelyenergiaa havaitaan. 370 -- sivu 8, viimeinen rivi "joten suodatin on lineaarinen". LTI-suotimen _ovat_ lineaarisia määritelmänsä mukaan. Ehkä tarkoitat "lineaarivaiheinen"? 371 -- sivu 8, Kuva 8: ei saa sanoa signaalin aaltomuotoa spektriksi. Spektri on taajuustason esitys (Fourier- muunnettu). Aaltomuodossa x(t), x[n], sekunteja. Spektrissä X(z), X(e^jw), Hertzejä, normalisoituja kulmataajuuksia yms. 372 -- Q3. Dokkariin jäänyt spekseistä estokaistan 40 dB vaikka kaikissa kuvissa 50 dB. 373 -- Kuva 15, vähän sekava, tekstissä 20 ms, mutta kuvan akseli 6 ms...? 374 -- Q3:n koodi ja dokumentointi puuttuu lähes täysin. Mielenkiintoinen tapa verrata suotimia kiinnittämällä asteluku ensin kiinni. Tässä haluttiin kuitenkin tehdä suodin amplitudispeksien kautta ja antaa asteluvun vaihdella. filtfilt on tosiaan nollavaiheinen suodin ja siksi viivettä ei tule. 375 -- Kuvateksti Kuva 10. 376 -- Käytätte ikkunana Hammingia (oletusikkuna), vaikka kuvittelette käyttävänne jotakin muuta. 377 -- Kuva 12 ilmeisesti kohdasta Matlab 4 / tehtävä 3. Huomaa, että "plot(x)" piirtää käyrän x siten, että x-akselille tulee x:n indeksinumerot alkaen ykkösestä ja loppuen length(x)-arvoon. x-akselille EI TULE AIKAA SEKUNNEISSA. Sekunteja varten pitää määritellä vektori t ja piirtää plot(t, x), mistä esimerkkejä mm. Matlab 1 -harjoituksissa. Vastaavasti "plot(xF)", jossa xF = 20*log10(...(fft(x))) piirtää signaalin amplitudivasteen 0 .. 2pi-epsilon, ja x-akselille tulee xF:n indeksit 1 .. length(xF). x-akselille EI TULE TAAJUUTTA HERTZEISSÄ. Hertzejä varten (Matlab 1 / tehtävä 3) f = fT * [0 : M-1]/M tai omegaa varten w = 2 * pi * [0 : M-1]/M, jossa M = length(xF). 378 -- Q3.4:ssä IIR:n magnitudivaste ei yleisesti ole monotoninen vaan se johtuu, että valittu Butterworth. 379 -- Q3.4:ssä FIR-viivästysten pitäisi molemmissa kohdissa olla samat, jos molempien suotimien asteluvut ovat samat. 380 -- fft(x, 512) == fft(x(1:512)). This means that if your signal x is for example 1 second long with fs=22050 Hz, then you will get spectrum only from the first 512/22050 ~ 22 ms, NOT any average spectrum of the whole signal x. Be aware! 381 -- Tehtävänannon kaavan mukaan FIR:n viive on (N/2) * (1/Fs). Eli teidän tapauksessa FIR:n viive 0.00259s. Kuitenkin kuvassa 13 teillä on zoomattuna pätkä signaalia 7.17 .. 7.17+0.0025 eli juuri tuo viiveen määrä. Ei tuosta kuvasta nähdä sitä, mitä haluatte osoittaa. Pitää zoomata vaikkapa 7.17 .. 7.19, jolloin x-akselilla 0.02 sekuntia ja viive näkyy noin 10% (0.002s) siirtymänä. 382 -- Q3.3ssa hämäävää käyttää delta_s:ää rajataajuutena. Pitäisi olla f_s tms. 383 -- Q3.3ssa kuvassa 9 näkee, että rajataajuus voisi olla pienempi, siis magnitudivastekäppyrä aavistuksen verran vasemmalla, jolloin tuo asteluku 172 luultavasti riittäisi. Sinulla on tähän liittyviä virheitä koodissa A33.m. [H, w] = freqz(B, fT) on "väärin", koska toinen argumentti on A-vektori, joka FIR:n tapauksessa on 1. Näytteenottotaajuus on vasta neljäs sisääntuleva muuttuja. Kun [H, w] = freqz(B, fT), niin fT skaalaa vain y-akselin arvoja ja muuttujaan w tulee ihan normaalisti vektori 0..pi. Seuraavalla rivillä on w = 10000 * w, jossa olet yrittänyt korjata onnettomuutta, mutta nyt w-akseliksi tuleekin 0 .. 10000pi eli 0 .. 31416 vaikka sen pitäisi olla 0 .. 31000 Hz. Tästä johtuu tuo hässäköinti. 384 -- Kuva 10, x-akseli taajuuksiksi kiitos. Tässä rajataajuus noin puolet oikeasta rajataajuudesta, unohtunut kakkonen. 4 ** Q4 Demodulointi ============================================================ 400 -- Demodulated signal is not exactly the same signal. In most cases there is the same song performed by two different artists. You can find differences in some small parts, which they sing differently. In few cases the upper band contained speech. 401 -- Too low cut-off for high-pass filter. Around 4-7 kHz. 402 -- Too high cut-off for high-pass filter. Around 4-7 kHz. 403 -- Incorrect demodulation frequency f_c. Should be around 10-12 kHz. f_c can be "guessed" from the spectrogram of the signal in Q3. (Modulated signal has either one- or two-sided spectrum.) 404 -- Generating cosine signal: see Matlab sessions. For example, t = [0 : M-1] / fs; c = A * cos(2 * pi * f * t + theta); 405 -- You can avoid for-loops in Matlab: size(x) % M x 1 size(c) % M x 1, if 1 x M then c.' x .* c % [x(1).c(1) x(2).c(2) ... x(M).c(M)] 406 -- Cosine frequency is probably almost correct but not exactly. By adjusting it a bit you can get better results. 407 -- z = x .* kos .* kos, jossa kos on kosinijono tietyllä fc-taajuudella. Mitä tässä tehdään x:lle? Moduloidaan ja demoduloidaan: z = (x .* kos) .* kos = y .* kos. Kaavakokoelmista varmaan näkee mitä cos(x).cos(x) on. Lasketaan Euleria hyväksikäyttäen: cos(w) . cos(w) = = (e^jw + e^-jw).(e^jw + e^-jw) = e^j2w + 1 + 1 + e^-j2w = 2 + cos(2w) Näin ollen z on alkuperäinen x ja sitten yksi tuplataajuudelle moduloitu x. 420 -- kuva 6:sta f_c ~~ 11700 Hz 421 -- Toiset näytteet hyvinkin herkkiä modulointitaajuuden arvoille. Arvolla f_c = 10000 Hz ("sekaisin") tulee aivan eri kuuloinen kuin f_c = 9980 Hz ("huojunta") ja erilainen kuin f_c = 9979 Hz ("jolla generoitu"). 422 -- q4 code: t = linspace(0, 1, length(x)); ??? This is apparently incorrect. Just say as earlier t = linspace(0, len_time, length(x)); Then 135000 --> 135000 - 5*27000 --> 0, and you have to have a feasiable f_c. 5 ** Q5 Palaute ============================================================ 550 -- "Not so much practical problems. Sometimes Matlab got jammed. Some Dr. Pepper got on the keyboard." You should not allow Mr Pepper to interrupt your work. Write a huge banner "Genius working - Do not interrupt". 551 -- Q4, Figure 1 (b): "Here a dashed line is considered as a new spectrum with two triangles in the extremes." I find it easier to think a spectrum consisting of two triangle components at -f_c and +f_c as one wide triangle spectrum (dashed), where one triangle is in left border (extreme) and the other in right border. Now that you modulate the wide triangle with f_c, you can draw wide triangles at -f_c and +f_c, and you notice that those small original triangular spectra components are copied to -2f_c, two times at 0 and one to +2f_c. Now you have done demodulation, and you have the original spectrum at origin plus some high-frequency components that can be filtered out. 6 ** Yleistä ============================================================ 600 -- Page numbers missing. It is extremely easy to add page numbers in any word processing software - so why not to do that. It is easier to refer: "in page X..." 601 -- Figure numbers missing. Adding figure numbers is not probably trivial in all word processing softwares. Probably "Insert Caption" or something. Again, it is easier to refer: "in Figure X..." If inserting figure numbers, then you should also write a caption for the figure. 602 -- Figure titles/captions missing. 603 -- Lots of Matlab code in the document. Sometimes it is nice to show a few lines of code inside the text in order to show how things work. However, in T-61.3010 instructions I wished to have all code in the end of the document. This implies that the code is written in a Matlab script file - NOT copy-pasted from command lines. If the code is written in a script file, it is easy to modify and run again. This is the way that we have been practicing in Matlab sessions during the spring. 604 -- Matlab code to script files. When written into files, easier to modify and re-use. Insert code in the end of the document. 605 -- Given Matlab code does not correspond or match with the results. This is very typical, if the code is not written in a Matlab script file and run from there. Example code from command line: >> [B, A] = ellip(2, 1, 20, 0.3); %doc >> freqz(B, A, 512, 22050); %doc >> [B] = fir1(8, 0.25); %doc >> freqz(B, A, 512, 22050); %doc % Here it takes time to understand that A _should_ be 1 >> A = 1 >> freqz(B, A, 512, 22050); % Now a correct figure. Suppose that two plots are copied from screen to the document, and only those four lines marked with %doc are copied directly to the document. It seems to be ok, but the next time when you try, you get incorrect answers because A=1 is not any more there. However, if you copy all lines into a script file, modification is easier, you can run all lines by one command (script file name), and you can definetely re-run code later and it works: %% Create IIR frequency response [B, A] = ellip(2, 1, 20, 0.3); freqz(B, A, 512, 22050); print -dpng fr_IIR.png %% Create FIR frequency repsonse [B] = fir1(8, 0.25); A = 1 freqz(B, A, 512, 22050); print -dpng fr_FIR.png It would be even better to use different variable names and different windows: %% Create IIR frequency response figure(1); clf; [BI, AI] = ellip(2, 1, 20, 0.3); freqz(BI, AI, 512, 22050); print -dpng fr_IIR.png %% Create FIR frequency repsonse figure(2); clf; [BF] = fir1(8, 0.25); AF = 1 freqz(BF, AF, 512, 22050); print -dpng fr_FIR.png And fir1 function works also as [BF, AF] = fir1(...). 606 -- READ INSTRUCTIONS for the course assignment!!! 607 -- Code missing. Typical, if the code is not written in a Matlab script file. 608 -- When plotting, e.g., two signals in the same Matlab plot, you should use different line widths or styles in order to make them differentiable in a grayscale paper copy. See "help plot", examples: plot(t, x, 'k-.', t, y, 'b-'); legend({'Original x[n]', 'Filtered y[n]'}); First signal x with black dash line, the latter y with blue solid line. You can also apply get, set, findobj commands to adjust properties: p1 = plot(t, x); get(p1) set(p1, 'LineWidth', 2, 'LineStyle', ':'); 609 -- What should be written in the document and what can be left in the code? Työselostus: Kirjoitettu tekstiä tuloksista, vain välttämättömät numerot ja koodinpätkät, jotka oikeasti kiinnostavat lukijaa tai ovat tärkeitä esityksen kannalta. Voisi sanoa, että työselostus on sen verran täydellinen selostus, ettei ulkopuolisen lukijan tarvitse tietää itse tehtävänannosta tai sen sanamuodoista mitään. Jos tämän työn kohdassa 4 on otsikko ja alla "koodi harj4.m" ja ainoana kirjoitettuna osana "Sama signaali", niin ulkopuolinen lukija ei ymmärtäisi mitään (eikä kenties työn tekijäkään puolen vuoden päästä). In the document it should be mentioned which data you are using. In this case, you should mention in Q3 and Q4 which audio file you had. If you compare two things quantitatively, you can write values in a table with two columns. If you asked to demodulate the signal, you can tell in the document, which modulation frequency you used instead of saying "look at code". Actually, there is no code that should be embedded in the text. You should comment your code in the Matlab script file for your own sake. 610 -- The function should be written with small letters. In Windows you can write function name either in small or capital letters. However, typically variables x and X are different, that is, Matlab is case-sensitive. In Linux/Unix thiscommand.m and THISCOMMAND.m are different (?). 611 -- Keep hard-coding as small as possible. Especially be careful with rounding numbers. If you are given cut-off frequencies fpass = ... and fstop = fpass+600, which would imply Wp = 0.324312... and Ws = 0.372345... then do NOT call the function [N, Wn] = ellipord(0.324, 0.372, ...) % 0.372-0.324 not any more exactly corresp. 600 Hz % second, easier to change, if cut-off values % given only in one line of code but Wp = 2 * fpass / fT; Ws = 2 * fstop / fT; [N, Wn] = ellipord(Wp, Ws, ...) Likiarvojen esityksessä itse kirjallisessa dokumentissa kannattaa pitää kohtuus kaikessa. Yleensä noin kolme merkitsevää lukua riittää. Jos esität lukuja kalvoilla, täydet prosentit ovat yleensä riittävä tarkkuus, yms. 612 -- Spectrogram is normally (?) drawn so that in x-axis there is time (seconds) and in y-axis frequency (Hz). 613 -- Käytän itse LaTeXissa pakettia url, \usepackage{url}. Se ymmärtää kivasti tildet ja ät-merkit. \url{http://www.hut.fi/~someone/DSP/} \url{someone@cc.hut.fi} 614 -- Matlabin kuvat kannattaa tallentaa tiedostoiksi eikä vain copy-pasteta dokumenttiin. Windowsin puolella voi käyttää esim. PNG-muotoa ja Linux/LaTeXissa EPS-muotoa. JPEG on huono viivakuvien tallennukseen. Esimerkkejä: print('-dpng','kuva1.png'); print('-deps','kuva1.eps'); % help print saveas(gcf, 'kuva1', 'png'); % help saveas 615 -- Kuvateksti ei ole kiinnitetty kuvaan. Miten lie Wordissä - pitääkö mennä kuvan päälle ja oikealla hiirellä sanoa Caption...? 616 -- Linux ja äänet. Kurssin sivulta http://www.cis.hut.fi/Opinnot/T-61.3010/matlabkoodia.shtml mysoundsc.m voi käyttää myös. 617 -- Given Matlab code does not correspond or match with the written part of the document. For instance, in the code it is said that Fourier-series consists of 20 components even if in the code it is constructed from only 5 components. 618 -- When plotting in Matlab you can add a "grid" in the plot that makes easier to read values. p1 = plot([1:7], [1:7].^2); % "handle" p1 into the figure grid on; If you want to adjust what values the grid lines get, you can write values with get, set commands get(gca) % gca == currect axis set(gca, 'XTick', [3 4.5 5.5]); set(gca, 'XTick', [3 4.5 5.5], 'XTickLabel', {'T','61','3010'}); 619 -- More text needed in the documentation (at least in some parts). What choices were made, the orders of the designed filters, what results we gotten, ... Dokumentti vajavainen. Tekstiä lisää, "oikeita" kuvia yms. 620 -- title('signalQ3_12345.wav'); käsittelee alaviivan siten, että seuraava merkki on alaindeksi. Tämän voi estää kenottamalla: title('signalQ3\_12345.wav'); 621 -- Dokkari pyydettiin tekemään Wordilla/Oofficella/LaTeXilla niin, että myös sen (kuten koodinkin) muokkaaminen on nopeaa ja helppoa. Sisältää mm. koodin kirjoittamisen skritpitiedostoihin ja kuvien "tulostamisen" eli tallettamisen tiedostoihin sekä kuvien "upottamisen" dokkariin. 622 -- Pidempää koodinpätkää LaTeXissa, käytä esim. \begin{verbatim} Tässä ympäristössä $x=4$ näkyy dollari-neljä- yhtäsuuruusmerkki-neljä-dollari. \end{verbatim} 623 -- Vältä omia funktioita, jotka ovat samannimisiä kuin Matlabin omat funktiot. Jos kirjoitat itse esimerkiksi funktion "spectrum.m" (freqz, fourier, ...), ja talletat sen työhakemistoon, niin Matlab käyttää sitä, koska se ennen valmiiksi määriteltyjä polkuja tarkistaa työhakemiston. Kuitenkin jos vaihdat hakemistoa, niin sen jälkeen Matlab hakeekin sen oman spectrum-funktion, mikä voi aiheuttaa hämmennystä. Toki ei voi välttämättä tietää, mikä on valmiiksi Matlabin oma funktio, koska niitä on niin paljon. Joskus voi olla jopa hyvä tehdä kumoava ("override") funktio - etenkin jos tarkoituksena on tehdä vastaavat asiat (mutta paremmin) kuin Matlabin oma funktio. Silloinkin suosittelen käyttämään eri tiedostonimeä. Esimerkiksi jos määrittelet oman funktion piirtämään taajuusvastetta, kuten Matlabin freqz, niin nimenä olisi vaikkapa myfreq.m. Lisää: "help addpath", "help exist". 624 -- LaTeXissa jos tarvitset enemmän "alaindekimerkkejä", niin laita ne kaarisulkuihin: $E_{ratio}$, $E_{\textrm{ratio}}$, $X_{MIN}^2$ 625 -- LaTeXin kuvassa ensin \caption{...} ja sitten \label{...}, niin pitäisi mennä oikein nuo kuvanumerot. Jos toisin päin, niin label taitaa vastata kappalenumeroa eikä kuvannumeroa. 626 -- Yleensä käytetään "Figure X" eikä "Picture X". 627 -- LaTeX:ssa ei kuvia juuri voi asetella. Lisäksi jos kuvia on paljon, niin ne "valuvat" dokkarissa eteenpäin. Tämän voi kiertää kahdella tavalla: ensiksi, pienennä kuvakokoa ja laita niitä vaikka rinnan, jotta ne mahtuvat paremmin. Toiseksi voi lukujen loppuun määrätä \afterpage{\clearpage}, joka pakottaa kyseiseen lukuun kuuluvat kuvat siihen ja sitten vasta aloittaa seuraavan luvun tekstin. 628 -- Matlabissa m-tiedostot ovat joko skriptejä (makroja) tai funktioita. Skriptit: rivejä, jotka ajetaan Matlabin tulkissa (ikäänkuin komentorivillä) rivi kerrallaan. Matlabin työpöydän muistiavaruus. Funktiot: alkaa erityisellä rivillä "function", jossa esitellään ulostulo-, sisääntulomuuttujat ja funktionnimi. Funktiolla oma muistiavaruus eli funktio ei näe Matlabin työtilan muuttujia ellei niitä eksplisiittisesti anneta funktiolle. Funktiotiedosto ei päädy end-sanaan. Katso esimerkkejä kurssin Matlab-kierroksilta. Esimerkki skriptistä http://www.cis.hut.fi/Opinnot/T-61.3010/Laskarit/D11quan.m joka käyttää funktiota a2dR http://www.cis.hut.fi/Opinnot/T-61.3010/Laskarit/a2dR.m Kts. lisää esim. http://www.cis.hut.fi/Opinnot/T-61.3010/Laskarit/ how_to_start_with_matlab.shtml 629 -- Annettu Matlab-koodi ei ole ajokelpoista. 690 -- Työ lähetetty sähköisessä muodossa muille opiskelijoille / jätetty sähköisessä muodossa vapaasti muiden nähtäväksi. Lue ohjeet! "Matlab-tiedostoja \textbf{ei saa} laittaa Internet-sivuille eikä niitä lähetetä sähköpostilla tms. Suojaa tiedostosi muilta - kopiointi on luonnollisesti kiellettyä. Mahdollisesta yhteistyöstä on ilmoitettava selkeästi." Mahdollisissa "ongelmatapauksissa" tulkitaan T-osaston vahvistamia ohjeita vilppitapausten käsittelyyn: http://tieto.tkk.fi/vilppitoimintaohje.html 7 ** Positiivinen palaute ============================================================ 710 -- GOOD: Fourier-series components in a table. 711 -- F-sarja fminsearch:llä oli hyvin tehty! 712 -- Q3:ssä näppärä FIR-parannus iteroimalla. 713 -- Q2. Tyylikäs pienimmän neliösumman käyttäminen parametrien hakemiseen! 720 -- Hyvin kirjoitettu - erittäin miellyttävä lukea. Vertaa kohta 609. 721 -- Q3:ssä näppärästi johdettu iterointi: aluksi Matlab-ohjeiden mukainen 20 dB, sitten korvakuulolta parannus 40 dB:en. 730 -- Hauskaa Wappua! 8 ** Oliko näitä kommentoitu jo? ============================================================ 800 -- Jos FIR:n implementointiin fir1-funktion (ikkunamenetelmä), niin astelukua EI aleta laskemaan mistään Kaiser-funktion asteluvun laskentakaavasta. 801 -- Dokumentointi: modulointitaajuus (kanta-aalto) olisi kyllä mukava ilmoittaa dokkarissa.