Question

let us consider following code

clear all;
 B=xlsread('data_generations1','A1','g8:g301');
% n=input('enter the number  from 1 to 16 for  windows  in periodogram :');
 fs=input('enter sampling frequency  fs :');
 while  1
     n=input('enter the number  from 1 to 16 for  windows  in periodogram :');
 switch n
     case 1
         disp('this is  hann window ');
         [pxx,f]=periodogram(B,hann(length(B)),length(B),fs);
         subplot(4,4,1);
         plot(f,pxx);
         hold on
     case 2
         disp('this is hamming window ');
         [pxx,f]=periodogram(B,hamming(length(B)),length(B),fs);
         subplot(4,4,2);
         plot(f,pxx);
         hold on
     case 3
         disp('this is kaiser window ');
         [pxx,f]=periodogram(B,kaiser(length(B),2.5),length(B),fs);
        subplot(4,4,3);
         plot(f,pxx);
         hold on
     case 4
         disp('this is barlett window ');
         [pxx,f]=periodogram(B,bartlett(length(B)),length(B),fs);
         subplot(4,4,4);
         plot(f,pxx);
         hold on
     case 5
         disp('this is bohmanwin window ');
         [pxx,f]=periodogram(B,bohmanwin(length(B)),length(B),fs);
         subplot(4,4,5);
         plot(f,pxx);
         hold on
     case 6
          [pxx,f]=periodogram(B,rectwin(length(B)),length(B),fs);
         subplot(4,4,6);
         plot(f,pxx);
         hold on

     case 7
          [pxx,f]=periodogram(B,triang(length(B)),length(B),fs);
         subplot(4,4,7);
         plot(f,pxx);
         hold on

     case 8
          [pxx,f]=periodogram(B,gausswin(length(B),2.5),length(B),fs);
         subplot(4,4,8);
         plot(f,pxx);
         hold on

     case 9
          [pxx,f]=periodogram(B,flattopwin(length(B),'periodic'),length(B),fs);
         subplot(4,4,9);
         plot(f,pxx);
         hold on

     case 10
          [pxx,f]=periodogram(B,gausswin(length(B),2.5),length(B),fs);
         subplot(4,4,10);
         plot(f,pxx);
         hold on

     case 11
         [pxx,f]=periodogram(B,tukeywin(length(B),0.5),length(B),fs);
         subplot(4,4,11);
         plot(f,pxx);
         hold on
     case 12 
         [pxx,f]=periodogram(B,taylorwin(length(B)),length(B),fs);
         subplot(4,4,12);
         plot(f,pxx);
         hold on
     case 13
        [pxx,f]=periodogram(B,barthannwin(length(B)),length(B),fs);
         subplot(4,4,13);
         plot(f,pxx);
         hold on
          case 14 
          [pxx,f]=periodogram(B,parzenwin(length(B)),length(B),fs);
         subplot(4,4,14);
         plot(f,pxx);
         hold on
     case 15
         [pxx,f]=periodogram(B,nuttalwin(length(B),'periodic'),length(B),fs);
         subplot(4,4,15);
         plot(f,pxx);
         hold on

     case 16 
         [pxx,f]=periodogram(B,nuttalwin(length(B),'periodic'),length(B),fs);
         subplot(4,4,15);
         plot(f,pxx);
         hold on
         otherwise
        warning('Unexpected number typed. No windows is used ');
 end
                 break;
 end

my goal is that using loop i want to enter at each step some number from 1 to 16 and make subpplot of power spectral density using periodogram with several different windows,but when i run,it only shows me plotting only one times,that means for example if i enter number 1,it shows me hann window and then stop,how can i make loop through each step and at the same time to keep previously plotted graph?thanks in advance

Was it helpful?

Solution

Remove the break call. The whole point of break is to exit early out of a loop. Since you don't want to exit early, don't call break.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top