I was wondering how to get n number of sample outputs constrained by the situations given.
AB > C^2
accept C
else reject C
however, I need n non zero final samples.
Wrote this one:
It works for me!
Tuesday, August 18, 2009
Tuesday, June 16, 2009
do till condition is met "continue" example
This is a nice example.
This takes x until y(j)>50. After the condition is met it simply passes out.
Better explained by:
continue keeps on taking values does not break the chain.
while break breaks it and comes out of the loop
Contrasted over the
lastly;
clear
clc
y = 1:100;
count = 0
for j = 1:length(y)
disp('go')
if y(j)<20||y(j)>50, break, end
count = count+1
x(j)=y(j)
pause
end
this does not even work while continue will keep looking for the situation.
Break just breaks while continue keep working escaping to the next one and checking!
This takes x until y(j)>50. After the condition is met it simply passes out.
Better explained by:
continue keeps on taking values does not break the chain.
while break breaks it and comes out of the loop
Contrasted over the
lastly;
clear
clc
y = 1:100;
count = 0
for j = 1:length(y)
disp('go')
if y(j)<20||y(j)>50, break, end
count = count+1
x(j)=y(j)
pause
end
this does not even work while continue will keep looking for the situation.
Break just breaks while continue keep working escaping to the next one and checking!
Thursday, June 11, 2009
saving .mat file as per the iteration
I wanted to save the mat files as the iteration progressed.
here is the quick solution:
it saves the mat file with number of iteration as the file name: viz: 100.mat, 200.mat etc.
This is handy when you want to compare the results of the intermediate results as you progress the iteration.
here is the quick solution:
it saves the mat file with number of iteration as the file name: viz: 100.mat, 200.mat etc.
This is handy when you want to compare the results of the intermediate results as you progress the iteration.
Friday, March 20, 2009
How to show the highlighted content in the blogger post
I wanted to highlight certain texts in the blogger posts, mostly codes and others and was having difficulties.
I just looked into the source code of one of the blog and realized that this piece of code will work:
So, I can show the highlighted content in the blogger post
I just looked into the source code of one of the blog and realized that this piece of code will work:
So, I can show the highlighted content in the blogger post
Monday, March 16, 2009
Use of figure handle in Matlab
Friday, February 20, 2009
Playing with wav file in Matlab
To do:
READ THE AUDIO FILE
DISPLAY WAVEFORM
COMPUTE AND DISPLAY FREQUENCY DOMAIN AS FIGURE
% tHE VALIDITY YET TO BE TESTED...
clear all;
close all;
clc;
% import a audio
[y,Fs,nbit]=wavread('your_audio.wav');
% extract left channel only
left=y(:,1);
% calculate the time scale
Ts=1/Fs;
[nsamples,c]=size(y);
tscale=0:Ts:(nsamples-1)*Ts;
%plot left and right channel in time domain
plot(tscale,left,'r');
xlabel('Time (sec)');
ylabel('Amplitude');
%compute the FFT with the proper sampling frequency
fmax=Fs;
%how many points the FFT must be computed on?
N=nsamples;
tscale=0:Ts:(N-1)*Ts;
%N=number of FFT points:
% change it and test the different resolution
fscale=linspace(0,fmax/2,floor(N/2));
spectrum=fft(left,N);
%plot the spectrum of the signal using the appropriate
% frequency scale and module of the coefficients
%plot the magnitude
figure(2);
plot(fscale,abs((spectrum(1:length(fscale)))));
xlabel('Frequency Hz')
ylabel('Module')
READ THE AUDIO FILE
DISPLAY WAVEFORM
COMPUTE AND DISPLAY FREQUENCY DOMAIN AS FIGURE
% tHE VALIDITY YET TO BE TESTED...
clear all;
close all;
clc;
% import a audio
[y,Fs,nbit]=wavread('your_audio.wav');
% extract left channel only
left=y(:,1);
% calculate the time scale
Ts=1/Fs;
[nsamples,c]=size(y);
tscale=0:Ts:(nsamples-1)*Ts;
%plot left and right channel in time domain
plot(tscale,left,'r');
xlabel('Time (sec)');
ylabel('Amplitude');
%compute the FFT with the proper sampling frequency
fmax=Fs;
%how many points the FFT must be computed on?
N=nsamples;
tscale=0:Ts:(N-1)*Ts;
%N=number of FFT points:
% change it and test the different resolution
fscale=linspace(0,fmax/2,floor(N/2));
spectrum=fft(left,N);
%plot the spectrum of the signal using the appropriate
% frequency scale and module of the coefficients
%plot the magnitude
figure(2);
plot(fscale,abs((spectrum(1:length(fscale)))));
xlabel('Frequency Hz')
ylabel('Module')
Subscribe to:
Posts (Atom)

