Speech Recog_ Important

Embed Size (px)

Citation preview

  • 8/13/2019 Speech Recog_ Important

    1/7

    India Contact Us Store

    Create Account Log

    Products & Services Solutions Academia Support User Community Events Company

    Trial Sof tw are Product Updates SharDocumentation Center

    Search R2013b Documentation

    Signal Proces sing Toolbox Signal Processing Toolbox Examples

    Measuring Signal Similarities

    This example s hows how to meas ure signal sim ilarities. It will help you answer questions s uch as: How do I compare signals with

    different lengths or different sampling rates? How do I find if there is a signal or just noise in a measurement? Are two signals related?

    How to meas ure a delay between two signals (and how do I align them )? How do I compare the frequency content of two signals?

    Similarities can also be found in different sections of a signal to determine if a signal is periodic.

    Comparing Signals w ith Different Sampling Rates

    Consider a database of audio signals and a pattern matching application where you need to identify a song as it is playing. Data is

    commonly stored at a low sampling rate to occupy less memory.

    % Load data

    load relatedsig.mat;

    figure

    ax(1) = subplot(311);

    plot((0:numel(T1)-1)/Fs1,T1,'k'); ylabel('Template 1'); grid on

    ax(2) = subplot(312);

    plot((0:numel(T2)-1)/Fs2,T2,'r'); ylabel('Template 2'); grid on

    ax(3) = subplot(313);

    plot((0:numel(S)-1)/Fs,S,'b'); ylabel('Signal'); grid on

    xlabel('Time (secs)');

    linkaxes(ax(1:3),'x')

    axis([0 1.61 -4 4])

    The first and the second subplot show the template signals from the database. The third subplot shows the signal which we want to

    search for in our databas e. Just by looking at the time se ries, the signal does not seem to m atch to any of the two templates . A closer

    inspection reveals that the signals actually have different lengths and sampling rates.

    [Fs1 Fs2 Fs]

    ans =

    4096 4096 8192

    Different lengths prevent you from calculating the d ifference between two signals but this can easi ly be remedied by extracting the comm on

    part of signals . Furthermore, it is not always necess ary to equalize lengths. Cross-correlation can be pe rformed between signals wi th

    Accel erati ng th e pace of en gin eeri ng an d sci ence

    http://www.mathworks.in/help/signal/index.htmlhttp://www.mathworks.in/help/signal/examples/index.htmlhttp://www.mathworks.in/help/signal/examples/index.htmlhttp://www.mathworks.in/help/signal/examples/index.htmlhttp://www.mathworks.in/help/signal/examples/index.htmlhttp://www.mathworks.in/help/signal/index.htmlhttp://www.mathworks.in/help/documentation-center.htmlhttp://www.addthis.com/bookmark.php?v=250&pubid=mathworkshttp://www.mathworks.in/support/web_downloads_bounce.html?s_cid=1008_degr_docdn_270055http://www.mathworks.in/programs/bounce/doc_tryit.htmlhttp://www.mathworks.in/company/?s_tid=gn_cohttp://www.mathworks.in/company/events/?s_tid=gn_evhttp://www.mathworks.in/matlabcentral/?s_tid=gn_mlchttp://www.mathworks.in/support/?s_tid=gn_supphttp://www.mathworks.in/academia/?s_tid=gn_acadhttp://www.mathworks.in/solutions/?s_tid=gn_solhttp://www.mathworks.in/products/?s_tid=gn_pshttps://www.mathworks.in/accesslogin/login.do?uri=http://www.mathworks.in/help/signal/examples/measuring-signal-similarities.htmlhttps://www.mathworks.in/accesslogin/createProfile.do?uri=http://www.mathworks.in/help/signal/examples/measuring-signal-similarities.htmlhttp://www.mathworks.in/store/default.do?s_tid=gn_storehttp://www.mathworks.in/company/aboutus/contact_us/?s_tid=gn_cntushttp://www.mathworks.in/company/worldwide/?s_tid=gn_loc
  • 8/13/2019 Speech Recog_ Important

    2/7

    different lengths, but it is essential to ensure that they have identical sampling rates. The safest way to do this is to resample the signal

    with a lower sampling rate. The resamplefunction applies an anti-aliasing(low-pass) FIR filter to the signal during the resampling

    process.

    [P1,Q1] = rat(Fs/Fs1); % Rational fraction approximation

    [P2,Q2] = rat(Fs/Fs2); % Rational fraction approximation

    T1 = resample(T1,P1,Q1); % Change sampling rate by rational factor

    T2 = resample(T2,P2,Q2); % Change sampling rate by rational factor

    Finding a Signal in a Measurement

    We can now cross-correlate signal S to templates T1 and T2 with the xcorrfunction to determine if there is a match.

    [C1,lag1] = xcorr(T1,S);

    [C2,lag2] = xcorr(T2,S);

    figure

    ax(1) = subplot(211);

    plot(lag1/Fs,C1,'k'); ylabel('Amplitude'); grid on

    title('Cross-correlation between Template 1 and Signal')

    ax(2) = subplot(212);

    plot(lag2/Fs,C2,'r'); ylabel('Amplitude'); grid on

    title('Cross-correlation between Template 2 and Signal')

    xlabel('Time(secs)');

    axis(ax(1:2),[-1.5 1.5 -700 700 ])

    The first subplot indicates that the signal and template 1 are less correlated while the high peak in the second subplot indicates that signal

    is present in the second template.

    [~,I] = max(abs(C2));

    timeDiff = lag2(I)/Fs

    timeDiff =

    0.0609

    The peak of the cross correlation implies that the signal is present in template T2 starting after 61 ms.

    Measuring Delay Between Signals and Aligning Them

    Consider a situation where you are collecting data from different sensors, recording vibrations caused by cars on both sides of a bridge.

    When you analyze the signa ls, you may need to align them . Assume you have 3 sensors working at same s ampling rates and they are

    measuring s ignals caused by the sam e event.

    figure,

    ax(1) = subplot(311); plot(s1,'b'); ylabel('s1'); grid on

    ax(2) = subplot(312); plot(s2,'k'); ylabel('s2'); grid on

    ax(3) = subplot(313); plot(s3,'r'); ylabel('s3'); grid on

    xlabel('Samples')

    linkaxes(ax,'xy')

  • 8/13/2019 Speech Recog_ Important

    3/7

    The maximum value of the cross-correlations between s1 and s2 and s1 and s3 indicate time leads /lags.

    [C21,lag1] = xcorr(s2,s1);

    [C31,lag2] = xcorr(s3,s1);

    figure

    subplot(211); plot(lag1,C21/max(C21)); ylabel('C21');grid on

    title('Cross-Correlations')

    subplot(212); plot(lag2,C31/max(C31)); ylabel('C31');grid on

    xlabel('Samples')

    [~,I1] = max(abs(C21)); % Find the index of the highest peak

    [~,I2] = max(abs(C31)); % Find the index of the highest peak

    t21 = lag1(I1) % Time difference between the signals s2,s1

    t31 = lag2(I2) % Time difference between the signals s3,s1

    t21 =

    -350

    t31 =

    150

    t21 indicates that s2 lags s1 by 350 samples, and t31 indicates that s3 leads s1 by 150 samples. This information can now used to align

    the 3 signals.

    s2 = [zeros(abs(t21),1);s2];

    s3 = s3(t31:end);

    figure

    ax(1) = subplot(311); plot(s1); grid on; title('s1'); axis tight

  • 8/13/2019 Speech Recog_ Important

    4/7

    ax(2) = subplot(312); plot(s2); grid on; title('s2'); axis tight

    ax(3) = subplot(313); plot(s3); grid on; title('s3'); axis tight

    linkaxes(ax,'xy')

    Comparing the Frequency Content of Signals

    A power spectrum disp lays the power pres ent in each frequency. Spectral coherence identi fies frequency-dom ain corre lation between

    signals. Coherence values tending towards 0 indicate that the corresponding frequency components are uncorrelated while values

    tending towards 1 i ndicate that the corresponding frequency componen ts are correlated. Consider two signals and their respective power

    spectra.

    Fs = FsSig; % Sampling Rate

    [P1,f1] = periodogram(sig1,[],[],Fs,'power');

    [P2,f2] = periodogram(sig2,[],[],Fs,'power');

    figure

    t = (0:numel(sig1)-1)/Fs;

    subplot(221); plot(t,sig1,'k'); ylabel('s1');grid on

    title('Time Series')

    subplot(223); plot(t,sig2); ylabel('s2');grid on

    xlabel('Time (secs)')

    subplot(222); plot(f1,P1,'k'); ylabel('P1'); grid on; axis tight

    title('Power Spectrum')subplot(224); plot(f2,P2); ylabel('P2'); grid on; axis tight

    xlabel('Frequency (Hz)')

    The mscoherefunction calculates the spectral coherence between the two signals . It confirms that sig1 and sig2 have two correlated

    components around 35 Hz and 165 Hz. In frequencies where spectral coherence is high, the relative phas e between the correlated

    components can be es timated with the cross spectrum phas e.

    [Cxy,f] = mscohere(sig1,sig2,[],[],[],Fs);

    Pxy = cpsd(sig1,sig2,[],[],[],Fs);

    phase = -angle(Pxy)/pi*180;

  • 8/13/2019 Speech Recog_ Important

    5/7

    [pks,locs] = findpeaks(Cxy,'MinPeakHeight',0.75);

    figure

    subplot(211);

    plot(f,Cxy); title('Coherence Estimate');grid on;

    set(gca,'xtick',f(locs),'ytick',.75);

    axis([0 200 0 1])

    subplot(212);

    plot(f,phase); title('Cross Spectrum Phase (deg)');grid on;

    set(gca,'xtick',f(locs),'ytick',round(phase(locs)));

    xlabel('Frequency (Hz)');

    axis([0 200 -180 180])

    The phase lag between the 35 Hz components is close to -90 degrees, and the phase lag between the 165 Hz components is close to -60

    degrees.

    Finding Periodicities in a Signal

    Consider a set of temperature measurements in an office building during the winter season. Measurements were taken every 30 minutes

    for about 16.5 weeks.

    load officetemp.mat % Load Temperature Data

    Fs = 1/(60*30); % Sample rate is 1 sample every 30 minutes

    days = (0:length(temp)-1)/(Fs*60*60*24);

    figure

    plot(days,temp)

    title('Temperature Data')

    xlabel('Time (days)'); ylabel('Temperature (Fahrenheit)')

    grid on

    With the temperatures in the low 70s , you need to remove the mean to analyze sm all fluctuations in the signal. The xcovfunction removes

    the mean of the signal before computing the cross -correlation. It returns the cross-covariance. Limit the maximum lag to 50% of the signal

    to get a good estim ate of the cross -covariance.

  • 8/13/2019 Speech Recog_ Important

    6/7

    maxlags = numel(temp)*0.5;

    [xc,lag] = xcov(temp,maxlags);

    [~,df] = findpeaks(xc,'MinPeakDistance',5*2*24);

    [~,mf] = findpeaks(xc);

    figure

    plot(lag/(2*24),xc,'k',...

    lag(df)/(2*24),xc(df),'kv','MarkerFaceColor','r')

    grid on

    set(gca,'Xlim',[-15 15])

    xlabel('Time (days)')

    title('Auto-covariance')

    Observe dominant and minor fluctuations i n the auto-covariance. Dominant and minor peaks appear equidistant. To verify if they are,

    compute and plot the difference between the locations of subsequent peaks.

    cycle1 = diff(df)/(2*24);

    cycle2 = diff(mf)/(2*24);

    subplot(211); plot(cycle1); ylabel('Days'); grid on

    title('Dominant peak distance')

    subplot(212); plot(cycle2,'r'); ylabel('Days'); grid on

    title('Minor peak distance')

    mean(cycle1)

    mean(cycle2)

    ans =

    7

    ans =

    1.0000

  • 8/13/2019 Speech Recog_ Important

    7/7

    The minor peaks indicate 7 cycle/week and the dominant peaks indicate 1 cycles per week. This m akes s ense gi ven that the data comes

    from a tem perature-controlled building on a 7 day calendar. The first 7-day cycle indicates that there is a weekly cyclic behavior of the

    building temperature where temperatures l ower during the weekends and go back to normal during the week days. The 1-day cycle

    behavior indicates that there is also a daily cyclic behavior - temperatures l ower during the night and increase during the day.

    Was this topic helpful? Yes No

    Try MATLAB, Simulink, and Other Products

    Get trial now

    Join the conversat

    Preventing PiracyPrivacy PolicyTrademarksPatentsSite Help 1994-2013 T he M athWorks, Inc.

    http://www.mathworks.in/help.htmlhttp://www.mathworks.in/company/aboutus/policies_statements/patents.htmlhttp://www.mathworks.in/company/aboutus/policies_statements/trademarks.htmlhttp://www.mathworks.in/company/aboutus/policies_statements/http://www.mathworks.in/company/aboutus/policies_statements/piracy.htmlhttp://www.mathworks.in/programs/bounce_hub_generic.html?s_tid=mlc_twt&url=http://www.twitter.com/MATLABhttp://www.mathworks.in/programs/bounce_hub_generic.html?s_tid=mlc_fbk&url=http://www.facebook.com/MATLABhttp://www.mathworks.in/programs/bounce_hub_generic.html?s_tid=mlc_glg&url=https://plus.google.com/117177960465154322866?prsrc=3http://www.mathworks.in/programs/bounce_hub_generic.html?s_tid=mlc_lkd&url=http://www.linkedin.com/company/the-mathworks_2http://www.mathworks.in/company/rss/index.htmlhttp://www.mathworks.in/programs/trials/trial_request.html?prodcode=SG&eventid=616177282&s_iid=doc_trial_SG_footer